From c08d4ce2562a5780a2396aa6c83e70a67a62aaa5 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sun, 23 Nov 2014 16:12:31 -0500 Subject: [PATCH] Add legend: "never" option --- dygraph.js | 3 +- plugins/legend.js | 14 +++++++--- tests/customLabelFollow.html | 65 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 64 insertions(+), 18 deletions(-) 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):
+
-- 2.7.4