From a4094ad124afb9c88c2023e9fd23e7017ab93218 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Thu, 29 Sep 2016 11:44:48 -0400 Subject: [PATCH] Set x appropriately for series but not point selection (#779) --- auto_tests/tests/plugins_legend.js | 12 ++++++++++++ src/dygraph.js | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/auto_tests/tests/plugins_legend.js b/auto_tests/tests/plugins_legend.js index 5f67591..e2ee4f1 100644 --- a/auto_tests/tests/plugins_legend.js +++ b/auto_tests/tests/plugins_legend.js @@ -113,6 +113,18 @@ it('should use a legendFormatter', function() { assert.equal(calls[2].series[0].y, undefined); }); +it('should work with highlight series', () => { + var calls = []; + var g = new Dygraph(graph, 'X,y1,y2\n1,2,3\n', { + highlightSeriesOpts: { + strokeWidth: 3, + } + }); + + g.setSelection(false, 'y2'); + assert.equal(Util.getLegend(graph), ''); +}); + it('should include point drawn where canvas-y is 0', function () { var graph = document.getElementById("graph"); var calls = [] diff --git a/src/dygraph.js b/src/dygraph.js index ce9f110..e0fcb58 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -1710,8 +1710,8 @@ Dygraph.prototype.animateSelection_ = function(direction) { Dygraph.prototype.updateSelection_ = function(opt_animFraction) { /*var defaultPrevented = */ this.cascadeEvents_('select', { - selectedRow: this.lastRow_, - selectedX: this.lastx_, + selectedRow: this.lastRow_ === -1 ? undefined : this.lastRow_, + selectedX: this.lastx_ === -1 ? undefined : this.lastx_, selectedPoints: this.selPoints_ }); // TODO(danvk): use defaultPrevented here? @@ -1787,6 +1787,10 @@ Dygraph.prototype.updateSelection_ = function(opt_animFraction) { * Manually set the selected points and display information about them in the * legend. The selection can be cleared using clearSelection() and queried * using getSelection(). + * + * To set a selected series but not a selected point, call setSelection with + * row=false and the selected series name. + * * @param {number} row Row number that should be highlighted (i.e. appear with * hover dots on the chart). * @param {seriesName} optional series name to highlight that series with the -- 2.7.4