@antv/g2 5.1.10 → 5.1.12
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.
- package/dist/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/animation/scaleInY.js +103 -33
- package/esm/animation/scaleInY.js.map +1 -1
- package/esm/component/slider.js +32 -2
- package/esm/component/slider.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/interaction/tooltip.js +32 -29
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/lib/core.d.ts +1 -0
- package/esm/lib/core.js +2 -1
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/mark/rangeX.js +2 -1
- package/esm/mark/rangeX.js.map +1 -1
- package/esm/mark/rangeY.js +2 -1
- package/esm/mark/rangeY.js.map +1 -1
- package/esm/runtime/library.js +7 -4
- package/esm/runtime/library.js.map +1 -1
- package/esm/runtime/plot.js +16 -4
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +5 -2
- package/esm/runtime/render.js.map +1 -1
- package/esm/shape/area/smooth.d.ts +1 -3
- package/esm/shape/area/smooth.js +9 -5
- package/esm/shape/area/smooth.js.map +1 -1
- package/esm/shape/line/smooth.d.ts +1 -3
- package/esm/shape/line/smooth.js +2 -2
- package/esm/shape/line/smooth.js.map +1 -1
- package/esm/spec/composition.d.ts +1 -1
- package/esm/spec/interaction.d.ts +1 -0
- package/esm/spec/mark.d.ts +1 -1
- package/esm/spec/transform.d.ts +7 -2
- package/esm/transform/index.d.ts +4 -0
- package/esm/transform/index.js +3 -0
- package/esm/transform/index.js.map +1 -1
- package/esm/transform/jitterY.d.ts +8 -0
- package/esm/transform/jitterY.js +25 -0
- package/esm/transform/jitterY.js.map +1 -0
- package/esm/transform/maybeDefaultX.d.ts +7 -0
- package/esm/transform/maybeDefaultX.js +29 -0
- package/esm/transform/maybeDefaultX.js.map +1 -0
- package/esm/transform/maybeDefaultY.d.ts +7 -0
- package/esm/transform/maybeDefaultY.js +29 -0
- package/esm/transform/maybeDefaultY.js.map +1 -0
- package/lib/animation/scaleInY.js +102 -32
- package/lib/animation/scaleInY.js.map +1 -1
- package/lib/component/slider.js +32 -2
- package/lib/component/slider.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/interaction/tooltip.js +32 -29
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/lib/core.d.ts +1 -0
- package/lib/lib/core.js +1 -0
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/mark/rangeX.js +2 -1
- package/lib/mark/rangeX.js.map +1 -1
- package/lib/mark/rangeY.js +2 -1
- package/lib/mark/rangeY.js.map +1 -1
- package/lib/runtime/library.js +7 -4
- package/lib/runtime/library.js.map +1 -1
- package/lib/runtime/plot.js +16 -4
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +5 -2
- package/lib/runtime/render.js.map +1 -1
- package/lib/shape/area/smooth.d.ts +1 -3
- package/lib/shape/area/smooth.js +7 -3
- package/lib/shape/area/smooth.js.map +1 -1
- package/lib/shape/line/smooth.d.ts +1 -3
- package/lib/shape/line/smooth.js +2 -2
- package/lib/shape/line/smooth.js.map +1 -1
- package/lib/spec/composition.d.ts +1 -1
- package/lib/spec/interaction.d.ts +1 -0
- package/lib/spec/mark.d.ts +1 -1
- package/lib/spec/transform.d.ts +7 -2
- package/lib/transform/index.d.ts +4 -0
- package/lib/transform/index.js +7 -1
- package/lib/transform/index.js.map +1 -1
- package/lib/transform/jitterY.d.ts +8 -0
- package/lib/transform/jitterY.js +29 -0
- package/lib/transform/jitterY.js.map +1 -0
- package/lib/transform/maybeDefaultX.d.ts +7 -0
- package/lib/transform/maybeDefaultX.js +33 -0
- package/lib/transform/maybeDefaultX.js.map +1 -0
- package/lib/transform/maybeDefaultY.d.ts +7 -0
- package/lib/transform/maybeDefaultY.js +33 -0
- package/lib/transform/maybeDefaultY.js.map +1 -0
- package/package.json +8 -6
- package/src/animation/scaleInY.ts +142 -43
- package/src/component/slider.ts +42 -2
- package/src/interaction/tooltip.ts +41 -31
- package/src/lib/core.ts +2 -0
- package/src/mark/rangeX.ts +2 -1
- package/src/mark/rangeY.ts +2 -1
- package/src/runtime/library.ts +10 -3
- package/src/runtime/plot.ts +20 -9
- package/src/runtime/render.ts +3 -2
- package/src/shape/area/smooth.ts +14 -8
- package/src/shape/line/smooth.ts +3 -5
- package/src/spec/composition.ts +1 -1
- package/src/spec/interaction.ts +1 -1
- package/src/spec/mark.ts +1 -1
- package/src/spec/transform.ts +8 -0
- package/src/transform/index.ts +4 -0
- package/src/transform/jitterY.ts +30 -0
- package/src/transform/maybeDefaultX.ts +36 -0
- package/src/transform/maybeDefaultY.ts +36 -0
- package/CHANGELOG.md +0 -484
|
@@ -22,12 +22,15 @@ import { dataOf } from './event';
|
|
|
22
22
|
|
|
23
23
|
function getContainer(
|
|
24
24
|
group: IElement,
|
|
25
|
-
mount
|
|
25
|
+
mount?: string | HTMLElement,
|
|
26
26
|
): HTMLElement {
|
|
27
|
-
if (mount)
|
|
27
|
+
if (mount) {
|
|
28
28
|
return typeof mount === 'string' ? document.querySelector(mount) : mount;
|
|
29
|
-
|
|
30
|
-
|
|
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 {
|
|
@@ -145,21 +146,28 @@ function showTooltip({
|
|
|
145
146
|
parent.tooltipElement = tooltipElement;
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
function hideTooltip({
|
|
149
|
+
function hideTooltip({
|
|
150
|
+
root,
|
|
151
|
+
single,
|
|
152
|
+
emitter,
|
|
153
|
+
nativeEvent = true,
|
|
154
|
+
event = null,
|
|
155
|
+
}) {
|
|
149
156
|
if (nativeEvent) {
|
|
150
157
|
emitter.emit('tooltip:hide', { nativeEvent });
|
|
151
158
|
}
|
|
152
|
-
const
|
|
153
|
-
const parent = single ?
|
|
159
|
+
const container = getContainer(root);
|
|
160
|
+
const parent = single ? container : root;
|
|
154
161
|
const { tooltipElement } = parent;
|
|
155
162
|
if (tooltipElement) {
|
|
156
|
-
|
|
163
|
+
// Must be clientX, clientY.
|
|
164
|
+
tooltipElement.hide(event?.clientX, event?.clientY);
|
|
157
165
|
}
|
|
158
166
|
}
|
|
159
167
|
|
|
160
168
|
function destroyTooltip({ root, single }) {
|
|
161
|
-
const
|
|
162
|
-
const parent = single ?
|
|
169
|
+
const container = getContainer(root);
|
|
170
|
+
const parent = single ? container : root;
|
|
163
171
|
if (!parent) return;
|
|
164
172
|
const { tooltipElement } = parent;
|
|
165
173
|
if (tooltipElement) {
|
|
@@ -522,9 +530,13 @@ export function seriesTooltip(
|
|
|
522
530
|
const finalX = abstractX(focus);
|
|
523
531
|
const DX = X.filter(defined);
|
|
524
532
|
const [minX, maxX] = sort([DX[0], DX[DX.length - 1]]);
|
|
533
|
+
// If only has one element(minX == maxX), show tooltip when hover whole chart
|
|
534
|
+
const isOnlyOneElement = minX === maxX;
|
|
535
|
+
|
|
525
536
|
// If closest is true, always find at least one element.
|
|
526
537
|
// Otherwise, skip element out of plot area.
|
|
527
|
-
if (!closest && (finalX < minX || finalX > maxX)
|
|
538
|
+
if (!closest && (finalX < minX || finalX > maxX) && !isOnlyOneElement)
|
|
539
|
+
return null;
|
|
528
540
|
const search = bisector((i) => X[+i]).center;
|
|
529
541
|
const i = search(I, finalX);
|
|
530
542
|
return I[i];
|
|
@@ -621,7 +633,7 @@ export function seriesTooltip(
|
|
|
621
633
|
|
|
622
634
|
// Hide tooltip with no selected tooltip.
|
|
623
635
|
if (selectedElements.length === 0 || isEmptyTooltipData(tooltipData)) {
|
|
624
|
-
hide();
|
|
636
|
+
hide(event);
|
|
625
637
|
return;
|
|
626
638
|
}
|
|
627
639
|
|
|
@@ -679,8 +691,8 @@ export function seriesTooltip(
|
|
|
679
691
|
{ leading, trailing },
|
|
680
692
|
) as (...args: any[]) => void;
|
|
681
693
|
|
|
682
|
-
const hide = () => {
|
|
683
|
-
hideTooltip({ root, single, emitter });
|
|
694
|
+
const hide = (event: MouseEvent) => {
|
|
695
|
+
hideTooltip({ root, single, emitter, event });
|
|
684
696
|
if (crosshairs) hideRuleY(root);
|
|
685
697
|
if (marker) hideMarker(root);
|
|
686
698
|
};
|
|
@@ -789,11 +801,11 @@ export function tooltip(
|
|
|
789
801
|
const elementSet = new Set(elements);
|
|
790
802
|
const keyGroup = group(elements, groupKey);
|
|
791
803
|
|
|
792
|
-
const
|
|
804
|
+
const pointermove = throttle(
|
|
793
805
|
(event) => {
|
|
794
806
|
const { target: element } = event;
|
|
795
807
|
if (!elementSet.has(element)) {
|
|
796
|
-
hideTooltip({ root, single, emitter });
|
|
808
|
+
hideTooltip({ root, single, emitter, event });
|
|
797
809
|
return;
|
|
798
810
|
}
|
|
799
811
|
const k = groupKey(element);
|
|
@@ -812,7 +824,7 @@ export function tooltip(
|
|
|
812
824
|
}
|
|
813
825
|
|
|
814
826
|
if (isEmptyTooltipData(data)) {
|
|
815
|
-
hideTooltip({ root, single, emitter });
|
|
827
|
+
hideTooltip({ root, single, emitter, event });
|
|
816
828
|
return;
|
|
817
829
|
}
|
|
818
830
|
|
|
@@ -846,25 +858,23 @@ export function tooltip(
|
|
|
846
858
|
{ leading, trailing },
|
|
847
859
|
) as (...args: any[]) => void;
|
|
848
860
|
|
|
849
|
-
const
|
|
850
|
-
|
|
851
|
-
if (!elementSet.has(element)) return;
|
|
852
|
-
hideTooltip({ root, single, emitter });
|
|
861
|
+
const pointerleave = (event) => {
|
|
862
|
+
hideTooltip({ root, single, emitter, event });
|
|
853
863
|
};
|
|
854
864
|
|
|
855
865
|
const addEventListeners = () => {
|
|
856
866
|
if (!disableNative) {
|
|
857
|
-
root.addEventListener('
|
|
858
|
-
root.
|
|
859
|
-
|
|
867
|
+
root.addEventListener('pointermove', pointermove);
|
|
868
|
+
// Only emit pointerleave event when the pointer is not in the root area.
|
|
869
|
+
// !!!DO NOT USE pointerout event, it will emit when the pointer is in the child area.
|
|
870
|
+
root.addEventListener('pointerleave', pointerleave);
|
|
860
871
|
}
|
|
861
872
|
};
|
|
862
873
|
|
|
863
874
|
const removeEventListeners = () => {
|
|
864
875
|
if (!disableNative) {
|
|
865
|
-
root.removeEventListener('
|
|
866
|
-
root.removeEventListener('
|
|
867
|
-
root.removeEventListener('pointerout', pointerout);
|
|
876
|
+
root.removeEventListener('pointermove', pointermove);
|
|
877
|
+
root.removeEventListener('pointerleave', pointerleave);
|
|
868
878
|
}
|
|
869
879
|
};
|
|
870
880
|
|
|
@@ -874,7 +884,7 @@ export function tooltip(
|
|
|
874
884
|
if (!element) return;
|
|
875
885
|
const bbox = element.getBBox();
|
|
876
886
|
const { x, y, width, height } = bbox;
|
|
877
|
-
|
|
887
|
+
pointermove({
|
|
878
888
|
target: element,
|
|
879
889
|
offsetX: x + width / 2,
|
|
880
890
|
offsetY: y + height / 2,
|
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,
|
package/src/mark/rangeX.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MarkComponent as MC } from '../runtime';
|
|
2
2
|
import { RangeXMark } from '../spec';
|
|
3
3
|
import { RangeShape } from '../shape';
|
|
4
|
+
import { MaybeDefaultX } from '../transform';
|
|
4
5
|
import {
|
|
5
6
|
baseAnnotationChannels,
|
|
6
7
|
basePostInference,
|
|
@@ -27,6 +28,6 @@ RangeX.props = {
|
|
|
27
28
|
...baseAnnotationChannels({ shapes: Object.keys(shape) }),
|
|
28
29
|
{ name: 'x', required: true },
|
|
29
30
|
],
|
|
30
|
-
preInference: [...basePreInference()],
|
|
31
|
+
preInference: [...basePreInference(), { type: MaybeDefaultX }],
|
|
31
32
|
postInference: [...basePostInference()],
|
|
32
33
|
};
|
package/src/mark/rangeY.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MarkComponent as MC } from '../runtime';
|
|
2
2
|
import { RangeYMark } from '../spec';
|
|
3
3
|
import { RangeShape } from '../shape';
|
|
4
|
+
import { MaybeDefaultY } from '../transform';
|
|
4
5
|
import {
|
|
5
6
|
baseAnnotationChannels,
|
|
6
7
|
basePostInference,
|
|
@@ -27,6 +28,6 @@ RangeY.props = {
|
|
|
27
28
|
...baseAnnotationChannels({ shapes: Object.keys(shape) }),
|
|
28
29
|
{ name: 'y', required: true },
|
|
29
30
|
],
|
|
30
|
-
preInference: [...basePreInference()],
|
|
31
|
+
preInference: [...basePreInference(), { type: MaybeDefaultY }],
|
|
31
32
|
postInference: [...basePostInference()],
|
|
32
33
|
};
|
package/src/runtime/library.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
39
|
+
return (
|
|
40
|
+
canvas?.document ||
|
|
41
|
+
group?.ownerDocument ||
|
|
42
|
+
error(`Cannot find library document`)
|
|
43
|
+
);
|
|
37
44
|
}
|
package/src/runtime/plot.ts
CHANGED
|
@@ -372,23 +372,34 @@ function applyTranslate(selection: Selection) {
|
|
|
372
372
|
);
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
function
|
|
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
|
-
|
|
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(
|
|
391
|
-
.filter(
|
|
401
|
+
.map(createDefinedInteraction)
|
|
402
|
+
.filter(filter)
|
|
392
403
|
.map((d) => d[0]);
|
|
393
404
|
|
|
394
405
|
return async (newOptions, source) => {
|
package/src/runtime/render.ts
CHANGED
|
@@ -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
|
-
|
|
150
|
-
canvas.requestAnimationFrame(() => {
|
|
151
|
+
context.canvas?.requestAnimationFrame(() => {
|
|
151
152
|
emitter.emit(ChartEvent.AFTER_RENDER);
|
|
152
153
|
resolve?.();
|
|
153
154
|
});
|
package/src/shape/area/smooth.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 {
|
|
13
|
+
const { ...rest } = options;
|
|
12
14
|
const { coordinate } = context;
|
|
13
15
|
return (...params) => {
|
|
14
|
-
const curve = isPolar(coordinate)
|
|
15
|
-
|
|
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
|
|
package/src/shape/line/smooth.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
21
|
+
return Curve({ curve, ...rest }, context)(...params);
|
|
24
22
|
};
|
|
25
23
|
};
|
|
26
24
|
|
package/src/spec/composition.ts
CHANGED
|
@@ -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/interaction.ts
CHANGED
|
@@ -181,7 +181,7 @@ export type TooltipInteraction = {
|
|
|
181
181
|
bounding?: BBox;
|
|
182
182
|
mount?: string | HTMLElement;
|
|
183
183
|
css?: Record<string, any>; // @todo
|
|
184
|
-
|
|
184
|
+
enterable?: boolean;
|
|
185
185
|
sort?: (d: TooltipItemValue) => any;
|
|
186
186
|
filter?: (d: TooltipItemValue) => any;
|
|
187
187
|
render?: (
|
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
|
|
package/src/spec/transform.ts
CHANGED
|
@@ -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;
|
package/src/transform/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ export { MaybeTupleY } from './maybeTupleY';
|
|
|
11
11
|
export { MaybeTupleX } from './maybeTupleX';
|
|
12
12
|
export { MaybeIdentityY } from './maybeIdentityY';
|
|
13
13
|
export { MaybeIdentityX } from './maybeIdentityX';
|
|
14
|
+
export { MaybeDefaultX } from './maybeDefaultX';
|
|
15
|
+
export { MaybeDefaultY } from './maybeDefaultY';
|
|
14
16
|
export { MaybeTooltip } from './maybeTooltip';
|
|
15
17
|
export { MaybeZeroPadding } from './maybeZeroPadding';
|
|
16
18
|
export { MaybeVisualPosition } from './maybeVisualPosition';
|
|
@@ -23,6 +25,7 @@ export { StackEnter } from './stackEnter';
|
|
|
23
25
|
export { NormalizeY } from './normalizeY';
|
|
24
26
|
export { Jitter } from './jitter';
|
|
25
27
|
export { JitterX } from './jitterX';
|
|
28
|
+
export { JitterY } from './jitterY';
|
|
26
29
|
export { SymmetryY } from './symmetryY';
|
|
27
30
|
export { DiffY } from './diffY';
|
|
28
31
|
export { Select } from './select';
|
|
@@ -66,6 +69,7 @@ export type { StackEnterOptions } from './stackEnter';
|
|
|
66
69
|
export type { NormalizeYOptions } from './normalizeY';
|
|
67
70
|
export type { JitterOptions } from './jitter';
|
|
68
71
|
export type { JitterXOptions } from './jitterX';
|
|
72
|
+
export type { JitterYOptions } from './jitterY';
|
|
69
73
|
export type { SymmetryYOptions } from './symmetryY';
|
|
70
74
|
export type { DiffYOptions } from './diffY';
|
|
71
75
|
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 = {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { deepMix } from '@antv/util';
|
|
2
|
+
import { TransformComponent as TC } from '../runtime';
|
|
3
|
+
import { column, isObject } from './utils/helper';
|
|
4
|
+
|
|
5
|
+
export type MaybeDefaultXOptions = Record<string, never>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add a default encode for rangeX
|
|
9
|
+
* when data is just an array
|
|
10
|
+
*/
|
|
11
|
+
export const MaybeDefaultX: TC<MaybeDefaultXOptions> = () => {
|
|
12
|
+
return (I, mark) => {
|
|
13
|
+
const { data } = mark;
|
|
14
|
+
if (
|
|
15
|
+
Array.isArray(data) &&
|
|
16
|
+
(data.every(Array.isArray) || !data.some(isObject))
|
|
17
|
+
) {
|
|
18
|
+
const extractX = (data, index: number) =>
|
|
19
|
+
Array.isArray(data[0])
|
|
20
|
+
? data.map((item) => item[index])
|
|
21
|
+
: [data[index]];
|
|
22
|
+
return [
|
|
23
|
+
I,
|
|
24
|
+
deepMix({}, mark, {
|
|
25
|
+
encode: {
|
|
26
|
+
x: column(extractX(data, 0)),
|
|
27
|
+
x1: column(extractX(data, 1)),
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
return [I, mark];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
MaybeDefaultX.props = {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { deepMix } from '@antv/util';
|
|
2
|
+
import { Primitive, TransformComponent as TC } from '../runtime';
|
|
3
|
+
import { column, isObject } from './utils/helper';
|
|
4
|
+
|
|
5
|
+
export type MaybeDefaultYOptions = Record<string, never>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add a default encode for rangeY
|
|
9
|
+
* when data is just an array
|
|
10
|
+
*/
|
|
11
|
+
export const MaybeDefaultY: TC<MaybeDefaultYOptions> = () => {
|
|
12
|
+
return (I, mark) => {
|
|
13
|
+
const { data } = mark;
|
|
14
|
+
if (
|
|
15
|
+
Array.isArray(data) &&
|
|
16
|
+
(data.every(Array.isArray) || !data.some(isObject))
|
|
17
|
+
) {
|
|
18
|
+
const extractY = (data, index: number) =>
|
|
19
|
+
Array.isArray(data[0])
|
|
20
|
+
? data.map((item) => item[index])
|
|
21
|
+
: [data[index]];
|
|
22
|
+
return [
|
|
23
|
+
I,
|
|
24
|
+
deepMix({}, mark, {
|
|
25
|
+
encode: {
|
|
26
|
+
y: column(extractY(data, 0)),
|
|
27
|
+
y1: column(extractY(data, 1)),
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
return [I, mark];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
MaybeDefaultY.props = {};
|