Skip to content

Commit 806ec8a

Browse files
committed
fix: symmetric log charting
1 parent 53ab10a commit 806ec8a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/scale/Log.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ const mathLog = Math.log;
4242
* symmetric log, allowing negative values for logarithmic scales
4343
*/
4444

45-
const C = mathLog(10)
45+
function symMathLog(x: number, linthresh: number = 0.03): number {
46+
if (x >= -linthresh && x <= linthresh) {
47+
const mul = (2 + mathLog(linthresh)) / linthresh
48+
return x * mul
49+
}
4650

47-
function symMathLog(x: number): number {
48-
if (x >= 0) {
49-
return mathLog(1 + x / C);
51+
if (x > 0) {
52+
return 2 + mathLog(x)
5053
}
5154

52-
return -mathLog(1 - x / C);
55+
return - 2 - mathLog(-x)
5356
}
5457

5558
/**

0 commit comments

Comments
 (0)