Skip to content

Commit ddcc301

Browse files
committed
Merge branch 'master' of github.com:danvk/dygraphs
2 parents a334624 + f9ae77b commit ddcc301

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/dygraph-layout.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,14 @@ DygraphLayout.prototype._evaluateLineCharts = function() {
248248
var axis = this.dygraph_.axisPropertiesForSeries(setName);
249249
// TODO (konigsberg): use optionsForAxis instead.
250250
var logscale = this.dygraph_.attributes_.getForSeries("logscale", setName);
251+
var outOfXBounds = 0, outOfYBounds = 0;
251252

252253
for (var j = 0; j < points.length; j++) {
253254
var point = points[j];
254255

255256
// Range from 0-1 where 0 represents left and 1 represents right.
256257
point.x = DygraphLayout.calcXNormal_(point.xval, this._xAxis, isLogscaleForX);
258+
outOfXBounds += (point.x < 0) || (point.x > 1);
257259
// Range from 0-1 where 0 represents top and 1 represents bottom
258260
var yval = point.yval;
259261
if (isStacked) {
@@ -270,6 +272,14 @@ DygraphLayout.prototype._evaluateLineCharts = function() {
270272
}
271273
}
272274
point.y = DygraphLayout.calcYNormal_(axis, yval, logscale);
275+
outOfYBounds += (point.y < 0) || (point.y > 1);
276+
}
277+
278+
if (outOfXBounds > 2) {
279+
console.warn(outOfXBounds + ' points out of X bounds:' + this._xAxis.minval + ' - ' + this._xAxis.maxval);
280+
}
281+
if (outOfYBounds > 0) {
282+
console.warn(outOfYBounds + ' points out of Y bounds:' + axis.minyval + ' - ' + axis.maxyval);
273283
}
274284

275285
this.dygraph_.dataHandler_.onLineEvaluated(points, axis, logscale);

src/extras/crosshair.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {
3333
this.strokeStyle_ = opt_options.strokeStyle || "rgba(0, 0, 0, 0.3)";
3434
};
3535

36+
crosshair.prototype.updateCanvasSize = function updateCanvasSize(width, height) {
37+
if (width === this.canvas_.width && height === this.canvas_.height) return;
38+
this.canvas_.width = width;
39+
this.canvas_.height = height;
40+
this.canvas_.style.width = width + 'px'; // for IE
41+
this.canvas_.style.height = height + 'px'; // for IE
42+
};
43+
3644
crosshair.prototype.toString = function toString() {
3745
return "Crosshair Plugin";
3846
};
@@ -42,6 +50,7 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {
4250
* @return {object.<string, function(ev)>} Mapping of event names to callbacks.
4351
*/
4452
crosshair.prototype.activate = function activate(g) {
53+
this.updateCanvasSize(g.width_, g.height_);
4554
g.graphDiv.appendChild(this.canvas_);
4655

4756
return {
@@ -57,21 +66,20 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {
5766

5867
var width = e.dygraph.width_;
5968
var height = e.dygraph.height_;
60-
this.canvas_.width = width;
61-
this.canvas_.height = height;
62-
this.canvas_.style.width = width + "px"; // for IE
63-
this.canvas_.style.height = height + "px"; // for IE
69+
this.updateCanvasSize(width, height);
6470

6571
var ctx = this.canvas_.getContext("2d");
6672
ctx.clearRect(0, 0, width, height);
6773
ctx.strokeStyle = this.strokeStyle_;
6874
ctx.beginPath();
69-
70-
var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering
71-
72-
if (this.direction_ === "vertical" || this.direction_ === "both") {
73-
ctx.moveTo(canvasx, 0);
74-
ctx.lineTo(canvasx, height);
75+
76+
if (e.dygraph.selPoints_.length !== 0) {
77+
var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering
78+
79+
if (this.direction_ === "vertical" || this.direction_ === "both") {
80+
ctx.moveTo(canvasx, 0);
81+
ctx.lineTo(canvasx, height);
82+
}
7583
}
7684

7785
if (this.direction_ === "horizontal" || this.direction_ === "both") {

0 commit comments

Comments
 (0)