rstudio/dygraphs

bug on click handler for stacked charts returns incorrect series

dan-i opened this issue · 1 comments

dan-i commented

in dygraphs.js line 692-694 always using points[0] is incorrect, it doesn't affect the x, but does the y:

    				x_closest_point: isDate ? new Date(points[0].xval) : points[0].xval,
    				y_closest_point: points[0].yval,
    				series_name: points[0].name,

need to find the right point index in the list and return that y, eg.

		var canvasy=e.clientY-e.srcElement.getBoundingClientRect().top
		var sitem;
                    for(sitem = 0; sitem < points.length; sitem++) {
                        if(points[sitem].canvasy>=canvasy) break;
                    }
                    if(sitem>0) {
                           Shiny.onInputChange(el.id + "_click", {
    				x: isDate ? new Date(x) : x,
    				x_closest_point: isDate ? new Date(points[sitem-1].xval) : points[sitem-1].xval,
    				y_closest_point: points[sitem-1].yval,
    				series_name: points[sitem-1].name,
    				'.nonce': Math.random() // Force reactivity if click hasn't changed
		      });
przmv commented

Could you please provide a Minimal Working Example (https://www.r-bloggers.com/writing-a-minimal-working-example-mwe-in-r/)?