Skip to content

Commit

Permalink
Warn if points are out of range
Browse files Browse the repository at this point in the history
Some users may improperly define the range of their axes, leading to
points being drawn outside of the chart area. In the worst cases, if
all points are out of range, the chart will not be drawn at all.

Adding a warning can help users identify this issue and correct it.

2 x points are allowed in order to draw the edges of the chart when
zoomed in.
  • Loading branch information
deribaucourt committed Oct 25, 2024
1 parent ea40d17 commit e292736
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dygraph-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,14 @@ DygraphLayout.prototype._evaluateLineCharts = function() {
var axis = this.dygraph_.axisPropertiesForSeries(setName);
// TODO (konigsberg): use optionsForAxis instead.
var logscale = this.dygraph_.attributes_.getForSeries("logscale", setName);
var outOfXBounds = 0, outOfYBounds = 0;

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

// Range from 0-1 where 0 represents left and 1 represents right.
point.x = DygraphLayout.calcXNormal_(point.xval, this._xAxis, isLogscaleForX);
outOfXBounds += (point.x < 0) || (point.x > 1);
// Range from 0-1 where 0 represents top and 1 represents bottom
var yval = point.yval;
if (isStacked) {
Expand All @@ -269,6 +271,14 @@ DygraphLayout.prototype._evaluateLineCharts = function() {
}
}
point.y = DygraphLayout.calcYNormal_(axis, yval, logscale);
outOfYBounds += (point.y < 0) || (point.y > 1);
}

if (outOfXBounds > 2) {
console.warn(outOfXBounds + ' points out of X bounds:' + this._xAxis.minval + ' - ' + this._xAxis.maxval);
}
if (outOfYBounds > 0) {
console.warn(outOfYBounds + ' points out of Y bounds:' + axis.minyval + ' - ' + axis.maxyval);
}

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

0 comments on commit e292736

Please sign in to comment.