@antv/g2 5.1.10 → 5.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/animation/scaleInY.js +103 -33
  4. package/esm/animation/scaleInY.js.map +1 -1
  5. package/esm/component/slider.js +32 -2
  6. package/esm/component/slider.js.map +1 -1
  7. package/esm/index.d.ts +2 -0
  8. package/esm/interaction/tooltip.js +11 -8
  9. package/esm/interaction/tooltip.js.map +1 -1
  10. package/esm/lib/core.d.ts +1 -0
  11. package/esm/lib/core.js +2 -1
  12. package/esm/lib/core.js.map +1 -1
  13. package/esm/lib/std.d.ts +1 -0
  14. package/esm/runtime/library.js +7 -4
  15. package/esm/runtime/library.js.map +1 -1
  16. package/esm/runtime/plot.js +16 -4
  17. package/esm/runtime/plot.js.map +1 -1
  18. package/esm/runtime/render.js +5 -2
  19. package/esm/runtime/render.js.map +1 -1
  20. package/esm/shape/area/smooth.d.ts +1 -3
  21. package/esm/shape/area/smooth.js +9 -5
  22. package/esm/shape/area/smooth.js.map +1 -1
  23. package/esm/shape/line/smooth.d.ts +1 -3
  24. package/esm/shape/line/smooth.js +2 -2
  25. package/esm/shape/line/smooth.js.map +1 -1
  26. package/esm/spec/composition.d.ts +1 -1
  27. package/esm/spec/mark.d.ts +1 -1
  28. package/esm/spec/transform.d.ts +7 -2
  29. package/esm/transform/index.d.ts +2 -0
  30. package/esm/transform/index.js +1 -0
  31. package/esm/transform/index.js.map +1 -1
  32. package/esm/transform/jitterY.d.ts +8 -0
  33. package/esm/transform/jitterY.js +25 -0
  34. package/esm/transform/jitterY.js.map +1 -0
  35. package/lib/animation/scaleInY.js +102 -32
  36. package/lib/animation/scaleInY.js.map +1 -1
  37. package/lib/component/slider.js +32 -2
  38. package/lib/component/slider.js.map +1 -1
  39. package/lib/index.d.ts +2 -0
  40. package/lib/interaction/tooltip.js +11 -8
  41. package/lib/interaction/tooltip.js.map +1 -1
  42. package/lib/lib/core.d.ts +1 -0
  43. package/lib/lib/core.js +1 -0
  44. package/lib/lib/core.js.map +1 -1
  45. package/lib/lib/std.d.ts +1 -0
  46. package/lib/runtime/library.js +7 -4
  47. package/lib/runtime/library.js.map +1 -1
  48. package/lib/runtime/plot.js +16 -4
  49. package/lib/runtime/plot.js.map +1 -1
  50. package/lib/runtime/render.js +5 -2
  51. package/lib/runtime/render.js.map +1 -1
  52. package/lib/shape/area/smooth.d.ts +1 -3
  53. package/lib/shape/area/smooth.js +7 -3
  54. package/lib/shape/area/smooth.js.map +1 -1
  55. package/lib/shape/line/smooth.d.ts +1 -3
  56. package/lib/shape/line/smooth.js +2 -2
  57. package/lib/shape/line/smooth.js.map +1 -1
  58. package/lib/spec/composition.d.ts +1 -1
  59. package/lib/spec/mark.d.ts +1 -1
  60. package/lib/spec/transform.d.ts +7 -2
  61. package/lib/transform/index.d.ts +2 -0
  62. package/lib/transform/index.js +3 -1
  63. package/lib/transform/index.js.map +1 -1
  64. package/lib/transform/jitterY.d.ts +8 -0
  65. package/lib/transform/jitterY.js +29 -0
  66. package/lib/transform/jitterY.js.map +1 -0
  67. package/package.json +4 -2
  68. package/src/animation/scaleInY.ts +142 -43
  69. package/src/component/slider.ts +42 -2
  70. package/src/interaction/tooltip.ts +12 -11
  71. package/src/lib/core.ts +2 -0
  72. package/src/runtime/library.ts +10 -3
  73. package/src/runtime/plot.ts +20 -9
  74. package/src/runtime/render.ts +3 -2
  75. package/src/shape/area/smooth.ts +14 -8
  76. package/src/shape/line/smooth.ts +3 -5
  77. package/src/spec/composition.ts +1 -1
  78. package/src/spec/mark.ts +1 -1
  79. package/src/spec/transform.ts +8 -0
  80. package/src/transform/index.ts +2 -0
  81. package/src/transform/jitterY.ts +30 -0
  82. package/CHANGELOG.md +0 -484
