projects
/
dygraphs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
minor tweaks to jeremy's change
[dygraphs.git]
/
dygraph.js
diff --git
a/dygraph.js
b/dygraph.js
index
3e32297
..
656d7a8
100644
(file)
--- a/
dygraph.js
+++ b/
dygraph.js
@@
-156,7
+156,7
@@
Dygraph.DEFAULT_ATTRS = {
yValueFormatter: function(x, opt_precision) {
var s = Dygraph.floatFormat(x, opt_precision);
var s2 = Dygraph.intFormat(x);
yValueFormatter: function(x, opt_precision) {
var s = Dygraph.floatFormat(x, opt_precision);
var s2 = Dygraph.intFormat(x);
- return s.length <
=
s2.length ? s : s2;
+ return s.length < s2.length ? s : s2;
},
strokeWidth: 1.0,
},
strokeWidth: 1.0,
@@
-221,7
+221,7
@@
Dygraph.prototype.__old_init__ = function(div, file, labels, attrs) {
/**
* Initializes the Dygraph. This creates a new DIV and constructs the PlotKit
/**
* Initializes the Dygraph. This creates a new DIV and constructs the PlotKit
- * and context <canvas> inside of it. See the constructor for details
+ * and context <canvas> inside of it. See the constructor for details
.
* on the parameters.
* @param {Element} div the Element to render the graph into.
* @param {String | Function} file Source data
* on the parameters.
* @param {Element} div the Element to render the graph into.
* @param {String | Function} file Source data
@@
-254,7
+254,7
@@
Dygraph.prototype.__init__ = function(div, file, attrs) {
this.wilsonInterval_ = attrs.wilsonInterval || true;
this.is_initial_draw_ = true;
this.annotations_ = [];
this.wilsonInterval_ = attrs.wilsonInterval || true;
this.is_initial_draw_ = true;
this.annotations_ = [];
-
+
// Number of digits to use when labeling the x (if numeric) and y axis
// ticks.
this.numXDigits_ = 2;
// Number of digits to use when labeling the x (if numeric) and y axis
// ticks.
this.numXDigits_ = 2;
@@
-331,6
+331,12
@@
Dygraph.prototype.__init__ = function(div, file, attrs) {
this.start_();
};
this.start_();
};
+Dygraph.prototype.toString = function() {
+ var maindiv = this.maindiv_;
+ var id = (maindiv && maindiv.id) ? maindiv.id : maindiv
+ return "[Dygraph " + id + "]";
+}
+
Dygraph.prototype.attr_ = function(name, seriesName) {
if (seriesName &&
typeof(this.user_attrs_[seriesName]) != 'undefined' &&
Dygraph.prototype.attr_ = function(name, seriesName) {
if (seriesName &&
typeof(this.user_attrs_[seriesName]) != 'undefined' &&
@@
-1469,6
+1475,9
@@
Dygraph.prototype.mouseMove_ = function(event) {
var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(this.mouseEventElement_);
var points = this.layout_.points;
var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(this.mouseEventElement_);
var points = this.layout_.points;
+ // This prevents JS errors when mousing over the canvas before data loads.
+ if (points === undefined) return;
+
var lastx = -1;
var lasty = -1;
var lastx = -1;
var lasty = -1;
@@
-1799,8
+1808,10
@@
Dygraph.prototype.addXTicks_ = function() {
var ret = formatter(range[0], range[1], this);
var xTicks = [];
var ret = formatter(range[0], range[1], this);
var xTicks = [];
+ // Note: numericTicks() returns a {ticks: [...], numDigits: yy} dictionary,
+ // whereas dateTicker and user-defined tickers typically just return a ticks
+ // array.
if (ret.ticks !== undefined) {
if (ret.ticks !== undefined) {
- // numericTicks() returns multiple values.
xTicks = ret.ticks;
this.numXDigits_ = ret.numDigits;
} else {
xTicks = ret.ticks;
this.numXDigits_ = ret.numDigits;
} else {
@@
-2110,7
+2121,7
@@
Dygraph.numericTicks = function(minV, maxV, self, axis_props, vals) {
var ticks = [];
if (vals) {
for (var i = 0; i < vals.length; i++) {
var ticks = [];
if (vals) {
for (var i = 0; i < vals.length; i++) {
- ticks
[i]
.push({v: vals[i]});
+ ticks.push({v: vals[i]});
}
} else {
if (axis_props && attr("logscale")) {
}
} else {
if (axis_props && attr("logscale")) {
@@
-2224,6
+2235,7
@@
Dygraph.numericTicks = function(minV, maxV, self, axis_props, vals) {
// Add labels to the ticks.
for (var i = 0; i < ticks.length; i++) {
// Add labels to the ticks.
for (var i = 0; i < ticks.length; i++) {
+ if (ticks[i].label !== undefined) continue; // Use current label.
var tickV = ticks[i].v;
var absTickV = Math.abs(tickV);
var label = (formatter !== undefined) ?
var tickV = ticks[i].v;
var absTickV = Math.abs(tickV);
var label = (formatter !== undefined) ?
@@
-2233,13
+2245,14
@@
Dygraph.numericTicks = function(minV, maxV, self, axis_props, vals) {
var n = k*k*k*k;
for (var j = 3; j >= 0; j--, n /= k) {
if (absTickV >= n) {
var n = k*k*k*k;
for (var j = 3; j >= 0; j--, n /= k) {
if (absTickV >= n) {
- label =
(tickV / n).toPrecision(
numDigits) + k_labels[j];
+ label =
formatter(tickV / n,
numDigits) + k_labels[j];
break;
}
}
break;
}
}
- ticks[i].label = label;
}
}
+ ticks[i].label = label;
}
}
+
return {ticks: ticks, numDigits: numDigits};
};
return {ticks: ticks, numDigits: numDigits};
};
@@
-2355,7
+2368,7
@@
Dygraph.prototype.drawGraph_ = function() {
// On the log scale, points less than zero do not exist.
// This will create a gap in the chart. Note that this ignores
// connectSeparatedPoints.
// On the log scale, points less than zero do not exist.
// This will create a gap in the chart. Note that this ignores
// connectSeparatedPoints.
- if (point < 0) {
+ if (point <
=
0) {
point = null;
}
series.push([date, point]);
point = null;
}
series.push([date, point]);