danielkrizian / rChartsDygraphs

An `rCharts` extension. Run `dygraphs` from R - interactive visualizations of time series using JavaScript and HTML canvas. See: http://dygraphs.com/ and
http://rcharts.io/
9 stars 10 forks source link

`width/height` cleanup & defaults to fit RStudio viewer #8

Open danielkrizian opened 10 years ago

danielkrizian commented 10 years ago

Dimensions of the charts are fixed and do not fit RStudio viewer:

image

Moreover, resolve trifold conflict where width and height are specified:

    <style>
    .rChart {
      display: block;
      margin-left: auto; 
      margin-right: auto;
      width: px;
      height: px;
    }  
    </style>

      </head>

      <body>
        <script>
          var blockRedraw = false;
          var gs = [];
        </script>

    <div id = 'chart401849fb2b17' class = 'rChart dygraph'></div>
    <script>
      if (typeof gs === 'undefined') { var gs = [] };
      if (typeof blockRedraw === 'undefined') { var blockRedraw = false };
      (function(){
        var params = {
     "dom": "chart401849fb2b17",
    "width":    800,
    "height":    400,
        "options": {
         "width":   1000,
        "height":    400,

@timelyportfolio let me know if any ideas

timelyportfolio commented 10 years ago

Probably will tackle this all in with #6. I do not think we would want to force a size to fit into RStudio Viewer. Rather, I think we should just provide height and width config (resolving the trifold problem) so folks can play with the size as they desire. Beyond that, we will also need to provide height/width for multi-charts. This will present a different set of challenges.

danielkrizian commented 10 years ago

agreed, I had in mind defaulting to the size of the RStudio viewer if height/width not provided, not forcing/overriding, if you agree. Edited the issue heading

timelyportfolio commented 10 years ago

Only issue is the Rstudio viewer will be different for each user. I guess we can apply some sensible defaults that we would expect to fit in most cases.

timelyportfolio commented 10 years ago

So, would you prefer using the rCharts height and width in the parent params or do you want it all contained in the child options?

params
  ...
  height = ??
  width = ??
  options
    height = ??
    width = ??

Don't care much on my end, but would assume the parent params would be more consistent with other rCharts libraries.

danielkrizian commented 10 years ago

Was wondering if layout_dygraphs can get current viewer pane dimensions. Only found a way to set Viewer pane size (height), which we don't want https://support.rstudio.com/hc/en-us/articles/202133558-Extending-RStudio-with-the-Viewer-Pane Will ask RStudio guys

timelyportfolio commented 10 years ago

do you want to start a new branch to iterate through this?

danielkrizian commented 10 years ago

Good question, I vote for parent params too. The duplicity you see now was just quick&dirty proof of concept when I first set things up

timelyportfolio commented 10 years ago

Simple enough change then. Just tested and this works for me. Then we will just need to change the template to use params or change the payload to keep the JSON in the original format.

Dygraph <- setRefClass('Dygraph', contains = 'rCharts'
                       , methods = list(
  initialize = function(){
    callSuper()
    params <<- c(params, list(options = list()))
  },
danielkrizian commented 10 years ago

New branch layout created for this #8 and #6 . Feel free to create branches at will

timelyportfolio commented 10 years ago

Not that you want to do it but after the last commit you could specify different height and width for use with layout_dygraphs, and it works.

dygraph1 <- dygraph(data=SPY[,c("Date","SPY.Close")], sync=TRUE, crosshair="vertical", legendFollow=TRUE, height = 400, width=300)
dygraph2 <- dygraph(data=SPY[,c("Date","Momentum20days")], sync=TRUE, crosshair="vertical", legendFollow=TRUE, height = 200, width=1000, colors='grey')

layout_dygraphs(dygraph1, dygraph2)