@@ -1,5 +1,15 @@
1
- import { isTranspose } from '../utils/coordinate';
1
+ import { arc } from 'd3-shape';
2
+ import {
3
+ Path,
4
+ convertToPath,
5
+ CSS,
6
+ PropertySyntax,
7
+ DisplayObject,
8
+ } from '@antv/g';
9
+ import { G2Element } from 'utils/selection';
2
10
  import { AnimationComponent as AC } from '../runtime';
11
+ import { isTranspose, isPolar } from '../utils/coordinate';
12
+ import { getArcObject } from '../shape/utils';
3
13
  import { Animation } from './types';
4
14
 
5
15
  export type ScaleInYOptions = Animation;
@@ -14,49 +24,138 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
14
24
 
15
25
  const { coordinate } = context;
16
26
 
27
+ // the polar coordinate need
28
+ CSS.registerProperty({
29
+ name: 'scaleInYRadius',
30
+ inherits: false,
31
+ initialValue: '',
32
+ interpolable: true,
33
+ syntax: PropertySyntax.NUMBER,
34
+ });
35
+
17
36
  return (from, _, defaults) => {
18
37
  const [shape] = from;
19
- const {
20
- transform: prefix = '',
21
- fillOpacity = 1,
22
- strokeOpacity = 1,
23
- opacity = 1,
24
- } = shape.style;
25
- const [transformOrigin, transform]: [string, string] = isTranspose(
26
- coordinate,
27
- )
28
- ? [`left top`, `scale(${ZERO}, 1)`] // left-top corner
29
- : [`left bottom`, `scale(1, ${ZERO})`]; // left-bottom corner
30
-
31
- // Using a short fadeIn transition to hide element with scale(0.001)
32
- // which is still visible.
33
- const keyframes = [
34
- {
35
- transform: `${prefix} ${transform}`.trimStart(),
36
- transformOrigin,
37
- fillOpacity: 0,
38
- strokeOpacity: 0,
39
- opacity: 0,
40
- },
41
- {
42
- transform: `${prefix} ${transform}`.trimStart(),
43
- transformOrigin,
44
- fillOpacity,
45
- strokeOpacity,
46
- opacity,
47
- offset: 0.01,
48
- },
49
- {
50
- transform: `${prefix} scale(1, 1)`.trimStart(),
51
- transformOrigin,
52
- fillOpacity,
53
- strokeOpacity,
54
- opacity,
55
- },
56
- ];
57
-
58
- const animation = shape.animate(keyframes, { ...defaults, ...options });
59
-
60
- return animation;
38
+ const PolarScaleInY = (shape: DisplayObject) => {
39
+ const { __data__, style } = shape as G2Element;
40
+ const {
41
+ radius = 0,
42
+ inset = 0,
43
+ fillOpacity = 1,
44
+ strokeOpacity = 1,
45
+ opacity = 1,
46
+ } = style;
47
+ const { points, y, y1 } = __data__;
48
+ const arcObject = getArcObject(coordinate, points, [y, y1]);
49
+ const { innerRadius, outerRadius } = arcObject;
50
+ const path = arc()
51
+ .cornerRadius(radius as number)
52
+ .padAngle((inset * Math.PI) / 180);
53
+ const pathForConversion = new Path({});
54
+ const center = coordinate.getCenter();
55
+ const createArcPath = (arcParams: {
56
+ startAngle: number;
57
+ endAngle: number;
58
+ innerRadius: number;
59
+ outerRadius: number;
60
+ }) => {
61
+ pathForConversion.attr({
62
+ d: path(arcParams),
63
+ transform: `translate(${center[0]}, ${center[1]})`,
64
+ });
65
+ const convertedPathDefinition = convertToPath(pathForConversion);
66
+ pathForConversion.style.transform = '';
67
+ return convertedPathDefinition;
68
+ };
69
+
70
+ const keyframes = [
71
+ {
72
+ scaleInYRadius: innerRadius + ZERO,
73
+ fillOpacity: 0,
74
+ strokeOpacity: 0,
75
+ opacity: 0,
76
+ },
77
+ {
78
+ scaleInYRadius: innerRadius + ZERO,
79
+ fillOpacity,
80
+ strokeOpacity,
81
+ opacity,
82
+ offset: 0.01,
83
+ },
84
+ {
85
+ scaleInYRadius: outerRadius,
86
+ fillOpacity,
87
+ strokeOpacity,
88
+ opacity,
89
+ },
90
+ ];
91
+
92
+ const animation = shape.animate(keyframes, { ...defaults, ...options });
93
+ animation.onframe = function () {
94
+ shape.style.path = createArcPath({
95
+ ...arcObject,
96
+ outerRadius: Number(shape.style.scaleInYRadius),
97
+ });
98
+ };
99
+
100
+ animation.onfinish = function () {
101
+ shape.style.path = createArcPath({
102
+ ...arcObject,
103
+ outerRadius: outerRadius,
104
+ });
105
+ };
106
+
107
+ return animation;
108
+ };
109
+
110
+ const RectangularScaleInY = (shape: DisplayObject) => {
111
+ const { style } = shape as G2Element;
112
+ const {
113
+ transform: prefix = '',
114
+ fillOpacity = 1,
115
+ strokeOpacity = 1,
116
+ opacity = 1,
117
+ } = style;
118
+ const [transformOrigin, transform]: [string, string] = isTranspose(
119
+ coordinate,
120
+ )
121
+ ? [`left top`, `scale(${ZERO}, 1)`] // left-top corner
122
+ : [`left bottom`, `scale(1, ${ZERO})`]; // left-bottom corner
123
+
124
+ // Using a short fadeIn transition to hide element with scale(0.001)
125
+ // which is still visible.
126
+ const keyframes = [
127
+ {
128
+ transform: `${prefix} ${transform}`.trimStart(),
129
+ transformOrigin,
130
+ fillOpacity: 0,
131
+ strokeOpacity: 0,
132
+ opacity: 0,
133
+ },
134
+ {
135
+ transform: `${prefix} ${transform}`.trimStart(),
136
+ transformOrigin,
137
+ fillOpacity,
138
+ strokeOpacity,
139
+ opacity,
140
+ offset: 0.01,
141
+ },
142
+ {
143
+ transform: `${prefix} scale(1, 1)`.trimStart(),
144
+ transformOrigin,
145
+ fillOpacity,
146
+ strokeOpacity,
147
+ opacity,
148
+ },
149
+ ];
150
+
151
+ const animation = shape.animate(keyframes, { ...defaults, ...options });
152
+ return animation;
153
+ };
154
+
155
+ if (isPolar(coordinate)) {
156
+ return PolarScaleInY(shape);
157
+ } else {
158
+ return RectangularScaleInY(shape);
159
+ }
61
160
  };
