1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Jitter = exports.interpolate = exports.rangeOf = void 0;
|
4 | const scale_1 = require("@antv/scale");
|
5 | const util_1 = require("@antv/util");
|
6 | const helper_1 = require("./utils/helper");
|
7 | const order_1 = require("./utils/order");
|
8 | function rangeOf(value, scaleOptions, padding) {
|
9 | if (value === null)
|
10 | return [-0.5, 0.5];
|
11 | const domain = (0, order_1.domainOf)(value, scaleOptions);
|
12 | const scale = new scale_1.Band({ domain, range: [0, 1], padding });
|
13 | const step = scale.getBandWidth();
|
14 | return [-step / 2, step / 2];
|
15 | }
|
16 | exports.rangeOf = rangeOf;
|
17 | function interpolate(t, a, b) {
|
18 | return a * (1 - t) + b * t;
|
19 | }
|
20 | exports.interpolate = interpolate;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const Jitter = (options = {}) => {
|
26 | const { padding = 0, paddingX = padding, paddingY = padding, random = Math.random, } = options;
|
27 | return (I, mark) => {
|
28 | const { encode, scale } = mark;
|
29 | const { x: scaleX, y: scaleY } = scale;
|
30 | const [X] = (0, helper_1.columnOf)(encode, 'x');
|
31 | const [Y] = (0, helper_1.columnOf)(encode, 'y');
|
32 | const rangeX = rangeOf(X, scaleX, paddingX);
|
33 | const rangeY = rangeOf(Y, scaleY, paddingY);
|
34 | const DY = I.map(() => interpolate(random(), ...rangeY));
|
35 | const DX = I.map(() => interpolate(random(), ...rangeX));
|
36 | return [
|
37 | I,
|
38 | (0, util_1.deepMix)({
|
39 | scale: {
|
40 | x: { padding: 0.5 },
|
41 | y: { padding: 0.5 },
|
42 | },
|
43 | }, mark, {
|
44 | encode: { dy: (0, helper_1.column)(DY), dx: (0, helper_1.column)(DX) },
|
45 | }),
|
46 | ];
|
47 | };
|
48 | };
|
49 | exports.Jitter = Jitter;
|
50 | exports.Jitter.props = {};
|
51 |
|
\ | No newline at end of file |