From fc4e84fafa99a27372b55bbd5f28f8af8429f3d0 Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Fri, 13 May 2011 11:37:40 -0400 Subject: [PATCH 1/1] When pan is the default behavior, clearSelection can't be called on redraw. --- auto_tests/tests/interaction_model.js | 3 +-- dygraph.js | 30 +++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/auto_tests/tests/interaction_model.js b/auto_tests/tests/interaction_model.js index 2698b5f..6249731 100644 --- a/auto_tests/tests/interaction_model.js +++ b/auto_tests/tests/interaction_model.js @@ -123,7 +123,6 @@ InteractionModelTestCase.prototype.testClickCallbackIsCalledOnCustomPan = functi DygraphOps.dispatchMouseMove_Point(g, 10, 10); DygraphOps.dispatchMouseUp_Point(g, 10, 10); - // THIS STILL FAILS. It's clicked, but x is undefined. - // assertEquals(20, clicked); + assertEquals(20, clicked); }; diff --git a/dygraph.js b/dygraph.js index 61e8e49..c10ef05 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1227,7 +1227,7 @@ Dygraph.Interaction.movePan = function(event, g, context) { } } - g.drawGraph_(); + g.drawGraph_(false); }; /** @@ -2674,9 +2674,19 @@ Dygraph.prototype.predraw_ = function() { * Update the graph with new data. This method is called when the viewing area * has changed. If the underlying data or options have changed, predraw_ will * be called before drawGraph_ is called. + * + * clearSelection, when undefined or true, causes this.clearSelection to be + * called at the end of the draw operation. This should rarely be defined, + * and never true (that is it should be undefined most of the time, and + * rarely false.) + * * @private */ -Dygraph.prototype.drawGraph_ = function() { +Dygraph.prototype.drawGraph_ = function(clearSelection) { + if (typeof clearSelection === 'undefined') { + clearSelection = true; + } + var data = this.rawData_; // This is used to set the second parameter to drawCallback, below. @@ -2819,13 +2829,15 @@ Dygraph.prototype.drawGraph_ = function() { // Generate a static legend before any particular point is selected. this.setLegendHTML_(); } else { - if (typeof(this.selPoints_) !== 'undefined' && this.selPoints_.length) { - // We should select the point nearest the page x/y here, but it's easier - // to just clear the selection. This prevents erroneous hover dots from - // being displayed. - this.clearSelection(); - } else { - this.clearSelection(); + if (clearSelection) { + if (typeof(this.selPoints_) !== 'undefined' && this.selPoints_.length) { + // We should select the point nearest the page x/y here, but it's easier + // to just clear the selection. This prevents erroneous hover dots from + // being displayed. + this.clearSelection(); + } else { + this.clearSelection(); + } } } -- 2.7.4