rstudio / dygraphs

R interface to dygraphs
http://rstudio.github.io/dygraphs
Other
364 stars 194 forks source link

stemPlot stopped working #238

Open bbTomas opened 4 years ago

bbTomas commented 4 years ago

stemPlot does not show anything, it worked in older versions (and stepPlot still works fine in this version)

Reproducible example:

library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
    dyOptions(stemPlot = TRUE)
rschuchmann commented 4 years ago

I just realized that this has something to do with the htmlwidgets package. With htmlwidgets v1.3 the stemplot is working, with the latest version it is not.

bbTomas commented 4 years ago

I have just realized how to fix the problem. @pshevtsov Please, add the last line of code into R/series.R, function resolveStemPlot:

# provide custom plotter JS
    "function stemPlotter(e) { 
       var ctx = e.drawingContext; 
       var points = e.points; 
       var y_bottom = e.dygraph.toDomYCoord(0);
       ctx.fillStyle = e.color; 
       for (var i = 0; i < points.length; i++) { 
          var p = points[i]; 
          var center_x = p.canvasx;
          var center_y = p.canvasy; 
          ctx.beginPath(); 
          ctx.moveTo(center_x, y_bottom); 
          ctx.lineTo(center_x, center_y); 
          ctx.stroke();
          ctx.beginPath(); 
          ctx.arc(center_x, center_y, 3, 0, 2*Math.PI); 
          ctx.stroke();
       }
    }
    Dygraph.Plotters.StemPlotter = stemPlotter;"     # <--- please add this line of code

The same thing should be probably added into the inst/plotters/stemplot.js file.