From 1788d90eed073eb0c3e628819965990085258f0b Mon Sep 17 00:00:00 2001 From: Robin Vanhove Date: Mon, 25 Jan 2016 14:25:23 +0100 Subject: [PATCH] fix the zoom rectangle and legend on dynamic updates --- auto_tests/tests/resize.js | 4 ++-- src/dygraph.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/auto_tests/tests/resize.js b/auto_tests/tests/resize.js index 6230ffb94..d31ceb0e5 100644 --- a/auto_tests/tests/resize.js +++ b/auto_tests/tests/resize.js @@ -43,14 +43,14 @@ it('testResizeMaintainsMouseOperations', function() { var g = new Dygraph(graph, data, {highlightCallback: callback}); strum(g, 300, 640); - assert.equal(6, callbackCount); + assert.equal(7, callbackCount); graph.style.width = "500px"; g.resize(); callbackCount = 0; strum(g, 300, 500); - assert.equal(6, callbackCount); + assert.equal(7, callbackCount); }); /** diff --git a/src/dygraph.js b/src/dygraph.js index 41e5cc15a..da0e129a6 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -217,6 +217,8 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { this.eventListeners_ = {}; this.attributes_ = new DygraphOptions(this); + this.lastMouseMoveEvent_ = null; + this.currentZoomRectArgs_ = null; // Create the containing DIV and other interactive elements this.createInterface_(); @@ -1247,6 +1249,7 @@ Dygraph.prototype.drawZoomRect_ = function(direction, startX, endX, startY, endY, prevDirection, prevEndX, prevEndY) { var ctx = this.canvas_ctx_; + this.currentZoomRectArgs_ = arguments; // Clean up from the previous rect if necessary if (prevDirection == utils.HORIZONTAL) { @@ -1664,6 +1667,8 @@ Dygraph.prototype.findStackedPoint = function(domX, domY) { * @private */ Dygraph.prototype.mouseMove_ = function(event) { + this.lastMouseMoveEvent_ = event; + // This prevents JS errors when mousing over the canvas before data loads. var points = this.layout_.points; if (points === undefined || points === null) return; @@ -2421,6 +2426,15 @@ Dygraph.prototype.renderGraph_ = function(is_initial_draw) { fn(this); } } + + if(this.lastMouseMoveEvent_ !== null) + { + this.mouseMove_(this.lastMouseMoveEvent_); + } + if(this.currentZoomRectArgs_ !== null) + { + this.drawZoomRect_.apply(this, this.currentZoomRectArgs_); + } }; /**