diff --git a/packages/mosaic/sql/src/transforms/scales.ts b/packages/mosaic/sql/src/transforms/scales.ts index 49b9ae9d4..eeed09a71 100644 --- a/packages/mosaic/sql/src/transforms/scales.ts +++ b/packages/mosaic/sql/src/transforms/scales.ts @@ -88,7 +88,7 @@ function scaleSymlog({ constant = 1 } = {}): ScaleTransform { const _ = +constant; return { apply: x => Math.sign(x) * Math.log1p(Math.abs(x)), - invert: x => Math.sign(x) * Math.exp(Math.abs(x) - _), + invert: x => Math.sign(x) * (Math.exp(Math.abs(x)) - _), sqlApply: c => (c = asNode(c), mul(sign(c), ln(add(_, abs(c))))), sqlInvert: c => mul(sign(c), sub(exp(abs(c)), _)) }; diff --git a/packages/mosaic/sql/test/scales.test.ts b/packages/mosaic/sql/test/scales.test.ts new file mode 100644 index 000000000..54c61ffdb --- /dev/null +++ b/packages/mosaic/sql/test/scales.test.ts @@ -0,0 +1,11 @@ +import { expect, describe, it } from 'vitest'; +import { scaleTransform } from '../src/index.js'; + +describe('scaleTransform', () => { + it('symlog invert is the inverse of apply', () => { + const s = scaleTransform({ type: 'symlog' }); + for (const x of [5, 10, 100, -7, 1, 0.5]) { + expect(s.invert(s.apply(x))).toBeCloseTo(x, 9); + } + }); +});