-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjitterY.ts
30 lines (27 loc) · 989 Bytes
/
jitterY.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { deepMix } from '@antv/util';
import { TransformComponent as TC } from '../runtime';
import { JitterYTransform } from '../spec';
import { column, columnOf } from './utils/helper';
import { rangeOf, interpolate } from './jitter';
export type JitterYOptions = Omit<JitterYTransform, 'type'>;
/**
* The JitterY transform produce dy channels for marks (especially for point)
* with ordinal x and y dimension, say to make them jitter in their own space.
*/
export const JitterY: TC<JitterYOptions> = (options = {}) => {
const { padding = 0, random = Math.random } = options;
return (I, mark) => {
const { encode, scale } = mark;
const { y: scaleY } = scale;
const [Y] = columnOf(encode, 'y');
const rangeY = rangeOf(Y, scaleY, padding);
const DY = I.map(() => interpolate(random(), ...rangeY));
return [
I,
deepMix({ scale: { y: { padding: 0.5 } } }, mark, {
encode: { dy: column(DY) },
}),
];
};
};
JitterY.props = {};