62
161
  };
@@ -1,8 +1,12 @@
1
1
  import { Slider as SliderComponent } from '@antv/component';
2
2
  import { format } from 'd3-format';
3
3
  import { DisplayObject } from '@antv/g';
4
+ import { isArray } from '@antv/util';
4
5
  import { isTranspose } from '../utils/coordinate';
5
- import { GuideComponentComponent as GCC } from '../runtime';
6
+ import {
7
+ GuideComponentComponent as GCC,
8
+ GuideComponentContext,
9
+ } from '../runtime';
6
10
  import { invert } from '../utils/scale';
7
11
 
8
12
  export type SliderOptions = {
@@ -32,7 +36,13 @@ export const Slider: GCC<SliderOptions> = (options) => {
32
36
  ...rest
33
37
  } = options;
34
38
 
35
- return ({ scales: [scale], value, theme, coordinate }) => {
39
+ return (context) => {
40
+ const {
41
+ scales: [scale],
42
+ value,
43
+ theme,
44
+ coordinate,
45
+ } = context;
36
46
  const { bbox } = value;
37
47
 
38
48
  const { width, height } = bbox;
@@ -60,6 +70,7 @@ export const Slider: GCC<SliderOptions> = (options) => {
60
70
  const tick = invert(scale, v1, true);
61
71
  return f(tick);
62
72
  },
73
+ sparklineData: inferSparklineData(options, context),
63
74
  ...style,
64
75
  ...rest,
65
76
  }),
@@ -67,6 +78,35 @@ export const Slider: GCC<SliderOptions> = (options) => {
67
78
  };
68
79
  };
