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

arrow annotations invisible in RStudio Viewer #10

Closed danielkrizian closed 10 years ago

danielkrizian commented 10 years ago

Test arrow annotations on the graph symbolizing trade timings, direction and profitability.

Existing dygraph functionality: https://github.com/danielkrizian/dygraphs/blob/canvas-annotations/tests/canvas-annotation.html

danielkrizian commented 10 years ago

Arrow annotations now available (run /examples/ohlc-trades.R)

Works when opened in the browser with this image button in the RStudio Viewer pane:

image

Doesn't work within RStudio Viewer: image

@timelyportfolio , any idea why? I suspect it could have something to do with using g.ready() in the new script template, which is a way of telling the dygraph to do something after chart finished rendering:

<script>
  if (typeof gs === 'undefined') { var gs = [] };
  if (typeof blockRedraw === 'undefined') { var blockRedraw = false };
  (function(){
    var params = {{{ chartParams }}};
    gs.push(new Dygraph(
      document.getElementById( '{{chartId}}' ),
      _.unzip(params.data),
      params.options
    ));

    for (var i = 0; i < gs.length; i++) {
      var g = gs[i];
      g.ready(function () {
        var labels = g.getLabels();
        g.setAnnotations(_.map(params.options.annotations, function(annotation) {
          if (_.indexOf(labels, annotation.series) === -1) {
            if (_.isNumber(annotation.series)) {
              annotation.series = labels[annotation.series];
            }
          }
          return annotation;
        }));
      });
    }
  })();
</script>
timelyportfolio commented 10 years ago

Interesting and wonder if might be part of the same issue why nvd3 do not work. Unfortunately I do not know how to debug in RStudio viewer, so not sure how to attack this.

danielkrizian commented 10 years ago

There is some debugging environment for the RStudio Viewer under right-click-> Inspect: image image Perhaps @ramnathv has some leads on this?

danielkrizian commented 10 years ago

@timelyportfolio , ( @ramnathv ) : FYI the above commit https://github.com/danielkrizian/rChartsDygraphs/commit/b22e2af93e1caad9ae55b83ca8264e39d390249e , could be also possibly solving the nvd3 troubles you mentioned.