From 3ebe24c54262cf54b188e3ebbd49fdc51899030b Mon Sep 17 00:00:00 2001 From: hanjano Date: Thu, 13 Feb 2025 20:38:19 +0100 Subject: [PATCH 1/2] fix: symmetric log charting --- src/scale/Log.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/scale/Log.ts b/src/scale/Log.ts index a9ae206011..4e7c624c96 100644 --- a/src/scale/Log.ts +++ b/src/scale/Log.ts @@ -42,14 +42,17 @@ const mathLog = Math.log; * symmetric log, allowing negative values for logarithmic scales */ -const C = mathLog(10) +function symMathLog(x: number, linthresh: number = 0.03): number { + if (x >= -linthresh && x <= linthresh) { + const mul = (2 + mathLog(linthresh)) / linthresh + return x * mul + } -function symMathLog(x: number): number { - if (x >= 0) { - return mathLog(1 + x / C); + if (x > 0) { + return 2 + mathLog(x) } - return -mathLog(1 - x / C); + return - 2 - mathLog(-x) } /** From a6dd7fde984aec361c595aebafa92b779bc3cbb6 Mon Sep 17 00:00:00 2001 From: hanjano Date: Fri, 14 Feb 2025 08:53:05 +0100 Subject: [PATCH 2/2] fix: lint --- src/scale/Log.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/scale/Log.ts b/src/scale/Log.ts index 4e7c624c96..1035f7b012 100644 --- a/src/scale/Log.ts +++ b/src/scale/Log.ts @@ -44,15 +44,15 @@ const mathLog = Math.log; function symMathLog(x: number, linthresh: number = 0.03): number { if (x >= -linthresh && x <= linthresh) { - const mul = (2 + mathLog(linthresh)) / linthresh - return x * mul + const mul = (2 + mathLog(linthresh)) / linthresh; + return x * mul; } if (x > 0) { - return 2 + mathLog(x) + return 2 + mathLog(x); } - - return - 2 - mathLog(-x) + + return -2 - mathLog(-x); } /**