+ var row = e.selectedRow;
+
+ var legendMode = e.dygraph.getOption('legend');
+ if (legendMode === 'never') {
+ this.legend_div_.style.display = 'none';
+ return;
+ }
+
+ if (legendMode === 'follow') {
+ // create floating legend div
+ var area = e.dygraph.plotter_.area;
+ var labelsDivWidth = e.dygraph.getOption('labelsDivWidth');
+ var yAxisLabelWidth = e.dygraph.getOptionForAxis('axisLabelWidth', 'y');
+ // determine floating [left, top] coordinates of the legend div
+ // within the plotter_ area
+ // offset 20 px to the right and down from the first selection point
+ // 20 px is guess based on mouse cursor size
+ var leftLegend = points[0].x * area.w + 20;
+ var topLegend = points[0].y * area.h - 20;
+
+ // if legend floats to end of the window area, it flips to the other
+ // side of the selection point
+ if ((leftLegend + labelsDivWidth + 1) > (window.scrollX + window.innerWidth)) {
+ leftLegend = leftLegend - 2 * 20 - labelsDivWidth - (yAxisLabelWidth - area.x);
+ }