diff --git a/src/scale/Interval.ts b/src/scale/Interval.ts index 1f4a7f98e8..866051dcf2 100644 --- a/src/scale/Interval.ts +++ b/src/scale/Interval.ts @@ -250,7 +250,8 @@ class IntervalScale = Dictionary> e if (extent[0] === extent[1]) { if (extent[0] !== 0) { // Expand extent - const expandSize = extent[0]; + // Note that extents can be both negative. See #13154 + const expandSize = Math.abs(extent[0]); // In the fowllowing case // Axis has been fixed max 100 // Plus data are all 100 and axis extent are [100, 100]. diff --git a/src/scale/Log.ts b/src/scale/Log.ts index 41586e8775..b1f4d08b16 100644 --- a/src/scale/Log.ts +++ b/src/scale/Log.ts @@ -85,9 +85,10 @@ class LogScale extends Scale { } setExtent(start: number, end: number): void { - const base = this.base; - start = mathLog(start) / mathLog(base); - end = mathLog(end) / mathLog(base); + const base = mathLog(this.base); + // log(-Infinity) is NaN, so safe guard here + start = mathLog(Math.max(0, start)) / base; + end = mathLog(Math.max(0, end)) / base; intervalScaleProto.setExtent.call(this, start, end); } diff --git a/test/logScale.html b/test/logScale.html index e91507ac10..def5bfdfdc 100644 --- a/test/logScale.html +++ b/test/logScale.html @@ -26,12 +26,13 @@
+
+ \ No newline at end of file