From 4b4d1a63e7e4723419f540bf8265c609783bc0fd Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Wed, 27 Jul 2011 03:14:43 -0400 Subject: [PATCH] resize automatically --- dygraph.js | 24 +++++++++++++++++++----- tests/resize.html | 15 ++++++++------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/dygraph.js b/dygraph.js index a1f8c1c..dcc555c 100644 --- a/dygraph.js +++ b/dygraph.js @@ -656,6 +656,12 @@ Dygraph.prototype.createInterface_ = function() { this.createStatusMessage_(); this.createDragInterface_(); + + // Update when the window is resized. + // TODO(danvk): drop frames depending on complexity of the chart. + Dygraph.addEvent(window, 'resize', function(e) { + dygraph.resize(); + }); }; /** @@ -1904,6 +1910,10 @@ Dygraph.prototype.predraw_ = function() { // If the data or options have changed, then we'd better redraw. this.drawGraph_(); + + // This is used to determine whether to do various animations. + var end = new Date(); + this.drawingTimeMs_ = (end - start); }; /** @@ -2990,9 +3000,8 @@ Dygraph.prototype.resize = function(width, height) { width = height = null; } - // TODO(danvk): there should be a clear() method. - this.maindiv_.innerHTML = ""; - this.attrs_.labelsDiv = null; + var old_width = this.width_; + var old_height = this.height_; if (width) { this.maindiv_.style.width = width + "px"; @@ -3004,8 +3013,13 @@ Dygraph.prototype.resize = function(width, height) { this.height_ = this.maindiv_.offsetHeight; } - this.createInterface_(); - this.predraw_(); + if (old_width != this.width_ || old_height != this.height_) { + // TODO(danvk): there should be a clear() method. + this.maindiv_.innerHTML = ""; + this.attrs_.labelsDiv = null; + this.createInterface_(); + this.predraw_(); + } this.resize_lock = false; }; diff --git a/tests/resize.html b/tests/resize.html index 2d2a02e..562fa9c 100644 --- a/tests/resize.html +++ b/tests/resize.html @@ -14,13 +14,18 @@ -
+

Resize the window. The dygraph will resize with it.

+
-- 2.7.4