PageRenderTime 27ms CodeModel.GetById 24ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/R/GraphicPars-class.R

http://github.com/tengfei/visnab
R | 129 lines | 28 code | 15 blank | 86 comment | 0 complexity | 5a30f9417ea745c435ea1c2efe626ab4 MD5 | raw file
  1##-----------------------------------------------------------------##
  2##                Class GrahpicPars
  3##-----------------------------------------------------------------##
  4## setOldClass("R::visnab::ControlPanel")
  5
  6setClass("Parameters", contains = c("VIRTUAL"))
  7
  8setPars <- function(viewname, pars = list(), prototype = list(), ..., 
  9                           contains = c("Parameters", "PropertySet"),
 10                           where = topenv(parent.frame())){
 11  names <- paste(viewname, "Pars", sep = "")
 12    setPropertySet(names, pars, prototype, ..., 
 13                   contains = contains)
 14
 15}
 16
 17.AllVisnabViews <- c("VisnabView",
 18                     "IntervalView",
 19                     "TxdbView",
 20                     "CoverageView",
 21                     "BamView",
 22                     "AlignmentView",
 23                     "ScaleView",
 24                     "SingleChromView",
 25                     "SeqView",
 26                     "TracksView",
 27                     "CircularView")
 28
 29## sapply(.AllVisnabViews, function(viewname){
 30##   gparslst <- list(xlimZoom = "numeric",
 31##                    ylimZoom= "numeric",
 32##                    xlim = "numeric",
 33##                    ylim = "numeric",
 34##                    view = "character",
 35##                    ## fix on active binding of this geom
 36##                    geom = .GeomName(viewname))
 37##   setPars(viewname, gparslst)
 38## })
 39
 40.GParsName <- function(viewname){
 41  paste(viewname, "Pars", sep = "")
 42}
 43
 44##----------------------------------------------------------------##
 45##                Constructor for GraphicsPars
 46##----------------------------------------------------------------##
 47
 48
 49##' GraphicPars is the constructor for generating a set of graphic parameters which
 50##' could control specific view
 51##'
 52##' All the parameters stored in a GraphicPars object are signal objects, which listen
 53##' to user's response, when the signal object is changed, it will emit certain binded
 54##' function(s), for graphic parameters, it usually just update associated view(s) to
 55##' make sure the color or other attributes changes on the fly.
 56##'
 57##' @title Graphic parameters constructor
 58##' @param ... pass paramters to update the default list
 59##' @param view specify a default graphic parameters set for particular View Class.
 60##' @return a GrahpicPars object, which store all parameteres as fields.
 61##' @seealso signalingField
 62##' @author Tengfei Yin <yintengfei@gmail.com>
 63GraphicPars <- function(..., view = "VisnabView", theme = "default"){
 64  ## switch geom
 65  geom <- .Geom(view)
 66  cls <- .GParsName(view)
 67  gp <- new(cls, ..., geom = geom)
 68  ## gp$setTheme(theme)
 69  ## gp$update(...)
 70  return(gp)
 71}
 72
 73
 74
 75
 76## reset = function(themeName){
 77##   'reset parameters to default
 78##       '
 79##   ## do some thing first
 80##   callSuper(themeName)
 81## },
 82## update = function(...){
 83##   'reset parameters to default
 84##       '
 85##   ## do some thing first
 86##   callSuper(...)
 87## },
 88## output = function(){
 89##   'output a list of parameters, automatically remove signal
 90##    function which are just used for internal signal emit.
 91##    This function return a list, pars shows the names of parameters;
 92##    value shows value of parameters; listeners shows how many
 93##    signal function associagted with certain parameter;
 94##    class shows class of those parameters.
 95##    '
 96##   .self$properties()
 97## },
 98## setTheme = function(themeName){
 99##   "set parameters based on theme name
100##   "
101##   .self$reset(themeName)
102## },
103## widget = function(){
104##   w <- ControlPanel(.self)
105##   ThemeChanged$connect(function(name){
106##     vals <-.self$field(name)
107##     w$setValue(name, vals)
108##   })
109##   w
110## }
111
112
113## setMethod("show","Parameters",function(object){
114##   cat("Parameters stored in pars\n")
115##   for(nm in ls(object@.xData)){
116##     y <- get(nm,env=object@.xData)
117##     if((is(y,"character"))||(is(y,"numeric"))){
118##       cat(nm, " = ", toString(y), "\n")
119##     }
120##     if(is(y,"Signal")){
121##       cat(nm, " = ")
122##       show(y)
123##     }
124##     if(is(y,"list")){
125##       cat(nm, " = ", "\n")
126##       str(y)
127##     }
128##   }
129## })