From c885e65033b45ced14536b61be8265d1a842f8a2 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Tue, 5 Jul 2022 16:46:52 +0800 Subject: [PATCH 1/2] fix(log): fix log axis breaks a single data whose log value is negative #13154 --- src/scale/Interval.ts | 3 ++- src/scale/Log.ts | 5 +++-- test/logScale.html | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) 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..6354e9eed0 100644 --- a/src/scale/Log.ts +++ b/src/scale/Log.ts @@ -86,8 +86,9 @@ class LogScale extends Scale { setExtent(start: number, end: number): void { const base = this.base; - start = mathLog(start) / mathLog(base); - end = mathLog(end) / mathLog(base); + // log(-Infinity) is NaN, so safe guard here + start = mathLog(Math.max(0, start)) / mathLog(base); + end = mathLog(Math.max(0, end)) / mathLog(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 From 4bf7f4d564410496406881610b34eab303020fbc Mon Sep 17 00:00:00 2001 From: Ovilia Date: Wed, 6 Jul 2022 15:07:12 +0800 Subject: [PATCH 2/2] fix(log): cache base variable --- src/scale/Log.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scale/Log.ts b/src/scale/Log.ts index 6354e9eed0..b1f4d08b16 100644 --- a/src/scale/Log.ts +++ b/src/scale/Log.ts @@ -85,10 +85,10 @@ class LogScale extends Scale { } setExtent(start: number, end: number): void { - const base = this.base; + const base = mathLog(this.base); // log(-Infinity) is NaN, so safe guard here - start = mathLog(Math.max(0, start)) / mathLog(base); - end = mathLog(Math.max(0, end)) / mathLog(base); + start = mathLog(Math.max(0, start)) / base; + end = mathLog(Math.max(0, end)) / base; intervalScaleProto.setExtent.call(this, start, end); }