69
80
 
81
+ function markValue(markState, channels: string[]) {
82
+ const [value] = Array.from(markState.entries())
83
+ .filter(([mark]) => mark.type === 'line' || mark.type === 'area')
84
+ .map(([mark]) => {
85
+ const { encode, slider } = mark;
86
+ if (slider?.x && Object.keys(slider.x).length === 0) {
87
+ const channel = (name) => {
88
+ const channel = encode[name];
89
+ return [name, channel ? channel.value : undefined];
90
+ };
91
+ return Object.fromEntries(channels.map(channel));
92
+ }
93
+ });
94
+
95
+ if (!value?.series) return value?.y;
96
+ const result = value.series.reduce((acc, curr, index) => {
97
+ acc[curr] = acc[curr] || [];
98
+ acc[curr].push(value.y[index]);
99
+ return acc;
100
+ }, {});
101
+ return Object.values(result);
102
+ }
103
+
104
+ function inferSparklineData(options, context: GuideComponentContext) {
105
+ const { markState } = context;
106
+ if (isArray(options.sparklineData)) return options.sparklineData;
107
+ return markValue(markState, ['y', 'series']);
108
+ }
109
+
70
110
  Slider.props = {
71
111
  defaultPosition: 'bottom',
72
112
  defaultSize: 24,
@@ -22,12 +22,15 @@ import { dataOf } from './event';
22
22
 
23
23
  function getContainer(
24
24
  group: IElement,
25
- mount: string | HTMLElement,
25
+ mount?: string | HTMLElement,
26
26
  ): HTMLElement {
27
- if (mount)
27
+ if (mount) {
28
28
  return typeof mount === 'string' ? document.querySelector(mount) : mount;
29
- // @ts-ignore
30
- return group.getRootNode().defaultView.getConfig().container;
29
+ }
30
+ const canvas: any = group.ownerDocument.defaultView
31
+ .getContextService()
32
+ .getDomElement();
33
+ return canvas.parentElement as unknown as HTMLElement;
31
34
  }
32
35
 
33
36
  function getBounding(root): BBox {
@@ -110,12 +113,10 @@ function showTooltip({
110
113
  mount,
111
114
  bounding,
112
115
  }) {
113
- const canvasContainer = root.getRootNode().defaultView.getConfig().container;
114
116
  const container = getContainer(root, mount);
115
-
117
+ const canvasContainer = getContainer(root);
116
118
  // All the views share the same tooltip.
117
119
  const parent = single ? canvasContainer : root;
118
-
119
120
  const b = bounding || getBounding(root);
120
121
  const containerOffset = getContainerOffset(canvasContainer, container);
121
122
  const {
@@ -149,8 +150,8 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
149
150
  if (nativeEvent) {
150
151
  emitter.emit('tooltip:hide', { nativeEvent });
151
152
  }
152
- const canvasContainer = root.getRootNode().defaultView.getConfig().container;
153
- const parent = single ? canvasContainer : root;
153
+ const container = getContainer(root);
154
+ const parent = single ? container : root;
154
155
  const { tooltipElement } = parent;
155
156
  if (tooltipElement) {
156
157
  tooltipElement.hide();
@@ -158,8 +159,8 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
158
159
  }
159
160
 
160
161
  function destroyTooltip({ root, single }) {
161
- const canvasContainer = root.getRootNode().defaultView.getConfig().container;
162
- const parent = single ? canvasContainer : root;
162
+ const container = getContainer(root);
163
+ const parent = single ? container : root;
163
164
  if (!parent) return;
164
165
  const { tooltipElement } = parent;
165
166
  if (tooltipElement) {
package/src/lib/core.ts CHANGED
@@ -116,6 +116,7 @@ import {
116
116
  NormalizeY,
117
117
  Jitter,
118
118
  JitterX,
119
+ JitterY,
119
120
  SymmetryY,
120
121
  DiffY,
121
122
  Select,
@@ -180,6 +181,7 @@ export function corelib() {
180
181
  'transform.dodgeX': DodgeX,
181
182
  'transform.jitter': Jitter,
182
183
  'transform.jitterX': JitterX,
184
+ 'transform.jitterY': JitterY,
183
185
  'transform.symmetryY': SymmetryY,
184
186
  'transform.diffY': DiffY,
185
187
  'transform.stackEnter': StackEnter,
@@ -23,15 +23,22 @@ export function useLibrary<
23
23
  const key = `${namespace}.${type}`;
24
24
  return library[key] || error(`Unknown Component: ${key}`);
25
25
  };
26
+
26
27
  const use = (options: O, context?) => {
27
28
  const { type, ...rest } = options;
28
- return create(type)(rest, context);
29
+ if (!type) error(`Plot type is required!`);
30
+ const currentLibrary = create(type);
31
+ return currentLibrary?.(rest, context);
29
32
  };
33
+
30
34
  return [use, create];
31
35
  }
32
36
 
33
37
  export function documentOf(library: G2Context): IDocument {
34
38
  const { canvas, group } = library;
35
- if (group) return group.ownerDocument;
36
- return canvas.document;
39
+ return (
40
+ canvas?.document ||
41
+ group?.ownerDocument ||
42
+ error(`Cannot find library document`)
43
+ );
37
44
  }
@@ -372,23 +372,34 @@ function applyTranslate(selection: Selection) {
372
372
  );
373
373
  }
374
374
 
375
- function createUpdateView(
376
- selection: Selection,
377
- options: G2ViewTree,
378
- library: G2Library,
379
- context: G2Context,
380
- ): G2ViewInstance['update'] {
375
+ function definedInteraction(library: G2Library) {
381
376
  const [, createInteraction] = useLibrary<
382
377
  G2InteractionOptions,
383
378
  InteractionComponent,
384
379
  Interaction
385
380
  >('interaction', library);
381
+ return (d) => {
382
+ const [name, options] = d;
383
+ try {
384
+ return [name, createInteraction(name)] as const;
385
+ } catch {
386
+ return [name, options.type] as const;
387
+ }
388
+ };
389
+ }
386
390
 
387
- // Filter interaction need to reapply when update.
391
+ function createUpdateView(
392
+ selection: Selection,
393
+ options: G2ViewTree,
394
+ library: G2Library,
395
+ context: G2Context,
396
+ ): G2ViewInstance['update'] {
397
+ const createDefinedInteraction = definedInteraction(library);
398
+ const filter = (d) => d[1] && d[1].props && d[1].props.reapplyWhenUpdate;
388
399
  const interactions = inferInteraction(options);
389
400
  const updates = interactions
390
- .map((d) => [d[0], createInteraction(d[0])] as const)
391
- .filter((d) => d[1].props && d[1].props.reapplyWhenUpdate)
401
+ .map(createDefinedInteraction)
402
+ .filter(filter)
392
403
  .map((d) => d[0]);
393
404
 
394
405
  return async (newOptions, source) => {
@@ -140,14 +140,15 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
140
140
  const selection = select(group);
141
141
  context.group = group;
142
142
  context.emitter = emitter;
143
+ context.canvas =
144
+ context.canvas || (group?.ownerDocument?.defaultView as GCanvas);
143
145
 
144
146
  emitter.emit(ChartEvent.BEFORE_RENDER);
145
147
  // Plot the chart and mutate context.
146
148
  // Make sure that plot chart after container is ready for every time.
147
149
  plot<T>({ ...keyed, width, height }, selection, library, context)
148
150
  .then(() => {
149
- const canvas = group.ownerDocument.defaultView;
150
- canvas.requestAnimationFrame(() => {
151
+ context.canvas?.requestAnimationFrame(() => {
151
152
  emitter.emit(ChartEvent.AFTER_RENDER);
152
153
  resolve?.();
153
154
  });
@@ -1,18 +1,24 @@
1
- import { curveCatmullRomClosed, curveCatmullRom } from 'd3-shape';
2
- import { isPolar } from '../../utils/coordinate';
1
+ import {
2
+ curveCatmullRomClosed,
3
+ curveMonotoneX,
4
+ curveMonotoneY,
5
+ } from 'd3-shape';
6
+ import { isPolar, isTranspose } from '../../utils/coordinate';
3
7
  import { ShapeComponent as SC } from '../../runtime';
4
8
  import { Curve } from './curve';
5
9
 
6
- export type SmoothOptions = {
7
- alpha?: number;
8
- };
10
+ export type SmoothOptions = Record<string, any>;
9
11
 
10
12
  export const Smooth: SC<SmoothOptions> = (options, context) => {
11
- const { alpha = 0.5, ...rest } = options;
13
+ const { ...rest } = options;
12
14
  const { coordinate } = context;
13
15
  return (...params) => {
14
- const curve = isPolar(coordinate) ? curveCatmullRomClosed : curveCatmullRom;
15
- return Curve({ curve: curve.alpha(alpha), ...rest }, context)(...params);
16
+ const curve = isPolar(coordinate)
17
+ ? curveCatmullRomClosed
18
+ : isTranspose(coordinate)
19
+ ? curveMonotoneY
20
+ : curveMonotoneX;
21
+ return Curve({ curve, ...rest }, context)(...params);
16
22
  };
17
23
  };
18
24
 
@@ -7,12 +7,10 @@ import { isPolar, isTranspose } from '../../utils/coordinate';
7
7
  import { ShapeComponent as SC } from '../../runtime';
8
8
  import { Curve } from './curve';
9
9
 
10
- export type SmoothOptions = {
11
- alpha?: number;
12
- };
10
+ export type SmoothOptions = Record<string, any>;
13
11
 
14
12
  export const Smooth: SC<SmoothOptions> = (options, context) => {
15
- const { alpha = 0.5, ...rest } = options;
13
+ const { ...rest } = options;
16
14
  const { coordinate } = context;
17
15
  return (...params) => {
18
16
  const curve = isPolar(coordinate)
@@ -20,7 +18,7 @@ export const Smooth: SC<SmoothOptions> = (options, context) => {
20
18
  : isTranspose(coordinate)
21
19
  ? curveMonotoneY
22
20
  : curveMonotoneX;
23
- return Curve({ curve: curve, ...rest }, context)(...params);
21
+ return Curve({ curve, ...rest }, context)(...params);
24
22
  };
25
23
  };
26
24
 
@@ -65,7 +65,7 @@ export type ViewComposition = {
65
65
  insetBottom?: number;
66
66
  insetRight?: number;
67
67
  coordinate?: Coordinate;
68
- interaction?: Literal2Object<Interaction>;
68
+ interaction?: Literal2Object<Interaction> & Record<string, any>;
69
69
  transform?: Transform[];
70
70
  theme?: Theme;
71
71
  children?: (Mark | AxisComponent | LegendComponent)[];
package/src/spec/mark.ts CHANGED
@@ -188,7 +188,7 @@ export type BaseMark<T extends MarkTypes, C extends string = ChannelTypes> = {
188
188
  Partial<Record<PositionChannelTypes, Closeable<ScrollbarComponent>>>
189
189
  >;
190
190
  title?: string | TitleComponent;
191
- interaction?: Literal2Object<Interaction>;
191
+ interaction?: Literal2Object<Interaction> & Record<string, any>;
192
192
  theme?: Theme;
193
193
  };
194
194
 
@@ -8,6 +8,7 @@ export type Transform =
8
8
  | StackEnterTransform
9
9
  | JitterTransform
10
10
  | JitterXTransform
11
+ | JitterYTransform
11
12
  | SymmetryYTransform
12
13
  | DiffYTransform
13
14
  | SelectTransform
@@ -34,6 +35,7 @@ export type TransformTypes =
34
35
  | 'stackEnter'
35
36
  | 'jitter'
36
37
  | 'jitterX'
38
+ | 'jitterY'
37
39
  | 'symmetryY'
38
40
  | 'diffY'
39
41
  | 'select'
@@ -109,6 +111,12 @@ export type JitterXTransform = {
109
111
  random?: () => number;
110
112
  };
111
113
 
114
+ export type JitterYTransform = {
115
+ type?: 'jitterY';
116
+ padding?: number;
117
+ random?: () => number;
118
+ };
119
+
112
120
  export type StackEnterTransform = {
113
121
  type?: 'stackEnter';
114
122
  groupBy?: string[] | string;
@@ -23,6 +23,7 @@ export { StackEnter } from './stackEnter';
23
23
  export { NormalizeY } from './normalizeY';
24
24
  export { Jitter } from './jitter';
25
25
  export { JitterX } from './jitterX';
26
+ export { JitterY } from './jitterY';
26
27
  export { SymmetryY } from './symmetryY';
27
28
  export { DiffY } from './diffY';
28
29
  export { Select } from './select';
@@ -66,6 +67,7 @@ export type { StackEnterOptions } from './stackEnter';
66
67
  export type { NormalizeYOptions } from './normalizeY';
67
68
  export type { JitterOptions } from './jitter';
68
69
  export type { JitterXOptions } from './jitterX';
70
+ export type { JitterYOptions } from './jitterY';
69
71
  export type { SymmetryYOptions } from './symmetryY';
70
72
  export type { DiffYOptions } from './diffY';
71
73
  export type { SelectOptions } from './select';
@@ -0,0 +1,30 @@
1
+ import { deepMix } from '@antv/util';
2
+ import { TransformComponent as TC } from '../runtime';
3
+ import { JitterYTransform } from '../spec';
4
+ import { column, columnOf } from './utils/helper';
5
+ import { rangeOf, interpolate } from './jitter';
6
+
7
+ export type JitterYOptions = Omit<JitterYTransform, 'type'>;
8
+
9
+ /**
10
+ * The JitterY transform produce dy channels for marks (especially for point)
11
+ * with ordinal x and y dimension, say to make them jitter in their own space.
12
+ */
13
+ export const JitterY: TC<JitterYOptions> = (options = {}) => {
14
+ const { padding = 0, random = Math.random } = options;
15
+ return (I, mark) => {
16
+ const { encode, scale } = mark;
17
+ const { y: scaleY } = scale;
18
+ const [Y] = columnOf(encode, 'y');
19
+ const rangeY = rangeOf(Y, scaleY, padding);
20
+ const DY = I.map(() => interpolate(random(), ...rangeY));
21
+ return [
22
+ I,
23
+ deepMix({ scale: { y: { padding: 0.5 } } }, mark, {
24
+ encode: { dy: column(DY) },
25
+ }),
26
+ ];
27
+ };
28
+ };
29
+
30
+ JitterY.props = {};