From a22cc80916b6e165451995e1ae3ed4d36dc86eab Mon Sep 17 00:00:00 2001 From: Petr Shevtsov Date: Thu, 13 Nov 2014 19:18:30 +0300 Subject: [PATCH] Use "legend" option with "follow" value. Hide legend on deselect. --- dygraph-options-reference.js | 8 +------- plugins/legend.js | 8 ++++---- tests/customLabelFollow.html | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index 05988c4..acb0626 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -472,13 +472,7 @@ Dygraph.OPTIONS_REFERENCE = // "default": "onmouseover", "labels": ["Legend"], "type": "string", - "description": "When to display the legend. By default, it only appears when a user mouses over the chart. Set it to \"always\" to always display a legend of some sort." - }, - "legendFollow": { - "default": "false", - "labels": ["Legend"], - "type": "boolean", - "description": "Legend follows highlighted points" + "description": "When to display the legend. By default, it only appears when a user mouses over the chart. Set it to \"always\" to always display a legend of some sort. When set to \"follow\", legend follows highlighted points." }, "labelsShowZeroValues": { "default": "true", diff --git a/plugins/legend.js b/plugins/legend.js index 3349969..9954682 100644 --- a/plugins/legend.js +++ b/plugins/legend.js @@ -128,7 +128,7 @@ legend.prototype.select = function(e) { var xValue = e.selectedX; var points = e.selectedPoints; - if (e.dygraph.getOption("legendFollow")) { + if (e.dygraph.getOption("legend") === "follow") { // create floating legend div var area = e.dygraph.plotter_.area; var labelsDivWidth = e.dygraph.getOption("labelsDivWidth"); @@ -149,6 +149,7 @@ legend.prototype.select = function(e) { e.dygraph.graphDiv.appendChild(this.legend_div_); this.legend_div_.style.left = yAxisLabelWidth + leftLegend + "px"; this.legend_div_.style.top = topLegend + "px"; + this.legend_div_.style.display = "block"; } var html = generateLegendHTML(e.dygraph, xValue, points, this.one_em_width_); @@ -157,9 +158,8 @@ legend.prototype.select = function(e) { legend.prototype.deselect = function(e) { - if(e.dygraph.getOption("legendFollow")) { - // return legend to the default non-floating position - this.predraw(e); + if (e.dygraph.getOption("legend") === "follow") { + this.legend_div_.style.display = "none"; } // Have to do this every time, since styles might have changed. diff --git a/tests/customLabelFollow.html b/tests/customLabelFollow.html index 90c762f..9ac31bb 100644 --- a/tests/customLabelFollow.html +++ b/tests/customLabelFollow.html @@ -36,7 +36,7 @@ errorBars: true, labelsDivWidth: 100, labelsSeparateLines: true, - legendFollow: true, + legend: "follow", yAxisLabelWidth: 20 } ); -- 2.7.4