From: Dan Vanderkam Date: Sun, 23 Nov 2014 21:12:31 +0000 (-0500) Subject: Add legend: "never" option X-Git-Tag: v1.1.0~11^2~1 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=c08d4ce2562a5780a2396aa6c83e70a67a62aaa5;p=dygraphs.git Add legend: "never" option --- diff --git a/dygraph.js b/dygraph.js index b1af8de..efc9092 100644 --- a/dygraph.js +++ b/dygraph.js @@ -312,8 +312,7 @@ Dygraph.DEFAULT_ATTRS = { stackedGraphNaNFill: 'all', hideOverlayOnMouseOut: true, - // TODO(danvk): support 'onmouseover' and 'never', and remove synonyms. - legend: 'onmouseover', // the only relevant value at the moment is 'always'. + legend: 'onmouseover', stepPlot: false, avoidMinZero: false, xRangePad: 0, diff --git a/plugins/legend.js b/plugins/legend.js index bb86949..65ee671 100644 --- a/plugins/legend.js +++ b/plugins/legend.js @@ -125,7 +125,13 @@ legend.prototype.select = function(e) { var xValue = e.selectedX; var points = e.selectedPoints; - if (e.dygraph.getOption('legend') === 'follow') { + 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'); @@ -146,16 +152,16 @@ 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 = ''; } var html = legend.generateLegendHTML(e.dygraph, xValue, points, this.one_em_width_); this.legend_div_.innerHTML = html; + this.legend_div_.style.display = ''; }; legend.prototype.deselect = function(e) { - - if (e.dygraph.getOption("legend") === "follow") { + var legendMode = e.dygraph.getOption('legend'); + if (legendMode !== 'always') { this.legend_div_.style.display = "none"; } diff --git a/tests/customLabelFollow.html b/tests/customLabelFollow.html index 76d3822..b2362a4 100644 --- a/tests/customLabelFollow.html +++ b/tests/customLabelFollow.html @@ -22,23 +22,64 @@ box-shadow: 4px 4px 4px #888; pointer-events: none; } + pre { + margin-top: 30px; + } -

Legend follows highlighted points:

-
+

This page demonstrates different values for the legend option. Mouse over the charts to see the different behaviors.

+
legend: "follow":
+
+ +
legend: "always":
+
+ +
legend: "never":
+
+ +
legend: "onmouseover" (the default):
+