Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/scale/Log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Loading