Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/mosaic/sql/src/transforms/scales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function scaleSymlog({ constant = 1 } = {}): ScaleTransform<number> {
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)), _))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test that the sql and js versions are consistent?

};
Expand Down
11 changes: 11 additions & 0 deletions packages/mosaic/sql/test/scales.test.ts
Original file line number Diff line number Diff line change
@@ -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<number>({ type: 'symlog' });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test this across constants?

for (const x of [5, 10, 100, -7, 1, 0.5]) {
expect(s.invert(s.apply(x))).toBeCloseTo(x, 9);
}
});
});