@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/api/chart.ts
CHANGED
|
@@ -2,10 +2,11 @@ import { RendererPlugin, Canvas as GCanvas } 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 { debounce } from '@antv/util';
|
|
5
|
+
import EventEmitter from '@antv/event-emitter';
|
|
5
6
|
import { G2Context, render, destroy } from '../runtime';
|
|
6
7
|
import { ViewComposition } from '../spec';
|
|
7
8
|
import { getChartSize } from '../utils/size';
|
|
8
|
-
import { CHART_LIFE_CIRCLE
|
|
9
|
+
import { CHART_LIFE_CIRCLE } from '../utils/event';
|
|
9
10
|
import { Node } from './node';
|
|
10
11
|
import {
|
|
11
12
|
defineProps,
|
|
@@ -133,7 +134,6 @@ export interface Chart extends Composition, Mark {
|
|
|
133
134
|
transform: ArrayAttribute<ChartProps['transform'], Chart>;
|
|
134
135
|
theme: ObjectAttribute<ChartProps['theme'], Chart>;
|
|
135
136
|
title: ObjectAttribute<ChartProps['title'], Chart>;
|
|
136
|
-
on: ObjectAttribute<ChartProps['on'], Chart>;
|
|
137
137
|
scale: ObjectAttribute<ChartOptions['scale'], Chart>;
|
|
138
138
|
axis: ObjectAttribute<ChartOptions['axis'], Chart>;
|
|
139
139
|
legend: ObjectAttribute<ChartOptions['legend'], Chart>;
|
|
@@ -151,7 +151,6 @@ export const props: NodePropertyDescriptor[] = [
|
|
|
151
151
|
{ name: 'key', type: 'value' },
|
|
152
152
|
{ name: 'transform', type: 'array' },
|
|
153
153
|
{ name: 'theme', type: 'object' },
|
|
154
|
-
{ name: 'on', type: 'event' },
|
|
155
154
|
{ name: 'scale', type: 'object' },
|
|
156
155
|
{ name: 'axis', type: 'object' },
|
|
157
156
|
{ name: 'legend', type: 'object' },
|
|
@@ -164,16 +163,18 @@ export const props: NodePropertyDescriptor[] = [
|
|
|
164
163
|
export class Chart extends View<ChartOptions> {
|
|
165
164
|
private _container: HTMLElement;
|
|
166
165
|
private _context: G2Context;
|
|
166
|
+
private _emitter: EventEmitter;
|
|
167
167
|
|
|
168
168
|
constructor(options: ChartOptions = {}) {
|
|
169
169
|
const { container, ...rest } = options;
|
|
170
170
|
super(rest, 'view');
|
|
171
171
|
this._container = normalizeContainer(container);
|
|
172
|
-
this.
|
|
172
|
+
this._emitter = new EventEmitter();
|
|
173
|
+
this._context = { library, emitter: this._emitter };
|
|
173
174
|
this.bindAutoFit();
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
render(): Chart {
|
|
177
|
+
render(): Promise<Chart> {
|
|
177
178
|
if (!this._context.canvas) {
|
|
178
179
|
// Init width and height.
|
|
179
180
|
const {
|
|
@@ -201,9 +202,10 @@ export class Chart extends View<ChartOptions> {
|
|
|
201
202
|
plugins,
|
|
202
203
|
);
|
|
203
204
|
}
|
|
204
|
-
render(this.options(), this._context);
|
|
205
205
|
|
|
206
|
-
return
|
|
206
|
+
return new Promise((resolve) => {
|
|
207
|
+
render(this.options(), this._context, () => resolve(this));
|
|
208
|
+
});
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
options() {
|
|
@@ -218,23 +220,41 @@ export class Chart extends View<ChartOptions> {
|
|
|
218
220
|
return this._context;
|
|
219
221
|
}
|
|
220
222
|
|
|
223
|
+
on(event: string, callback: (...args: any[]) => any, once?: boolean): this {
|
|
224
|
+
this._emitter.on(event, callback, once);
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
once(event: string, callback: (...args: any[]) => any): this {
|
|
229
|
+
this._emitter.once(event, callback);
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
emit(event: string, ...args: any[]): this {
|
|
234
|
+
this._emitter.emit(event, ...args);
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
off(event?: string, callback?: (...args: any[]) => any) {
|
|
239
|
+
this._emitter.off(event, callback);
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
|
|
221
243
|
destroy() {
|
|
222
244
|
const options = this.options();
|
|
223
|
-
|
|
224
|
-
emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_DESTROY);
|
|
245
|
+
this.emit(CHART_LIFE_CIRCLE.BEFORE_DESTROY);
|
|
225
246
|
this.unbindAutoFit();
|
|
226
247
|
destroy(options, this._context);
|
|
227
248
|
// Remove the container.
|
|
228
249
|
removeContainer(this._container);
|
|
229
|
-
|
|
250
|
+
this.emit(CHART_LIFE_CIRCLE.AFTER_DESTROY);
|
|
230
251
|
}
|
|
231
252
|
|
|
232
253
|
clear() {
|
|
233
254
|
const options = this.options();
|
|
234
|
-
|
|
235
|
-
emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_CLEAR);
|
|
255
|
+
this.emit(CHART_LIFE_CIRCLE.BEFORE_CLEAR);
|
|
236
256
|
destroy(options, this._context);
|
|
237
|
-
|
|
257
|
+
this.emit(CHART_LIFE_CIRCLE.AFTER_CLEAR);
|
|
238
258
|
}
|
|
239
259
|
|
|
240
260
|
forceFit() {
|
|
@@ -256,11 +276,12 @@ export class Chart extends View<ChartOptions> {
|
|
|
256
276
|
return this;
|
|
257
277
|
}
|
|
258
278
|
|
|
259
|
-
|
|
279
|
+
this.emit(CHART_LIFE_CIRCLE.BEFORE_CHANGE_SIZE);
|
|
260
280
|
this.width(adjustedWidth);
|
|
261
281
|
this.height(adjustedHeight);
|
|
262
|
-
this.render()
|
|
263
|
-
|
|
282
|
+
return this.render().then(() => {
|
|
283
|
+
this.emit(CHART_LIFE_CIRCLE.AFTER_CHANGE_SIZE);
|
|
284
|
+
});
|
|
264
285
|
}
|
|
265
286
|
|
|
266
287
|
private onResize = debounce(() => {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { Coordinate } from '@antv/coord';
|
|
1
3
|
import { defineProps } from '../props';
|
|
2
4
|
import { Node } from '../node';
|
|
5
|
+
import { G2Theme, G2ViewDescriptor } from '../../runtime';
|
|
3
6
|
|
|
4
7
|
@defineProps([{ name: 'on', type: 'event' }])
|
|
5
8
|
export class Base<
|
|
@@ -7,5 +10,47 @@ export class Base<
|
|
|
7
10
|
ParentValue extends Record<string, any> = Record<string, any>,
|
|
8
11
|
ChildValue extends Record<string, any> = Record<string, any>,
|
|
9
12
|
> extends Node<Value, ParentValue, ChildValue> {
|
|
10
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Get view instance by key.
|
|
15
|
+
*/
|
|
16
|
+
getView(): G2ViewDescriptor {
|
|
17
|
+
const chart = this.root();
|
|
18
|
+
const { views } = chart.context();
|
|
19
|
+
if (!views?.length) return undefined;
|
|
20
|
+
return views.find((view) => view.key === this.attr('key'));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getCoordinate(): Coordinate {
|
|
24
|
+
return this.getView()?.coordinate;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getTheme(): G2Theme {
|
|
28
|
+
return this.getView()?.theme;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getGroup(): DisplayObject {
|
|
32
|
+
const key = this.attr('key');
|
|
33
|
+
if (!key) return undefined;
|
|
34
|
+
const chart = this.root();
|
|
35
|
+
const chartGroup = chart.context().canvas.getRoot();
|
|
36
|
+
return chartGroup.getElementById(key);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Show the view.
|
|
41
|
+
*/
|
|
42
|
+
show() {
|
|
43
|
+
const group = this.getGroup();
|
|
44
|
+
if (!group) return;
|
|
45
|
+
!group.isVisible() && group.setAttribute('visibility', 'visible');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Hide the view.
|
|
50
|
+
*/
|
|
51
|
+
hide() {
|
|
52
|
+
const group = this.getGroup();
|
|
53
|
+
if (!group) return;
|
|
54
|
+
group.isVisible() && group.setAttribute('visibility', 'hidden');
|
|
55
|
+
}
|
|
11
56
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { Node } from '../node';
|
|
3
|
+
import { G2MarkState, Scale } from '../../runtime';
|
|
4
|
+
|
|
5
|
+
export class MarkBase<
|
|
6
|
+
Value extends Record<string, any> = Record<string, any>,
|
|
7
|
+
ParentValue extends Record<string, any> = Record<string, any>,
|
|
8
|
+
ChildValue extends Record<string, any> = Record<string, any>,
|
|
9
|
+
> extends Node<Value, ParentValue, ChildValue> {
|
|
10
|
+
changeData(data: any) {
|
|
11
|
+
const chart = this.root();
|
|
12
|
+
if (!chart) return;
|
|
13
|
+
this.attr('data', data);
|
|
14
|
+
chart?.render();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get mark from chart views.
|
|
19
|
+
*/
|
|
20
|
+
getMark(): G2MarkState {
|
|
21
|
+
const chartView = this.root()?.getView();
|
|
22
|
+
if (!chartView) return undefined;
|
|
23
|
+
const { markState } = chartView;
|
|
24
|
+
const markKey = Array.from(markState.keys()).find(
|
|
25
|
+
(item) => item.key === this.attr('key'),
|
|
26
|
+
);
|
|
27
|
+
return markState.get(markKey);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get all scales instance.
|
|
32
|
+
*/
|
|
33
|
+
getScale(): Record<string, Scale> {
|
|
34
|
+
const chartView = this.root()?.getView();
|
|
35
|
+
if (!chartView) return undefined;
|
|
36
|
+
return chartView?.scale;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the scale instance by channel.
|
|
41
|
+
*/
|
|
42
|
+
getScaleByChannel(channel: string): Scale {
|
|
43
|
+
const chartView = this.root()?.getView();
|
|
44
|
+
if (!chartView) return undefined;
|
|
45
|
+
return chartView?.scale?.[channel];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get canvas group.
|
|
50
|
+
*/
|
|
51
|
+
getGroup(): DisplayObject {
|
|
52
|
+
const key = this.attr('key');
|
|
53
|
+
if (!key) return undefined;
|
|
54
|
+
const chart = this.root();
|
|
55
|
+
const chartGroup = chart.context().canvas.getRoot();
|
|
56
|
+
return chartGroup.getElementById(key);
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/api/mark/mark.ts
CHANGED
|
@@ -27,8 +27,8 @@ import {
|
|
|
27
27
|
WordCloudMark,
|
|
28
28
|
} from '../../spec';
|
|
29
29
|
import { NodePropertyDescriptor, defineProps } from '../props';
|
|
30
|
-
import { Node } from '../node';
|
|
31
30
|
import { Concrete } from '../types';
|
|
31
|
+
import { MarkBase } from './base';
|
|
32
32
|
import { API } from './types';
|
|
33
33
|
|
|
34
34
|
export interface Interval extends API<Concrete<IntervalGeometry>, Interval> {
|
|
@@ -148,25 +148,6 @@ export const props: NodePropertyDescriptor[] = [
|
|
|
148
148
|
{ name: 'scrollbar', type: 'object' },
|
|
149
149
|
];
|
|
150
150
|
|
|
151
|
-
export class MarkBase<
|
|
152
|
-
Value extends Record<string, any> = Record<string, any>,
|
|
153
|
-
ParentValue extends Record<string, any> = Record<string, any>,
|
|
154
|
-
ChildValue extends Record<string, any> = Record<string, any>,
|
|
155
|
-
> extends Node<Value, ParentValue, ChildValue> {
|
|
156
|
-
changeData(data) {
|
|
157
|
-
const chart = this.root();
|
|
158
|
-
if (!chart) return;
|
|
159
|
-
this.attr('data', data);
|
|
160
|
-
chart?.render();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
getMark() {}
|
|
164
|
-
|
|
165
|
-
getScale() {}
|
|
166
|
-
|
|
167
|
-
getGroup() {}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
151
|
@defineProps(props)
|
|
171
152
|
export class Interval extends MarkBase<IntervalGeometry> {
|
|
172
153
|
constructor() {
|
package/src/api/props.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { isObject, deepMix, get, isString, isArray } from '@antv/util';
|
|
2
|
-
|
|
3
|
-
type EventListener = (...args: any[]) => void;
|
|
4
|
-
|
|
5
1
|
export type NodePropertyDescriptor = {
|
|
6
2
|
type: 'object' | 'value' | 'array' | 'node' | 'container' | 'event';
|
|
7
3
|
name: string;
|
|
@@ -51,24 +47,6 @@ function defineContainerProp(Node, { name, ctor }: NodePropertyDescriptor) {
|
|
|
51
47
|
};
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
function defineEventProp(Node, { name, key = name }: NodePropertyDescriptor) {
|
|
55
|
-
Node.prototype[name] = function (
|
|
56
|
-
eventName: string,
|
|
57
|
-
listener: EventListener | EventListener[],
|
|
58
|
-
) {
|
|
59
|
-
const events = this.attr(key) || {};
|
|
60
|
-
if (arguments.length === 0) return events;
|
|
61
|
-
if (arguments.length === 1) return events[eventName];
|
|
62
|
-
const listeners = events[eventName];
|
|
63
|
-
if (listeners) {
|
|
64
|
-
isArray(listener) ? listeners.concat(listener) : listeners.push(listener);
|
|
65
|
-
} else {
|
|
66
|
-
events[eventName] = isArray(listener) ? listener : [listener];
|
|
67
|
-
}
|
|
68
|
-
return this.attr(key, events);
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
50
|
/**
|
|
73
51
|
* A decorator to define different type of attribute setter or
|
|
74
52
|
* getter for current node.
|
|
@@ -82,7 +60,6 @@ export function defineProps(descriptors: NodePropertyDescriptor[]) {
|
|
|
82
60
|
else if (type === 'object') defineObjectProp(Node, descriptor);
|
|
83
61
|
else if (type === 'node') defineNodeProp(Node, descriptor);
|
|
84
62
|
else if (type === 'container') defineContainerProp(Node, descriptor);
|
|
85
|
-
else if (type === 'event') defineEventProp(Node, descriptor);
|
|
86
63
|
}
|
|
87
64
|
return Node;
|
|
88
65
|
};
|
package/src/component/axis.ts
CHANGED
|
@@ -273,10 +273,17 @@ function inferOverrideStyle(
|
|
|
273
273
|
startPos: [x, y],
|
|
274
274
|
};
|
|
275
275
|
} else if (position === 'arcY') {
|
|
276
|
+
const [startAngle, endAngle] = angleOf(coordinate);
|
|
276
277
|
return {
|
|
277
278
|
startPos: [x, y],
|
|
278
279
|
endPos: [x + width, y + height],
|
|
279
280
|
gridCenter: [bbox.x, cy + bbox.y],
|
|
281
|
+
gridControlAngles: new Array(3)
|
|
282
|
+
.fill(0)
|
|
283
|
+
.map(
|
|
284
|
+
(d, i, arr) =>
|
|
285
|
+
90 + startAngle + ((endAngle - startAngle) / (arr.length - 1)) * i,
|
|
286
|
+
),
|
|
280
287
|
};
|
|
281
288
|
}
|
|
282
289
|
|
|
@@ -8,8 +8,21 @@ import { titleContent } from './utils';
|
|
|
8
8
|
export type LegendContinuousOptions = {
|
|
9
9
|
position?: GuideComponentPosition;
|
|
10
10
|
title?: string | string[];
|
|
11
|
+
[key: string]: any;
|
|
11
12
|
};
|
|
12
13
|
|
|
14
|
+
function inferContinuousLayout(options: LegendContinuousOptions) {
|
|
15
|
+
const { position = 'top', size, length = 200 } = options;
|
|
16
|
+
const layouts = {
|
|
17
|
+
left: ['vertical', size, length],
|
|
18
|
+
right: ['vertical', size, length],
|
|
19
|
+
top: ['horizontal', length, size],
|
|
20
|
+
bottom: ['horizontal', length, size],
|
|
21
|
+
};
|
|
22
|
+
const [orient, width, height] = layouts[position];
|
|
23
|
+
return { orient, width, height };
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
/**
|
|
14
27
|
* Guide Component for continuous color scale.
|
|
15
28
|
* @todo Custom style.
|
|
@@ -30,17 +43,14 @@ export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
|
|
|
30
43
|
{
|
|
31
44
|
x,
|
|
32
45
|
y,
|
|
33
|
-
width: 400,
|
|
34
|
-
height: 300,
|
|
35
46
|
data: [{ value: min }, { value: max }],
|
|
36
47
|
titleText: titleContent(title),
|
|
37
48
|
titleFontSize: 12,
|
|
38
|
-
ribbonLen: 120,
|
|
39
|
-
ribbonSize: 12,
|
|
40
49
|
ribbonColor: domain.map((d) => scale.map(d)),
|
|
41
50
|
showHandle: false,
|
|
42
51
|
showIndicator: false,
|
|
43
52
|
labelAlign: 'value',
|
|
53
|
+
...inferContinuousLayout(options),
|
|
44
54
|
},
|
|
45
55
|
rest,
|
|
46
56
|
),
|
|
@@ -51,5 +61,5 @@ export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
|
|
|
51
61
|
LegendContinuous.props = {
|
|
52
62
|
defaultPosition: 'top',
|
|
53
63
|
defaultOrder: 1,
|
|
54
|
-
defaultSize:
|
|
64
|
+
defaultSize: 50,
|
|
55
65
|
};
|
|
Binary file
|
package/src/interaction/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { ChartIndex } from './native/chartIndex';
|
|
|
10
10
|
export { Fisheye } from './native/fisheye';
|
|
11
11
|
export { Tooltip } from './native/tooltip';
|
|
12
12
|
export { LegendFilter } from './native/legendFilter';
|
|
13
|
+
export { LegendHighlight } from './native/legendHighlight';
|
|
13
14
|
export { BrushHighlight } from './native/brushHighlight';
|
|
14
15
|
export { BrushXHighlight } from './native/brushXHighlight';
|
|
15
16
|
export { BrushYHighlight } from './native/brushYHighlight';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
2
|
import { group } from 'd3-array';
|
|
3
|
+
import { isPolar, isTranspose } from '../../utils/coordinate';
|
|
3
4
|
import { subObject } from '../../utils/helper';
|
|
4
5
|
import {
|
|
5
6
|
createValueof,
|
|
@@ -8,6 +9,9 @@ import {
|
|
|
8
9
|
useState,
|
|
9
10
|
renderLink,
|
|
10
11
|
applyDefaultsHighlightedStyle,
|
|
12
|
+
renderBackground,
|
|
13
|
+
selectPlotArea,
|
|
14
|
+
offsetTransform,
|
|
11
15
|
} from './utils';
|
|
12
16
|
|
|
13
17
|
/**
|
|
@@ -20,6 +24,11 @@ export function elementHighlight(
|
|
|
20
24
|
datum, // given each element returns the datum of it
|
|
21
25
|
groupKey = (d) => d, // group elements by specified key
|
|
22
26
|
link = false, // draw link or not
|
|
27
|
+
background = false, // draw background or not
|
|
28
|
+
delay = 60, // delay to unhighlighted element
|
|
29
|
+
scale,
|
|
30
|
+
coordinate,
|
|
31
|
+
offset = 0,
|
|
23
32
|
...rest
|
|
24
33
|
}: Record<string, any>,
|
|
25
34
|
) {
|
|
@@ -27,50 +36,107 @@ export function elementHighlight(
|
|
|
27
36
|
const elementSet = new Set(elements);
|
|
28
37
|
const keyGroup = group(elements, groupKey);
|
|
29
38
|
const valueof = createValueof(elements, datum);
|
|
30
|
-
const [appendLink, removeLink] = renderLink(
|
|
39
|
+
const [appendLink, removeLink] = renderLink({
|
|
31
40
|
elements,
|
|
32
41
|
valueof,
|
|
42
|
+
link,
|
|
43
|
+
coordinate,
|
|
33
44
|
...subObject(rest, 'link'),
|
|
34
45
|
});
|
|
35
|
-
const
|
|
46
|
+
const [appendBackground, removeBackground, isBackground] = renderBackground({
|
|
47
|
+
scale,
|
|
48
|
+
coordinate,
|
|
49
|
+
background,
|
|
50
|
+
valueof,
|
|
51
|
+
...subObject(rest, 'background'),
|
|
52
|
+
});
|
|
53
|
+
const elementStyle = {
|
|
54
|
+
...(offset !== 0 && {
|
|
55
|
+
// Apply translate to mock slice out.
|
|
56
|
+
highlightedTransform: (_, i) => {
|
|
57
|
+
return offsetTransform(elements[i], offset, coordinate);
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
...rest,
|
|
61
|
+
};
|
|
62
|
+
const { setState, removeState, hasState } = useState(elementStyle, valueof);
|
|
36
63
|
|
|
64
|
+
let out; // Timer for delaying unhighlighted.
|
|
37
65
|
const pointerover = (event) => {
|
|
38
66
|
const { target: element } = event;
|
|
39
67
|
if (!elementSet.has(element)) return;
|
|
68
|
+
if (out) clearTimeout(out);
|
|
40
69
|
const k = groupKey(element);
|
|
41
70
|
const group = keyGroup.get(k);
|
|
42
71
|
const groupSet = new Set(group);
|
|
43
72
|
for (const e of elements) {
|
|
44
|
-
if (groupSet.has(e))
|
|
45
|
-
|
|
73
|
+
if (groupSet.has(e)) {
|
|
74
|
+
if (!hasState(e, 'highlighted')) setState(e, 'highlighted');
|
|
75
|
+
} else {
|
|
76
|
+
setState(e, 'unhighlighted');
|
|
77
|
+
removeLink(e);
|
|
78
|
+
}
|
|
79
|
+
if (e !== element) removeBackground(e);
|
|
80
|
+
}
|
|
81
|
+
appendBackground(element);
|
|
82
|
+
appendLink(group);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const delayUnhighlighted = () => {
|
|
86
|
+
if (out) clearTimeout(out);
|
|
87
|
+
out = setTimeout(() => {
|
|
88
|
+
unhighlighted();
|
|
89
|
+
out = null;
|
|
90
|
+
}, delay);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const unhighlighted = () => {
|
|
94
|
+
for (const e of elements) {
|
|
95
|
+
removeState(e, 'unhighlighted', 'highlighted');
|
|
96
|
+
removeBackground(e);
|
|
97
|
+
removeLink(e);
|
|
46
98
|
}
|
|
47
|
-
if (link) appendLink(group);
|
|
48
99
|
};
|
|
49
100
|
|
|
50
101
|
const pointerout = (event) => {
|
|
51
102
|
const { target: element } = event;
|
|
52
|
-
if (!
|
|
53
|
-
|
|
54
|
-
if (
|
|
103
|
+
if (background && !isBackground(element)) return;
|
|
104
|
+
if (!background && !elementSet.has(element)) return;
|
|
105
|
+
if (delay > 0) delayUnhighlighted();
|
|
106
|
+
else unhighlighted();
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const pointerleave = () => {
|
|
110
|
+
unhighlighted();
|
|
55
111
|
};
|
|
56
112
|
|
|
57
113
|
root.addEventListener('pointerover', pointerover);
|
|
58
114
|
root.addEventListener('pointerout', pointerout);
|
|
115
|
+
root.addEventListener('pointerleave', pointerleave);
|
|
59
116
|
|
|
60
117
|
return () => {
|
|
61
118
|
root.removeEventListener('pointerover', pointerover);
|
|
62
119
|
root.removeEventListener('pointerout', pointerout);
|
|
63
|
-
|
|
120
|
+
root.removeEventListener('pointerleave', pointerleave);
|
|
121
|
+
for (const e of elements) {
|
|
122
|
+
removeBackground(e);
|
|
123
|
+
removeLink(e);
|
|
124
|
+
}
|
|
64
125
|
};
|
|
65
126
|
}
|
|
66
127
|
|
|
67
|
-
export function ElementHighlight(
|
|
128
|
+
export function ElementHighlight({ delay, ...rest }) {
|
|
68
129
|
return (context) => {
|
|
69
130
|
const { container, view } = context;
|
|
70
|
-
|
|
71
|
-
|
|
131
|
+
const { scale, coordinate } = view;
|
|
132
|
+
const plotArea = selectPlotArea(container);
|
|
133
|
+
return elementHighlight(plotArea, {
|
|
134
|
+
...applyDefaultsHighlightedStyle(rest),
|
|
72
135
|
elements: selectG2Elements,
|
|
73
136
|
datum: createDatumof(view),
|
|
137
|
+
scale,
|
|
138
|
+
coordinate,
|
|
139
|
+
delay,
|
|
74
140
|
});
|
|
75
141
|
};
|
|
76
142
|
}
|
|
@@ -3,21 +3,26 @@ import {
|
|
|
3
3
|
createDatumof,
|
|
4
4
|
selectG2Elements,
|
|
5
5
|
createColorKey,
|
|
6
|
+
selectPlotArea,
|
|
6
7
|
} from './utils';
|
|
7
8
|
import { elementHighlight } from './elementHighlight';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @todo Bind abstract data or data index.
|
|
11
12
|
*/
|
|
12
|
-
export function ElementHighlightByColor(
|
|
13
|
+
export function ElementHighlightByColor({ delay, ...rest }) {
|
|
13
14
|
return (context) => {
|
|
14
15
|
const { container, view } = context;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const { scale, coordinate } = view;
|
|
17
|
+
const plotArea = selectPlotArea(container);
|
|
18
|
+
return elementHighlight(plotArea, {
|
|
19
|
+
...applyDefaultsHighlightedStyle(rest),
|
|
18
20
|
elements: selectG2Elements,
|
|
19
21
|
datum: createDatumof(view),
|
|
20
22
|
groupKey: createColorKey(view),
|
|
23
|
+
scale,
|
|
24
|
+
coordinate,
|
|
25
|
+
delay,
|
|
21
26
|
});
|
|
22
27
|
};
|
|
23
28
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
createDatumof,
|
|
4
4
|
selectG2Elements,
|
|
5
5
|
createXKey,
|
|
6
|
+
selectPlotArea,
|
|
6
7
|
} from './utils';
|
|
7
8
|
import { elementHighlight } from './elementHighlight';
|
|
8
9
|
|
|
@@ -10,16 +11,19 @@ import { elementHighlight } from './elementHighlight';
|
|
|
10
11
|
*
|
|
11
12
|
* @todo Bind abstract data or data index.
|
|
12
13
|
*/
|
|
13
|
-
export function ElementHighlightByX(
|
|
14
|
-
options = { selectedLineWidth: 1, selectedColor: 'black' },
|
|
15
|
-
) {
|
|
14
|
+
export function ElementHighlightByX({ delay, ...rest }) {
|
|
16
15
|
return (context) => {
|
|
17
16
|
const { container, view } = context;
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const { scale, coordinate } = view;
|
|
18
|
+
const plotArea = selectPlotArea(container);
|
|
19
|
+
return elementHighlight(plotArea, {
|
|
20
|
+
...applyDefaultsHighlightedStyle(rest),
|
|
20
21
|
elements: selectG2Elements,
|
|
21
22
|
datum: createDatumof(view),
|
|
22
23
|
groupKey: createXKey(view),
|
|
24
|
+
scale,
|
|
25
|
+
coordinate,
|
|
26
|
+
delay,
|
|
23
27
|
});
|
|
24
28
|
};
|
|
25
29
|
}
|