From af3fd038500714d4b815d033288017fe4ba9d96c Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Tue, 22 Oct 2024 16:16:27 +0200 Subject: [PATCH] Warn if points are out of range 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. Note that may spew a lot of warnings if their are a lot of points. --- src/dygraph-layout.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dygraph-layout.js b/src/dygraph-layout.js index 71d38051..d43fbb5d 100644 --- a/src/dygraph-layout.js +++ b/src/dygraph-layout.js @@ -253,6 +253,9 @@ DygraphLayout.prototype._evaluateLineCharts = function() { // Range from 0-1 where 0 represents left and 1 represents right. point.x = DygraphLayout.calcXNormal_(point.xval, this._xAxis, isLogscaleForX); + if (point.x < 0 || point.x > 1) { + console.warn('x value ' + point.xval + ' out of range ' + this._xAxis.minval + ' - ' + this._xAxis.maxval); + } // Range from 0-1 where 0 represents top and 1 represents bottom var yval = point.yval; if (isStacked) { @@ -269,6 +272,9 @@ DygraphLayout.prototype._evaluateLineCharts = function() { } } point.y = DygraphLayout.calcYNormal_(axis, yval, logscale); + if (point.y < 0 || point.y > 1) { + console.warn('y value ' + point.yval + ' out of range ' + axis.minyval + ' - ' + axis.maxyval); + } } this.dygraph_.dataHandler_.onLineEvaluated(points, axis, logscale);