@antv/g2 5.0.0-beta.7 → 5.0.0-beta.8
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 +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/chart.d.ts +6 -2
- package/esm/api/chart.js +31 -14
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +18 -1
- package/esm/api/composition/base.js +44 -1
- package/esm/api/composition/base.js.map +1 -1
- package/esm/api/mark/base.d.ts +22 -0
- package/esm/api/mark/base.js +54 -0
- package/esm/api/mark/base.js.map +1 -0
- package/esm/api/mark/mark.d.ts +1 -7
- package/esm/api/mark/mark.js +1 -13
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/props.js +0 -20
- package/esm/api/props.js.map +1 -1
- package/esm/component/axis.js +4 -0
- package/esm/component/axis.js.map +1 -1
- package/esm/component/legendContinuous.d.ts +1 -0
- package/esm/component/legendContinuous.js +14 -16
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/interaction/builtin/elementHighlight.d.ts +2 -0
- package/esm/interaction/builtin/elementHighlightByColor.d.ts +2 -0
- package/esm/interaction/builtin/elementHighlightByX.d.ts +2 -0
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/native/elementHighlight.d.ts +7 -2
- package/esm/interaction/native/elementHighlight.js +72 -19
- package/esm/interaction/native/elementHighlight.js.map +1 -1
- package/esm/interaction/native/elementHighlightByColor.d.ts +4 -1
- package/esm/interaction/native/elementHighlightByColor.js +19 -3
- package/esm/interaction/native/elementHighlightByColor.js.map +1 -1
- package/esm/interaction/native/elementHighlightByX.d.ts +3 -3
- package/esm/interaction/native/elementHighlightByX.js +19 -3
- package/esm/interaction/native/elementHighlightByX.js.map +1 -1
- package/esm/interaction/native/elementSelect.d.ts +1 -1
- package/esm/interaction/native/elementSelect.js +42 -21
- package/esm/interaction/native/elementSelect.js.map +1 -1
- package/esm/interaction/native/elementSelectByColor.js +3 -2
- package/esm/interaction/native/elementSelectByColor.js.map +1 -1
- package/esm/interaction/native/elementSelectByX.js +3 -2
- package/esm/interaction/native/elementSelectByX.js.map +1 -1
- package/esm/interaction/native/legendFilter.d.ts +4 -0
- package/esm/interaction/native/legendFilter.js +7 -4
- package/esm/interaction/native/legendFilter.js.map +1 -1
- package/esm/interaction/native/legendHighlight.d.ts +4 -0
- package/esm/interaction/native/legendHighlight.js +94 -0
- package/esm/interaction/native/legendHighlight.js.map +1 -0
- package/esm/interaction/native/utils.d.ts +13 -2
- package/esm/interaction/native/utils.js +151 -26
- package/esm/interaction/native/utils.js.map +1 -1
- package/esm/label-transform/overlapDodgeY.js +0 -8
- package/esm/label-transform/overlapDodgeY.js.map +1 -1
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/runtime/plot.js +4 -4
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +18 -13
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/types/options.d.ts +4 -2
- package/esm/shape/area/hv.d.ts +3 -0
- package/esm/shape/area/hv.js +9 -0
- package/esm/shape/area/hv.js.map +1 -0
- package/esm/shape/area/hvh.d.ts +3 -0
- package/esm/shape/area/{step.js → hvh.js} +3 -3
- package/esm/shape/area/hvh.js.map +1 -0
- package/esm/shape/area/vh.d.ts +3 -0
- package/esm/shape/area/vh.js +9 -0
- package/esm/shape/area/vh.js.map +1 -0
- package/esm/shape/index.d.ts +6 -2
- package/esm/shape/index.js +3 -1
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval/color.d.ts +1 -0
- package/esm/shape/interval/color.js +65 -53
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/spec/composition.d.ts +0 -3
- package/esm/spec/interaction.d.ts +24 -11
- package/esm/spec/transform.d.ts +13 -3
- package/esm/stdlib/index.js +3 -8
- package/esm/stdlib/index.js.map +1 -1
- package/esm/transform/sample.js +42 -26
- package/esm/transform/sample.js.map +1 -1
- package/esm/transform/utils/lttb.d.ts +5 -0
- package/esm/transform/utils/lttb.js +56 -0
- package/esm/transform/utils/lttb.js.map +1 -0
- package/esm/utils/event.d.ts +0 -2
- package/esm/utils/event.js +0 -18
- package/esm/utils/event.js.map +1 -1
- package/esm/utils/scale.d.ts +1 -0
- package/esm/utils/scale.js +3 -3
- package/esm/utils/scale.js.map +1 -1
- package/esm/utils/vector.d.ts +1 -1
- package/esm/utils/vector.js +1 -1
- package/lib/api/chart.d.ts +6 -2
- package/lib/api/chart.js +33 -13
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +18 -1
- package/lib/api/composition/base.js +44 -1
- package/lib/api/composition/base.js.map +1 -1
- package/lib/api/mark/base.d.ts +22 -0
- package/lib/api/mark/base.js +58 -0
- package/lib/api/mark/base.js.map +1 -0
- package/lib/api/mark/mark.d.ts +1 -7
- package/lib/api/mark/mark.js +28 -41
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/props.js +0 -20
- package/lib/api/props.js.map +1 -1
- package/lib/component/axis.js +4 -0
- package/lib/component/axis.js.map +1 -1
- package/lib/component/legendContinuous.d.ts +1 -0
- package/lib/component/legendContinuous.js +14 -16
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/interaction/builtin/elementHighlight.d.ts +2 -0
- package/lib/interaction/builtin/elementHighlightByColor.d.ts +2 -0
- package/lib/interaction/builtin/elementHighlightByX.d.ts +2 -0
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/native/elementHighlight.d.ts +7 -2
- package/lib/interaction/native/elementHighlight.js +71 -18
- package/lib/interaction/native/elementHighlight.js.map +1 -1
- package/lib/interaction/native/elementHighlightByColor.d.ts +4 -1
- package/lib/interaction/native/elementHighlightByColor.js +18 -2
- package/lib/interaction/native/elementHighlightByColor.js.map +1 -1
- package/lib/interaction/native/elementHighlightByX.d.ts +3 -3
- package/lib/interaction/native/elementHighlightByX.js +18 -2
- package/lib/interaction/native/elementHighlightByX.js.map +1 -1
- package/lib/interaction/native/elementSelect.d.ts +1 -1
- package/lib/interaction/native/elementSelect.js +41 -20
- package/lib/interaction/native/elementSelect.js.map +1 -1
- package/lib/interaction/native/elementSelectByColor.js +2 -1
- package/lib/interaction/native/elementSelectByColor.js.map +1 -1
- package/lib/interaction/native/elementSelectByX.js +2 -1
- package/lib/interaction/native/elementSelectByX.js.map +1 -1
- package/lib/interaction/native/legendFilter.d.ts +4 -0
- package/lib/interaction/native/legendFilter.js +10 -3
- package/lib/interaction/native/legendFilter.js.map +1 -1
- package/lib/interaction/native/legendHighlight.d.ts +4 -0
- package/lib/interaction/native/legendHighlight.js +98 -0
- package/lib/interaction/native/legendHighlight.js.map +1 -0
- package/lib/interaction/native/utils.d.ts +13 -2
- package/lib/interaction/native/utils.js +154 -27
- package/lib/interaction/native/utils.js.map +1 -1
- package/lib/label-transform/overlapDodgeY.js +0 -8
- package/lib/label-transform/overlapDodgeY.js.map +1 -1
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/runtime/plot.js +3 -3
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +20 -12
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/types/options.d.ts +4 -2
- package/lib/shape/area/hv.d.ts +3 -0
- package/lib/shape/area/hv.js +13 -0
- package/lib/shape/area/hv.js.map +1 -0
- package/lib/shape/area/hvh.d.ts +3 -0
- package/lib/shape/area/{step.js → hvh.js} +5 -5
- package/lib/shape/area/hvh.js.map +1 -0
- package/lib/shape/area/vh.d.ts +3 -0
- package/lib/shape/area/vh.js +13 -0
- package/lib/shape/area/vh.js.map +1 -0
- package/lib/shape/index.d.ts +6 -2
- package/lib/shape/index.js +7 -3
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval/color.d.ts +1 -0
- package/lib/shape/interval/color.js +67 -54
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/spec/composition.d.ts +0 -3
- package/lib/spec/interaction.d.ts +24 -11
- package/lib/spec/transform.d.ts +13 -3
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/transform/sample.js +42 -26
- package/lib/transform/sample.js.map +1 -1
- package/lib/transform/utils/lttb.d.ts +5 -0
- package/lib/transform/utils/lttb.js +60 -0
- package/lib/transform/utils/lttb.js.map +1 -0
- package/lib/utils/event.d.ts +0 -2
- package/lib/utils/event.js +1 -21
- package/lib/utils/event.js.map +1 -1
- package/lib/utils/scale.d.ts +1 -0
- package/lib/utils/scale.js +5 -4
- package/lib/utils/scale.js.map +1 -1
- package/lib/utils/vector.d.ts +1 -1
- package/lib/utils/vector.js +1 -1
- package/package.json +4 -3
- package/src/.DS_Store +0 -0
- package/src/api/chart.ts +37 -16
- package/src/api/composition/base.ts +46 -1
- package/src/api/mark/base.ts +58 -0
- package/src/api/mark/mark.ts +1 -20
- package/src/api/props.ts +0 -23
- package/src/component/axis.ts +7 -0
- package/src/component/legendContinuous.ts +15 -5
- package/src/data/.DS_Store +0 -0
- package/src/interaction/index.ts +1 -0
- package/src/interaction/native/elementHighlight.ts +78 -12
- package/src/interaction/native/elementHighlightByColor.ts +9 -4
- package/src/interaction/native/elementHighlightByX.ts +9 -5
- package/src/interaction/native/elementSelect.ts +58 -15
- package/src/interaction/native/elementSelectByColor.ts +4 -1
- package/src/interaction/native/elementSelectByX.ts +4 -1
- package/src/interaction/native/legendFilter.ts +8 -4
- package/src/interaction/native/legendHighlight.ts +87 -0
- package/src/interaction/native/utils.ts +183 -26
- package/src/label-transform/overlapDodgeY.ts +0 -7
- package/src/mark/area.ts +1 -1
- package/src/runtime/plot.ts +4 -4
- package/src/runtime/render.ts +26 -13
- package/src/runtime/types/options.ts +10 -2
- package/src/shape/.DS_Store +0 -0
- package/src/shape/area/hv.ts +20 -0
- package/src/shape/area/{step.ts → hvh.ts} +3 -3
- package/src/shape/area/vh.ts +20 -0
- package/src/shape/index.ts +7 -2
- package/src/shape/interval/color.ts +86 -54
- package/src/spec/composition.ts +0 -1
- package/src/spec/interaction.ts +35 -11
- package/src/spec/transform.ts +27 -2
- package/src/stdlib/index.ts +8 -6
- package/src/transform/sample.ts +54 -18
- package/src/transform/utils/lttb.ts +73 -0
- package/src/utils/event.ts +0 -26
- package/src/utils/scale.ts +4 -4
- package/src/utils/vector.ts +1 -1
- package/esm/shape/area/step.d.ts +0 -3
- package/esm/shape/area/step.js.map +0 -1
- package/lib/shape/area/step.d.ts +0 -3
- package/lib/shape/area/step.js.map +0 -1
package/src/runtime/render.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { Canvas as GCanvas, DisplayObject, Group } from '@antv/g';
|
|
|
2
2
|
import { Renderer as CanvasRenderer } from '@antv/g-canvas';
|
|
3
3
|
import { Plugin as DragAndDropPlugin } from '@antv/g-plugin-dragndrop';
|
|
4
4
|
import { deepMix } from '@antv/util';
|
|
5
|
+
import EventEmitter from '@antv/event-emitter';
|
|
5
6
|
import { createLibrary } from '../stdlib';
|
|
6
7
|
import { select } from '../utils/selection';
|
|
7
|
-
import {
|
|
8
|
+
import { CHART_LIFE_CIRCLE } from '../utils/event';
|
|
8
9
|
import { G2Context, G2ViewTree } from './types/options';
|
|
9
10
|
import { plot } from './plot';
|
|
10
11
|
|
|
@@ -65,12 +66,17 @@ export function render<T extends G2ViewTree = G2ViewTree>(
|
|
|
65
66
|
// Initialize the context if it is not provided.
|
|
66
67
|
const { width = 640, height = 480, on } = options;
|
|
67
68
|
const keyed = inferKeys(options);
|
|
68
|
-
const {
|
|
69
|
+
const {
|
|
70
|
+
canvas = Canvas(width, height),
|
|
71
|
+
library = createLibrary(),
|
|
72
|
+
emitter = new EventEmitter(),
|
|
73
|
+
} = context;
|
|
69
74
|
context.canvas = canvas;
|
|
70
75
|
context.library = library;
|
|
76
|
+
context.emitter = emitter;
|
|
71
77
|
canvas.resize(width, height);
|
|
72
78
|
|
|
73
|
-
|
|
79
|
+
emitter.emit(CHART_LIFE_CIRCLE.BEFORE_RENDER);
|
|
74
80
|
|
|
75
81
|
// Plot the chart and mutate context.
|
|
76
82
|
// Make sure that plot chart after container is ready for every time.
|
|
@@ -79,8 +85,10 @@ export function render<T extends G2ViewTree = G2ViewTree>(
|
|
|
79
85
|
.then(() =>
|
|
80
86
|
plot<T>({ ...keyed, width, height }, selection, library, context),
|
|
81
87
|
)
|
|
82
|
-
.then(
|
|
83
|
-
|
|
88
|
+
.then(() => {
|
|
89
|
+
emitter.emit(CHART_LIFE_CIRCLE.AFTER_RENDER);
|
|
90
|
+
callback?.();
|
|
91
|
+
});
|
|
84
92
|
|
|
85
93
|
// Return the container HTML element wraps the canvas or svg element.
|
|
86
94
|
return normalizeContainer(canvas.getConfig().container);
|
|
@@ -94,7 +102,11 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
|
|
|
94
102
|
// Initialize the context if it is not provided.
|
|
95
103
|
const { width = 640, height = 480, on } = options;
|
|
96
104
|
const keyed = inferKeys(options);
|
|
97
|
-
const {
|
|
105
|
+
const {
|
|
106
|
+
library = createLibrary(),
|
|
107
|
+
group = new Group(),
|
|
108
|
+
emitter = new EventEmitter(),
|
|
109
|
+
} = context;
|
|
98
110
|
|
|
99
111
|
if (!group?.parentElement) {
|
|
100
112
|
throw new Error(
|
|
@@ -105,13 +117,15 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
|
|
|
105
117
|
const selection = select(group);
|
|
106
118
|
context.group = group;
|
|
107
119
|
context.library = library;
|
|
120
|
+
context.emitter = emitter;
|
|
108
121
|
|
|
109
|
-
|
|
122
|
+
emitter.emit(CHART_LIFE_CIRCLE.BEFORE_RENDER);
|
|
110
123
|
// Plot the chart and mutate context.
|
|
111
124
|
// Make sure that plot chart after container is ready for every time.
|
|
112
|
-
plot<T>({ ...keyed, width, height }, selection, library, context)
|
|
113
|
-
.
|
|
114
|
-
|
|
125
|
+
plot<T>({ ...keyed, width, height }, selection, library, context).then(() => {
|
|
126
|
+
emitter.emit(CHART_LIFE_CIRCLE.AFTER_RENDER);
|
|
127
|
+
callback?.();
|
|
128
|
+
});
|
|
115
129
|
|
|
116
130
|
// Return the Group wraps the canvas or svg element.
|
|
117
131
|
return group;
|
|
@@ -121,12 +135,11 @@ export function destroy<T extends G2ViewTree = G2ViewTree>(
|
|
|
121
135
|
options: T,
|
|
122
136
|
context: G2Context = {},
|
|
123
137
|
) {
|
|
124
|
-
const {
|
|
125
|
-
const { canvas } = context;
|
|
138
|
+
const { canvas, emitter } = context;
|
|
126
139
|
if (canvas) {
|
|
127
140
|
canvas.destroy();
|
|
128
141
|
}
|
|
129
|
-
|
|
142
|
+
emitter.off();
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
function normalizeContainer(container: HTMLElement | string): HTMLElement {
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Canvas, IAnimation as GAnimation } from '@antv/g';
|
|
2
2
|
import type { DisplayObject } from '@antv/g';
|
|
3
|
-
import
|
|
3
|
+
import EventEmitter from '@antv/event-emitter';
|
|
4
|
+
import {
|
|
5
|
+
G2Title,
|
|
6
|
+
G2ViewDescriptor,
|
|
7
|
+
GuideComponentPosition,
|
|
8
|
+
Layout,
|
|
9
|
+
Primitive,
|
|
10
|
+
} from './common';
|
|
4
11
|
import {
|
|
5
12
|
G2BaseComponent,
|
|
6
13
|
StatisticComponent,
|
|
@@ -46,9 +53,10 @@ export type G2Library = Record<
|
|
|
46
53
|
export type G2Context = {
|
|
47
54
|
library?: G2Library;
|
|
48
55
|
canvas?: Canvas;
|
|
56
|
+
emitter?: EventEmitter;
|
|
49
57
|
group?: DisplayObject;
|
|
50
58
|
animations?: GAnimation[];
|
|
51
|
-
|
|
59
|
+
views?: G2ViewDescriptor[];
|
|
52
60
|
};
|
|
53
61
|
|
|
54
62
|
export type G2View = {
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { curveStepAfter } from 'd3-shape';
|
|
2
|
+
import { ShapeComponent as SC } from '../../runtime';
|
|
3
|
+
import { Curve } from './curve';
|
|
4
|
+
|
|
5
|
+
export type HVOptions = Record<string, any>;
|
|
6
|
+
|
|
7
|
+
export const HV: SC<HVOptions> = (options) => {
|
|
8
|
+
return (P, value, coordinate, theme) => {
|
|
9
|
+
return Curve({ curve: curveStepAfter, ...options })(
|
|
10
|
+
P,
|
|
11
|
+
value,
|
|
12
|
+
coordinate,
|
|
13
|
+
theme,
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
HV.props = {
|
|
19
|
+
...Curve.props,
|
|
20
|
+
};
|
|
@@ -2,14 +2,14 @@ import { curveStep } from 'd3-shape';
|
|
|
2
2
|
import { ShapeComponent as SC } from '../../runtime';
|
|
3
3
|
import { Curve } from './curve';
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type HVHOptions = Record<string, any>;
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const HVH: SC<HVHOptions> = (options) => {
|
|
8
8
|
return (P, value, coordinate, theme) => {
|
|
9
9
|
return Curve({ curve: curveStep, ...options })(P, value, coordinate, theme);
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
HVH.props = {
|
|
14
14
|
...Curve.props,
|
|
15
15
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { curveStepBefore } from 'd3-shape';
|
|
2
|
+
import { ShapeComponent as SC } from '../../runtime';
|
|
3
|
+
import { Curve } from './curve';
|
|
4
|
+
|
|
5
|
+
export type VHOptions = Record<string, any>;
|
|
6
|
+
|
|
7
|
+
export const VH: SC<VHOptions> = (options) => {
|
|
8
|
+
return (P, value, coordinate, theme) => {
|
|
9
|
+
return Curve({ curve: curveStepBefore, ...options })(
|
|
10
|
+
P,
|
|
11
|
+
value,
|
|
12
|
+
coordinate,
|
|
13
|
+
theme,
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
VH.props = {
|
|
19
|
+
...Curve.props,
|
|
20
|
+
};
|
package/src/shape/index.ts
CHANGED
|
@@ -31,7 +31,9 @@ export { Text } from './text/text';
|
|
|
31
31
|
export { Badge } from './text/badge';
|
|
32
32
|
export { Area } from './area/area';
|
|
33
33
|
export { Smooth as SmoothArea } from './area/smooth';
|
|
34
|
-
export {
|
|
34
|
+
export { HVH as HVHArea } from './area/hvh';
|
|
35
|
+
export { VH as VHArea } from './area/vh';
|
|
36
|
+
export { HV as HVArea } from './area/hv';
|
|
35
37
|
export { Link } from './link/link';
|
|
36
38
|
export { Smooth as SmoothEdge } from './link/smooth';
|
|
37
39
|
export { VHV as VHVEdge } from './link/vhv';
|
|
@@ -83,7 +85,10 @@ export type { TextOptions } from './text/text';
|
|
|
83
85
|
export type { BadgeOptions } from './text/badge';
|
|
84
86
|
export type { AreaOptions } from './area/area';
|
|
85
87
|
export type { SmoothOptions as SmoothAreaOptions } from './area/smooth';
|
|
86
|
-
export type {
|
|
88
|
+
export type { HVHOptions as HVHAreaOptions } from './area/hvh';
|
|
89
|
+
export type { VHOptions as VHAreaOptions } from './area/vh';
|
|
90
|
+
export type { HVOptions as HVAreaOptions } from './area/hv';
|
|
91
|
+
|
|
87
92
|
export type { LinkOptions } from './link/link';
|
|
88
93
|
export type { ImageOptions } from './image/image';
|
|
89
94
|
export type { PolygonOptions } from './polygon/polygon';
|
|
@@ -17,6 +17,72 @@ export type ColorOptions = {
|
|
|
17
17
|
[key: string]: any;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
// Render rect in different coordinate.
|
|
21
|
+
export function rect(
|
|
22
|
+
points,
|
|
23
|
+
value,
|
|
24
|
+
coordinate,
|
|
25
|
+
style: Record<string, any> = {},
|
|
26
|
+
) {
|
|
27
|
+
const {
|
|
28
|
+
inset = 0,
|
|
29
|
+
radius = 0,
|
|
30
|
+
insetLeft = inset,
|
|
31
|
+
insetTop = inset,
|
|
32
|
+
insetRight = inset,
|
|
33
|
+
insetBottom = inset,
|
|
34
|
+
radiusBottomLeft = radius,
|
|
35
|
+
radiusBottomRight = radius,
|
|
36
|
+
radiusTopLeft = radius,
|
|
37
|
+
radiusTopRight = radius,
|
|
38
|
+
...rest
|
|
39
|
+
} = style;
|
|
40
|
+
if (!isPolar(coordinate) && !isHelix(coordinate)) {
|
|
41
|
+
const tpShape = !!isTranspose(coordinate);
|
|
42
|
+
|
|
43
|
+
const [p0, , p2] = tpShape ? reorder(points) : points;
|
|
44
|
+
const [x, y] = p0;
|
|
45
|
+
const [width, height] = sub(p2, p0);
|
|
46
|
+
// Deal with width or height is negative.
|
|
47
|
+
const absX = width > 0 ? x : x + width;
|
|
48
|
+
const absY = height > 0 ? y : y + height;
|
|
49
|
+
const absWidth = Math.abs(width);
|
|
50
|
+
const absHeight = Math.abs(height);
|
|
51
|
+
const finalX = absX + insetLeft;
|
|
52
|
+
const finalY = absY + insetTop;
|
|
53
|
+
const finalWidth = absWidth - (insetLeft + insetRight);
|
|
54
|
+
const finalHeight = absHeight - (insetTop + insetBottom);
|
|
55
|
+
|
|
56
|
+
return select(new Rect({}))
|
|
57
|
+
.style('x', finalX)
|
|
58
|
+
.style('y', finalY)
|
|
59
|
+
.style('width', finalWidth)
|
|
60
|
+
.style('height', finalHeight)
|
|
61
|
+
.style('radius', [
|
|
62
|
+
radiusTopLeft,
|
|
63
|
+
radiusTopRight,
|
|
64
|
+
radiusBottomRight,
|
|
65
|
+
radiusBottomLeft,
|
|
66
|
+
])
|
|
67
|
+
.call(applyStyle, rest)
|
|
68
|
+
.node();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Render path in polar coordinate.
|
|
72
|
+
const { y, y1 } = value;
|
|
73
|
+
const center = coordinate.getCenter() as Vector2;
|
|
74
|
+
const arcObject = getArcObject(coordinate, points, [y, y1]);
|
|
75
|
+
const path = arc()
|
|
76
|
+
.cornerRadius(radius as number)
|
|
77
|
+
.padAngle((inset * Math.PI) / 180);
|
|
78
|
+
|
|
79
|
+
return select(new Path({}))
|
|
80
|
+
.style('path', path(arcObject))
|
|
81
|
+
.style('transform', `translate(${center[0]}, ${center[1]})`)
|
|
82
|
+
.call(applyStyle, rest)
|
|
83
|
+
.node();
|
|
84
|
+
}
|
|
85
|
+
|
|
20
86
|
/**
|
|
21
87
|
* Render rect in different coordinate.
|
|
22
88
|
* Calc arc path based on control points directly rather startAngle, endAngle, innerRadius,
|
|
@@ -36,7 +102,6 @@ export const Color: SC<ColorOptions> = (options) => {
|
|
|
36
102
|
return (points, value, coordinate, theme) => {
|
|
37
103
|
const { mark, shape, defaultShape } = value;
|
|
38
104
|
const {
|
|
39
|
-
// [colorAttribute]: defaultColor,
|
|
40
105
|
defaultColor,
|
|
41
106
|
radius: defaultRadius = 0,
|
|
42
107
|
...defaults
|
|
@@ -55,70 +120,37 @@ export const Color: SC<ColorOptions> = (options) => {
|
|
|
55
120
|
innerRadiusTopRight = innerRadius,
|
|
56
121
|
innerRadiusBottomRight = innerRadius,
|
|
57
122
|
innerRadiusBottomLeft = innerRadius,
|
|
123
|
+
lineWidth = colorAttribute === 'stroke' || stroke ? defaultLineWidth : 0,
|
|
58
124
|
inset = 0,
|
|
59
125
|
insetLeft = inset,
|
|
60
126
|
insetRight = inset,
|
|
61
127
|
insetBottom = inset,
|
|
62
128
|
insetTop = inset,
|
|
63
|
-
lineWidth = colorAttribute === 'stroke' || stroke ? defaultLineWidth : 0,
|
|
64
129
|
...rest
|
|
65
130
|
} = style;
|
|
66
131
|
const { color = defaultColor, opacity } = value;
|
|
67
132
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const finalWidth = absWidth - (insetLeft + insetRight);
|
|
83
|
-
const finalHeight = absHeight - (insetTop + insetBottom);
|
|
84
|
-
|
|
85
|
-
return select(new Rect({}))
|
|
86
|
-
.call(applyStyle, defaults)
|
|
87
|
-
.style('lineWidth', lineWidth)
|
|
88
|
-
.style('x', finalX)
|
|
89
|
-
.style('y', finalY)
|
|
90
|
-
.style('width', finalWidth)
|
|
91
|
-
.style('height', finalHeight)
|
|
92
|
-
.style('stroke', stroke === undefined ? color : stroke)
|
|
93
|
-
.style(toOpacityKey(options), opacity)
|
|
94
|
-
.style(colorAttribute, color)
|
|
95
|
-
.style('radius', [
|
|
96
|
-
first ? radiusTopLeft : innerRadiusTopLeft,
|
|
97
|
-
first ? radiusTopRight : innerRadiusTopRight,
|
|
98
|
-
last ? radiusBottomRight : innerRadiusBottomRight,
|
|
99
|
-
last ? radiusBottomLeft : innerRadiusBottomLeft,
|
|
100
|
-
])
|
|
101
|
-
.call(applyStyle, rest)
|
|
102
|
-
.node();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Render path in polar coordinate.
|
|
106
|
-
const { y, y1 } = value;
|
|
107
|
-
const center = coordinate.getCenter() as Vector2;
|
|
108
|
-
const arcObject = getArcObject(coordinate, points, [y, y1]);
|
|
109
|
-
const path = arc()
|
|
110
|
-
.cornerRadius(radius as number)
|
|
111
|
-
.padAngle((inset * Math.PI) / 180);
|
|
133
|
+
// Extended style, which is not supported by native g shape,
|
|
134
|
+
// should apply at first.
|
|
135
|
+
const extendedStyle = {
|
|
136
|
+
radius,
|
|
137
|
+
radiusTopLeft: first ? radiusTopLeft : innerRadiusTopLeft,
|
|
138
|
+
radiusTopRight: first ? radiusTopRight : innerRadiusTopRight,
|
|
139
|
+
radiusBottomRight: last ? radiusBottomRight : innerRadiusBottomRight,
|
|
140
|
+
radiusBottomLeft: last ? radiusBottomLeft : innerRadiusBottomLeft,
|
|
141
|
+
inset,
|
|
142
|
+
insetLeft,
|
|
143
|
+
insetRight,
|
|
144
|
+
insetBottom,
|
|
145
|
+
insetTop,
|
|
146
|
+
};
|
|
112
147
|
|
|
113
|
-
return select(
|
|
114
|
-
.call(applyStyle, defaults)
|
|
115
|
-
.style('path', path(arcObject))
|
|
116
|
-
.style('transform', `translate(${center[0]}, ${center[1]})`)
|
|
117
|
-
.style('stroke', color || stroke)
|
|
118
|
-
.style('lineWidth', lineWidth)
|
|
119
|
-
.style(colorAttribute, color)
|
|
148
|
+
return select(rect(points, value, coordinate, extendedStyle))
|
|
149
|
+
.call(applyStyle, { ...defaults, ...rest })
|
|
120
150
|
.style(toOpacityKey(options), opacity)
|
|
121
|
-
.
|
|
151
|
+
.style(colorAttribute, color)
|
|
152
|
+
.style('lineWidth', lineWidth)
|
|
153
|
+
.style('stroke', stroke === undefined ? color : stroke)
|
|
122
154
|
.node();
|
|
123
155
|
};
|
|
124
156
|
};
|
package/src/spec/composition.ts
CHANGED
package/src/spec/interaction.ts
CHANGED
|
@@ -12,9 +12,10 @@ export type Interaction =
|
|
|
12
12
|
| ElementSelectInteraction
|
|
13
13
|
| TooltipInteraction
|
|
14
14
|
| FisheyeInteraction
|
|
15
|
-
|
|
|
15
|
+
| ChartIndexInteraction
|
|
16
16
|
| CustomInteraction
|
|
17
17
|
| LegendFilterInteraction
|
|
18
|
+
| LegendHighlightInteraction
|
|
18
19
|
| BrushHighlightInteraction
|
|
19
20
|
| BrushXHighlightInteraction
|
|
20
21
|
| BrushYHighlightInteraction
|
|
@@ -45,6 +46,7 @@ export type InteractionTypes =
|
|
|
45
46
|
| 'fisheye'
|
|
46
47
|
| 'tooltip'
|
|
47
48
|
| 'legendFilter'
|
|
49
|
+
| 'legendHighlight'
|
|
48
50
|
| 'brushXHighlight'
|
|
49
51
|
| 'brushYHighlight'
|
|
50
52
|
| 'brushHighlight'
|
|
@@ -125,33 +127,54 @@ export type ElementHighlightInteraction = {
|
|
|
125
127
|
type?: 'elementHighlight';
|
|
126
128
|
// @todo: Style supported by G.
|
|
127
129
|
link?: boolean;
|
|
128
|
-
|
|
130
|
+
background?: boolean;
|
|
131
|
+
offset?: number;
|
|
132
|
+
} & Record<
|
|
133
|
+
`${'link' | 'highlighted' | 'unhighlighted' | 'background'}${any}`,
|
|
134
|
+
any
|
|
135
|
+
>;
|
|
129
136
|
|
|
130
137
|
export type ElementSelectInteraction = {
|
|
131
138
|
type?: 'elementSelect';
|
|
132
139
|
single?: boolean;
|
|
133
|
-
|
|
140
|
+
background?: true;
|
|
141
|
+
offset?: number;
|
|
142
|
+
} & Record<`${'selected' | 'link' | 'unselected' | 'background'}${any}`, any>;
|
|
134
143
|
|
|
135
144
|
export type ElementSelectByColorInteraction = {
|
|
136
145
|
type?: 'elementSelectByColor';
|
|
137
146
|
single?: boolean;
|
|
147
|
+
offset?: number;
|
|
138
148
|
} & Record<`${'selected' | 'link' | 'unselected'}${any}`, any>;
|
|
139
149
|
|
|
140
150
|
export type ElementSelectByXInteraction = {
|
|
141
151
|
type?: 'elementSelectByX';
|
|
142
152
|
single?: boolean;
|
|
143
|
-
|
|
153
|
+
background?: true;
|
|
154
|
+
offset?: number;
|
|
155
|
+
} & Record<`${'selected' | 'link' | 'unselected' | 'background'}${any}`, any>;
|
|
144
156
|
|
|
145
157
|
export type ElementHighlightByXInteraction = {
|
|
146
158
|
type?: 'elementHighlightByX';
|
|
147
159
|
x?: string;
|
|
148
160
|
link?: boolean;
|
|
149
|
-
|
|
161
|
+
background?: boolean;
|
|
162
|
+
offset?: number;
|
|
163
|
+
} & Record<
|
|
164
|
+
`${'link' | 'highlighted' | 'unhighlighted' | 'background'}${any}`,
|
|
165
|
+
any
|
|
166
|
+
>;
|
|
150
167
|
|
|
151
168
|
export type ElementHighlightByColorInteraction = {
|
|
152
169
|
type?: 'elementHighlightByColor';
|
|
153
170
|
color?: string;
|
|
154
|
-
|
|
171
|
+
background?: boolean;
|
|
172
|
+
link?: boolean;
|
|
173
|
+
offset?: number;
|
|
174
|
+
} & Record<
|
|
175
|
+
`${'link' | 'highlighted' | 'unhighlighted' | 'background'}${any}`,
|
|
176
|
+
any
|
|
177
|
+
>;
|
|
155
178
|
|
|
156
179
|
export type LegendFilterInteraction = {
|
|
157
180
|
type?: 'legendFilter';
|
|
@@ -159,7 +182,12 @@ export type LegendFilterInteraction = {
|
|
|
159
182
|
[key: string]: any; // @todo
|
|
160
183
|
} & Record<`${'marker' | 'label'}Unselected${any}`, any>;
|
|
161
184
|
|
|
162
|
-
export type
|
|
185
|
+
export type LegendHighlightInteraction = {
|
|
186
|
+
type?: 'legendHighlight';
|
|
187
|
+
[key: string]: any; // @todo
|
|
188
|
+
} & Record<`${'marker' | 'label'}Unhighlighted${any}`, any>;
|
|
189
|
+
|
|
190
|
+
export type ChartIndexInteraction = {
|
|
163
191
|
type?: 'chartIndex';
|
|
164
192
|
wait?: number;
|
|
165
193
|
leading?: boolean;
|
|
@@ -181,10 +209,6 @@ export type LegendActiveInteraction = {
|
|
|
181
209
|
type?: 'legendActive';
|
|
182
210
|
};
|
|
183
211
|
|
|
184
|
-
export type LegendHighlightInteraction = {
|
|
185
|
-
type?: 'legendHighlight';
|
|
186
|
-
};
|
|
187
|
-
|
|
188
212
|
export type TooltipInteraction = Omit<TooltipAction, 'type'> & {
|
|
189
213
|
type?: 'tooltip';
|
|
190
214
|
shared?: boolean;
|
package/src/spec/transform.ts
CHANGED
|
@@ -254,11 +254,36 @@ export type BinTransform = {
|
|
|
254
254
|
thresholdsY?: number;
|
|
255
255
|
} & { [key in ChannelTypes]?: Reducer };
|
|
256
256
|
|
|
257
|
+
export type SampleFunction = (
|
|
258
|
+
I: number[],
|
|
259
|
+
X: number[],
|
|
260
|
+
Y: number[],
|
|
261
|
+
thresholds: number,
|
|
262
|
+
) => number[];
|
|
263
|
+
|
|
257
264
|
export type SampleTransform = {
|
|
258
265
|
type?: 'sample';
|
|
259
|
-
|
|
266
|
+
/**
|
|
267
|
+
* Sample strategy. Default is 'median'.
|
|
268
|
+
*/
|
|
269
|
+
strategy?:
|
|
270
|
+
| 'lttb'
|
|
271
|
+
| 'median'
|
|
272
|
+
| 'max'
|
|
273
|
+
| 'min'
|
|
274
|
+
| 'first'
|
|
275
|
+
| 'last'
|
|
276
|
+
| SampleFunction;
|
|
277
|
+
/**
|
|
278
|
+
* The thresholds of sample, when data size great then thresholds, sample will take effect.
|
|
279
|
+
* Default is 2000.
|
|
280
|
+
*/
|
|
260
281
|
thresholds?: number;
|
|
261
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Group data by fields, for series data.
|
|
284
|
+
*/
|
|
285
|
+
groupBy?: string | string[];
|
|
286
|
+
};
|
|
262
287
|
|
|
263
288
|
export type FilterTransform = {
|
|
264
289
|
type?: 'filter';
|
package/src/stdlib/index.ts
CHANGED
|
@@ -114,7 +114,9 @@ import {
|
|
|
114
114
|
Connector as ConnectorShape,
|
|
115
115
|
Area,
|
|
116
116
|
SmoothArea,
|
|
117
|
-
|
|
117
|
+
HVHArea,
|
|
118
|
+
VHArea,
|
|
119
|
+
HVArea,
|
|
118
120
|
SmoothEdge,
|
|
119
121
|
VHVEdge,
|
|
120
122
|
Arc,
|
|
@@ -159,10 +161,6 @@ import {
|
|
|
159
161
|
GrowInY,
|
|
160
162
|
} from '../animation';
|
|
161
163
|
import {
|
|
162
|
-
// ElementHighlight,
|
|
163
|
-
// ElementSelected,
|
|
164
|
-
// Tooltip,
|
|
165
|
-
// Fisheye as FisheyeInteraction,
|
|
166
164
|
ElementHighlight,
|
|
167
165
|
ElementHighlightByX,
|
|
168
166
|
ElementHighlightByColor,
|
|
@@ -173,6 +171,7 @@ import {
|
|
|
173
171
|
Fisheye as ChartFisheye,
|
|
174
172
|
Tooltip,
|
|
175
173
|
LegendFilter,
|
|
174
|
+
LegendHighlight,
|
|
176
175
|
BrushHighlight,
|
|
177
176
|
BrushXHighlight,
|
|
178
177
|
BrushYHighlight,
|
|
@@ -447,7 +446,9 @@ export function createLibrary(): G2Library {
|
|
|
447
446
|
'shape.text.text': Text,
|
|
448
447
|
'shape.area.area': Area,
|
|
449
448
|
'shape.area.smooth': SmoothArea,
|
|
450
|
-
'shape.area.
|
|
449
|
+
'shape.area.hvh': HVHArea,
|
|
450
|
+
'shape.area.vh': VHArea,
|
|
451
|
+
'shape.area.hv': HVArea,
|
|
451
452
|
'shape.link.smooth': SmoothEdge,
|
|
452
453
|
'shape.link.vhv': VHVEdge,
|
|
453
454
|
'shape.link.arc': Arc,
|
|
@@ -503,6 +504,7 @@ export function createLibrary(): G2Library {
|
|
|
503
504
|
'interaction.chartIndex': ChartIndex,
|
|
504
505
|
'interaction.tooltip': Tooltip,
|
|
505
506
|
'interaction.legendFilter': LegendFilter,
|
|
507
|
+
'interaction.legendHighlight': LegendHighlight,
|
|
506
508
|
'interaction.brushHighlight': BrushHighlight,
|
|
507
509
|
'interaction.brushXHighlight': BrushXHighlight,
|
|
508
510
|
'interaction.brushYHighlight': BrushYHighlight,
|
package/src/transform/sample.ts
CHANGED
|
@@ -1,14 +1,46 @@
|
|
|
1
|
+
// @ts-ignore medianIndex exist in d3-array@3.2.0, but @types/d3-array Expired.
|
|
2
|
+
import { maxIndex, minIndex, medianIndex } from 'd3-array';
|
|
1
3
|
import { TransformComponent as TC, Primitive } from '../runtime';
|
|
2
|
-
import { SampleTransform } from '../spec';
|
|
4
|
+
import { SampleTransform, SampleFunction } from '../spec';
|
|
3
5
|
import { createGroups } from './utils/order';
|
|
4
|
-
import {
|
|
6
|
+
import { columnOf } from './utils/helper';
|
|
7
|
+
import { lttb } from './utils/lttb';
|
|
5
8
|
|
|
6
9
|
export type SampleOptions = Omit<SampleTransform, 'type'>;
|
|
7
10
|
|
|
11
|
+
function normalizeSample(
|
|
12
|
+
strategy: SampleTransform['strategy'],
|
|
13
|
+
): SampleFunction {
|
|
14
|
+
if (typeof strategy === 'function') return strategy;
|
|
15
|
+
if (strategy === 'lttb') return lttb;
|
|
16
|
+
|
|
17
|
+
const strategies = {
|
|
18
|
+
first: (f: number[]) => [f[0]],
|
|
19
|
+
last: (f: number[]) => [f[f.length - 1]],
|
|
20
|
+
min: (f: number[], X: number[], Y: number[]) => [
|
|
21
|
+
f[minIndex(f, (i) => Y[i])],
|
|
22
|
+
],
|
|
23
|
+
max: (f: number[], X: number[], Y: number[]) => [
|
|
24
|
+
f[maxIndex(f, (i) => Y[i])],
|
|
25
|
+
],
|
|
26
|
+
median: (f: number[], X: number[], Y: number[]) => [
|
|
27
|
+
f[medianIndex(f, (i) => Y[i])],
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
const sampleFunction = strategies[strategy] || strategies.median;
|
|
31
|
+
return (I: number[], X: number[], Y: number[], thresholds: number) => {
|
|
32
|
+
// Sepreate group to frames, then sample each frame.
|
|
33
|
+
// Keep more data as possible.
|
|
34
|
+
const frameSize = Math.max(1, Math.floor(I.length / thresholds));
|
|
35
|
+
const frames = getFrames(I, frameSize);
|
|
36
|
+
return frames.flatMap((frame) => sampleFunction(frame, X, Y));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
8
40
|
/**
|
|
9
41
|
* Split the array into frame with each frameSize.
|
|
10
42
|
*/
|
|
11
|
-
function getFrames(I: Primitive[], frameSize: number) {
|
|
43
|
+
function getFrames(I: Primitive[], frameSize: number): number[][] {
|
|
12
44
|
const size = I.length;
|
|
13
45
|
const frames = [];
|
|
14
46
|
let i = 0;
|
|
@@ -23,22 +55,26 @@ function getFrames(I: Primitive[], frameSize: number) {
|
|
|
23
55
|
* sample data for each group when data.length >= threshold(default = 2000).
|
|
24
56
|
*/
|
|
25
57
|
export const Sample: TC<SampleOptions> = (options = {}) => {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
const {
|
|
59
|
+
strategy = 'median',
|
|
60
|
+
thresholds = 2000,
|
|
61
|
+
groupBy = 'series',
|
|
62
|
+
} = options;
|
|
63
|
+
const sampleFunction = normalizeSample(strategy);
|
|
64
|
+
|
|
65
|
+
return (I, mark) => {
|
|
66
|
+
const { encode } = mark;
|
|
67
|
+
const groups = createGroups(groupBy, I, mark);
|
|
68
|
+
const [X] = columnOf(encode, 'x');
|
|
69
|
+
const [Y] = columnOf(encode, 'y');
|
|
70
|
+
|
|
71
|
+
return [
|
|
72
|
+
groups.flatMap((g) =>
|
|
73
|
+
sampleFunction(g, X as number[], Y as number[], thresholds),
|
|
74
|
+
),
|
|
75
|
+
mark,
|
|
76
|
+
];
|
|
40
77
|
};
|
|
41
|
-
return GroupN({ ...rest, groupBy });
|
|
42
78
|
};
|
|
43
79
|
|
|
44
80
|
Sample.props = {};
|