projects
/
dygraphs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of https://github.com/lrobb/dygraphs into lrobb
[dygraphs.git]
/
dygraph.js
diff --git
a/dygraph.js
b/dygraph.js
index
555bae4
..
1861fb6
100644
(file)
--- a/
dygraph.js
+++ b/
dygraph.js
@@
-235,22
+235,16
@@
Dygraph.prototype.__init__ = function(div, file, attrs) {
if (div.style.height == '' && attrs.height) {
div.style.height = attrs.height + "px";
}
if (div.style.height == '' && attrs.height) {
div.style.height = attrs.height + "px";
}
- if (div.offsetHeight == 0) {
+ if (div.
style.height == '' && div.
offsetHeight == 0) {
div.style.height = Dygraph.DEFAULT_HEIGHT + "px";
if (div.style.width == '') {
div.style.width = Dygraph.DEFAULT_WIDTH + "px";
}
}
div.style.height = Dygraph.DEFAULT_HEIGHT + "px";
if (div.style.width == '') {
div.style.width = Dygraph.DEFAULT_WIDTH + "px";
}
}
+ // these will be zero if the dygraph's div is hidden.
this.width_ = div.offsetWidth;
this.height_ = div.offsetHeight;
this.width_ = div.offsetWidth;
this.height_ = div.offsetHeight;
- if (this.width_ == 0) {
- this.error("dygraph has zero width. Please specify a width in pixels.");
- }
- if (this.height_ == 0) {
- this.error("dygraph has zero height. Please specify a height in pixels.");
- }
-
// TODO(danvk): set fillGraph to be part of attrs_ here, not user_attrs_.
if (attrs['stackedGraph']) {
attrs['fillGraph'] = true;
// TODO(danvk): set fillGraph to be part of attrs_ here, not user_attrs_.
if (attrs['stackedGraph']) {
attrs['fillGraph'] = true;
@@
-656,6
+650,12
@@
Dygraph.prototype.createInterface_ = function() {
this.createStatusMessage_();
this.createDragInterface_();
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();
+ });
};
/**
};
/**
@@
-777,6
+777,7
@@
Dygraph.prototype.createStatusMessage_ = function() {
"overflow": "hidden"};
Dygraph.update(messagestyle, this.attr_('labelsDivStyles'));
var div = document.createElement("div");
"overflow": "hidden"};
Dygraph.update(messagestyle, this.attr_('labelsDivStyles'));
var div = document.createElement("div");
+ div.className = "dygraph-legend";
for (var name in messagestyle) {
if (messagestyle.hasOwnProperty(name)) {
div.style[name] = messagestyle[name];
for (var name in messagestyle) {
if (messagestyle.hasOwnProperty(name)) {
div.style[name] = messagestyle[name];
@@
-1661,7
+1662,8
@@
Dygraph.dateTicker = function(startDate, endDate, self) {
if (chosen >= 0) {
return self.GetXAxis(startDate, endDate, chosen);
} else {
if (chosen >= 0) {
return self.GetXAxis(startDate, endDate, chosen);
} else {
- // TODO(danvk): signal error.
+ // this can happen if self.width_ is zero.
+ return [];
}
};
}
};
@@
-1881,6
+1883,8
@@
Dygraph.prototype.extremeValues_ = function(series) {
* number of axes, rolling averages, etc.
*/
Dygraph.prototype.predraw_ = function() {
* number of axes, rolling averages, etc.
*/
Dygraph.prototype.predraw_ = function() {
+ var start = new Date();
+
// TODO(danvk): move more computations out of drawGraph_ and into here.
this.computeYAxes_();
// TODO(danvk): move more computations out of drawGraph_ and into here.
this.computeYAxes_();
@@
-1902,6
+1906,10
@@
Dygraph.prototype.predraw_ = function() {
// If the data or options have changed, then we'd better redraw.
this.drawGraph_();
// 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);
};
/**
};
/**
@@
-1917,6
+1925,8
@@
Dygraph.prototype.predraw_ = function() {
* @private
*/
Dygraph.prototype.drawGraph_ = function(clearSelection) {
* @private
*/
Dygraph.prototype.drawGraph_ = function(clearSelection) {
+ var start = new Date();
+
if (typeof(clearSelection) === 'undefined') {
clearSelection = true;
}
if (typeof(clearSelection) === 'undefined') {
clearSelection = true;
}
@@
-2078,6
+2088,13
@@
Dygraph.prototype.drawGraph_ = function(clearSelection) {
if (this.attr_("drawCallback") !== null) {
this.attr_("drawCallback")(this, is_initial_draw);
}
if (this.attr_("drawCallback") !== null) {
this.attr_("drawCallback")(this, is_initial_draw);
}
+
+ if (this.attr_("timingName")) {
+ var end = new Date();
+ if (console) {
+ console.log(this.attr_("timingName") + " - drawGraph: " + (end - start) + "ms")
+ }
+ }
};
/**
};
/**
@@
-2979,9
+2996,8
@@
Dygraph.prototype.resize = function(width, height) {
width = height = null;
}
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";
if (width) {
this.maindiv_.style.width = width + "px";
@@
-2993,8
+3009,13
@@
Dygraph.prototype.resize = function(width, height) {
this.height_ = this.maindiv_.offsetHeight;
}
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;
};
this.resize_lock = false;
};