@antv/g6 5.0.0-beta.33 → 5.0.0-beta.34
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/g6.min.js +2 -2
- package/dist/lib/behaviors/brush-select.d.ts +2 -3
- package/dist/lib/behaviors/collapse-expand.d.ts +1 -2
- package/dist/lib/behaviors/create-edge.d.ts +1 -2
- package/dist/lib/behaviors/drag-element-force.d.ts +1 -2
- package/dist/lib/behaviors/drag-element.d.ts +2 -3
- package/dist/lib/behaviors/lasso-select.d.ts +2 -3
- package/dist/lib/constants/events/animation.d.ts +1 -4
- package/dist/lib/elements/nodes/base-node.d.ts +2 -3
- package/dist/lib/elements/nodes/donut.d.ts +45 -0
- package/dist/lib/elements/nodes/html.d.ts +27 -0
- package/dist/lib/elements/nodes/index.d.ts +4 -0
- package/dist/lib/exports.d.ts +4 -3
- package/dist/lib/plugins/hull/index.d.ts +1 -2
- package/dist/lib/runtime/data.d.ts +4 -4
- package/dist/lib/runtime/element.d.ts +3 -3
- package/dist/lib/runtime/graph.d.ts +2 -3
- package/dist/lib/runtime/viewport.d.ts +1 -2
- package/dist/lib/spec/data.d.ts +74 -1
- package/dist/lib/spec/element/combo.d.ts +17 -6
- package/dist/lib/spec/element/edge.d.ts +14 -2
- package/dist/lib/spec/element/node.d.ts +19 -3
- package/dist/lib/themes/base.d.ts +1 -0
- package/dist/lib/transforms/process-parallel-edges.d.ts +1 -2
- package/dist/lib/transforms/types.d.ts +1 -1
- package/dist/lib/types/callable.d.ts +2 -2
- package/dist/lib/types/data.d.ts +1 -1
- package/dist/lib/types/id.d.ts +1 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/style.d.ts +1 -3
- package/dist/lib/utils/animation.d.ts +1 -1
- package/dist/lib/utils/behaviors/brush.d.ts +1 -2
- package/dist/lib/utils/behaviors/lasso.d.ts +1 -2
- package/dist/lib/utils/behaviors/utils.d.ts +1 -1
- package/dist/lib/utils/edge.d.ts +1 -2
- package/dist/lib/utils/id.d.ts +2 -3
- package/dist/lib/utils/palette.d.ts +1 -2
- package/dist/lib/utils/relation.d.ts +1 -2
- package/esm/behaviors/brush-select.d.ts +2 -3
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/click-element.js.map +1 -1
- package/esm/behaviors/collapse-expand.d.ts +1 -2
- package/esm/behaviors/collapse-expand.js.map +1 -1
- package/esm/behaviors/create-edge.d.ts +1 -2
- package/esm/behaviors/create-edge.js.map +1 -1
- package/esm/behaviors/drag-element-force.d.ts +1 -2
- package/esm/behaviors/drag-element-force.js.map +1 -1
- package/esm/behaviors/drag-element.d.ts +2 -3
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/focus-element.js.map +1 -1
- package/esm/behaviors/hover-element.js.map +1 -1
- package/esm/behaviors/lasso-select.d.ts +2 -3
- package/esm/behaviors/lasso-select.js.map +1 -1
- package/esm/constants/events/animation.d.ts +1 -4
- package/esm/constants/events/animation.js +0 -4
- package/esm/constants/events/animation.js.map +1 -1
- package/esm/elements/nodes/base-node.d.ts +2 -3
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/nodes/donut.d.ts +45 -0
- package/esm/elements/nodes/donut.js +81 -0
- package/esm/elements/nodes/donut.js.map +1 -0
- package/esm/elements/nodes/html.d.ts +27 -0
- package/esm/elements/nodes/html.js +209 -0
- package/esm/elements/nodes/html.js.map +1 -0
- package/esm/elements/nodes/index.d.ts +4 -0
- package/esm/elements/nodes/index.js +2 -0
- package/esm/elements/nodes/index.js.map +1 -1
- package/esm/exports.d.ts +4 -3
- package/esm/exports.js +2 -1
- package/esm/exports.js.map +1 -1
- package/esm/plugins/hull/index.d.ts +1 -2
- package/esm/plugins/hull/index.js.map +1 -1
- package/esm/plugins/legend.js +3 -2
- package/esm/plugins/legend.js.map +1 -1
- package/esm/registry/build-in.js +5 -3
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/canvas.js +5 -2
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/data.d.ts +4 -4
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +3 -3
- package/esm/runtime/element.js +59 -42
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +2 -3
- package/esm/runtime/graph.js +11 -9
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.js +2 -2
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/viewport.d.ts +1 -2
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/spec/data.d.ts +74 -1
- package/esm/spec/element/combo.d.ts +17 -6
- package/esm/spec/element/edge.d.ts +14 -2
- package/esm/spec/element/node.d.ts +19 -3
- package/esm/themes/base.d.ts +1 -0
- package/esm/themes/base.js +2 -0
- package/esm/themes/base.js.map +1 -1
- package/esm/transforms/process-parallel-edges.d.ts +1 -2
- package/esm/transforms/process-parallel-edges.js +2 -4
- package/esm/transforms/process-parallel-edges.js.map +1 -1
- package/esm/transforms/types.d.ts +1 -1
- package/esm/transforms/update-related-edge.js.map +1 -1
- package/esm/types/callable.d.ts +2 -2
- package/esm/types/data.d.ts +1 -1
- package/esm/types/id.d.ts +1 -0
- package/esm/types/id.js +2 -0
- package/esm/types/id.js.map +1 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/style.d.ts +1 -3
- package/esm/utils/animation.d.ts +1 -1
- package/esm/utils/animation.js +1 -1
- package/esm/utils/animation.js.map +1 -1
- package/esm/utils/behaviors/brush.d.ts +1 -2
- package/esm/utils/behaviors/brush.js.map +1 -1
- package/esm/utils/behaviors/lasso.d.ts +1 -2
- package/esm/utils/behaviors/lasso.js.map +1 -1
- package/esm/utils/behaviors/utils.d.ts +1 -1
- package/esm/utils/change.js.map +1 -1
- package/esm/utils/edge.d.ts +1 -2
- package/esm/utils/edge.js.map +1 -1
- package/esm/utils/id.d.ts +2 -3
- package/esm/utils/id.js.map +1 -1
- package/esm/utils/palette.d.ts +1 -2
- package/esm/utils/palette.js.map +1 -1
- package/esm/utils/relation.d.ts +1 -2
- package/esm/utils/relation.js.map +1 -1
- package/esm/utils/style.js +3 -3
- package/esm/utils/style.js.map +1 -1
- package/lib/behaviors/brush-select.d.ts +2 -3
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/click-element.js.map +1 -1
- package/lib/behaviors/collapse-expand.d.ts +1 -2
- package/lib/behaviors/collapse-expand.js.map +1 -1
- package/lib/behaviors/create-edge.d.ts +1 -2
- package/lib/behaviors/create-edge.js.map +1 -1
- package/lib/behaviors/drag-element-force.d.ts +1 -2
- package/lib/behaviors/drag-element-force.js.map +1 -1
- package/lib/behaviors/drag-element.d.ts +2 -3
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/focus-element.js.map +1 -1
- package/lib/behaviors/hover-element.js.map +1 -1
- package/lib/behaviors/lasso-select.d.ts +2 -3
- package/lib/behaviors/lasso-select.js.map +1 -1
- package/lib/constants/events/animation.d.ts +1 -4
- package/lib/constants/events/animation.js +0 -4
- package/lib/constants/events/animation.js.map +1 -1
- package/lib/elements/nodes/base-node.d.ts +2 -3
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/nodes/donut.d.ts +45 -0
- package/lib/elements/nodes/donut.js +85 -0
- package/lib/elements/nodes/donut.js.map +1 -0
- package/lib/elements/nodes/html.d.ts +27 -0
- package/lib/elements/nodes/html.js +213 -0
- package/lib/elements/nodes/html.js.map +1 -0
- package/lib/elements/nodes/index.d.ts +4 -0
- package/lib/elements/nodes/index.js +5 -1
- package/lib/elements/nodes/index.js.map +1 -1
- package/lib/exports.d.ts +4 -3
- package/lib/exports.js +5 -1
- package/lib/exports.js.map +1 -1
- package/lib/plugins/hull/index.d.ts +1 -2
- package/lib/plugins/hull/index.js.map +1 -1
- package/lib/plugins/legend.js +3 -2
- package/lib/plugins/legend.js.map +1 -1
- package/lib/registry/build-in.js +4 -2
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/canvas.js +5 -2
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/data.d.ts +4 -4
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +3 -3
- package/lib/runtime/element.js +58 -41
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +2 -3
- package/lib/runtime/graph.js +10 -8
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.js +2 -2
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/viewport.d.ts +1 -2
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/spec/data.d.ts +74 -1
- package/lib/spec/element/combo.d.ts +17 -6
- package/lib/spec/element/edge.d.ts +14 -2
- package/lib/spec/element/node.d.ts +19 -3
- package/lib/themes/base.d.ts +1 -0
- package/lib/themes/base.js +2 -0
- package/lib/themes/base.js.map +1 -1
- package/lib/transforms/process-parallel-edges.d.ts +1 -2
- package/lib/transforms/process-parallel-edges.js +2 -4
- package/lib/transforms/process-parallel-edges.js.map +1 -1
- package/lib/transforms/types.d.ts +1 -1
- package/lib/transforms/update-related-edge.js.map +1 -1
- package/lib/types/callable.d.ts +2 -2
- package/lib/types/data.d.ts +1 -1
- package/lib/types/id.d.ts +1 -0
- package/lib/{spec/element/base.js → types/id.js} +1 -1
- package/lib/types/id.js.map +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/style.d.ts +1 -3
- package/lib/utils/animation.d.ts +1 -1
- package/lib/utils/animation.js +1 -1
- package/lib/utils/animation.js.map +1 -1
- package/lib/utils/behaviors/brush.d.ts +1 -2
- package/lib/utils/behaviors/brush.js.map +1 -1
- package/lib/utils/behaviors/lasso.d.ts +1 -2
- package/lib/utils/behaviors/lasso.js.map +1 -1
- package/lib/utils/behaviors/utils.d.ts +1 -1
- package/lib/utils/change.js.map +1 -1
- package/lib/utils/edge.d.ts +1 -2
- package/lib/utils/edge.js.map +1 -1
- package/lib/utils/id.d.ts +2 -3
- package/lib/utils/id.js.map +1 -1
- package/lib/utils/palette.d.ts +1 -2
- package/lib/utils/palette.js.map +1 -1
- package/lib/utils/relation.d.ts +1 -2
- package/lib/utils/relation.js.map +1 -1
- package/lib/utils/style.js +3 -3
- package/lib/utils/style.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/brush-select.ts +1 -2
- package/src/behaviors/click-element.ts +1 -2
- package/src/behaviors/collapse-expand.ts +1 -2
- package/src/behaviors/create-edge.ts +1 -2
- package/src/behaviors/drag-element-force.ts +1 -2
- package/src/behaviors/drag-element.ts +1 -2
- package/src/behaviors/focus-element.ts +1 -2
- package/src/behaviors/hover-element.ts +1 -2
- package/src/behaviors/lasso-select.ts +1 -2
- package/src/constants/events/animation.ts +0 -4
- package/src/elements/nodes/base-node.ts +3 -3
- package/src/elements/nodes/donut.ts +137 -0
- package/src/elements/nodes/html.ts +230 -0
- package/src/elements/nodes/index.ts +4 -0
- package/src/exports.ts +20 -1
- package/src/plugins/hull/index.ts +1 -2
- package/src/plugins/legend.ts +4 -4
- package/src/registry/build-in.ts +6 -2
- package/src/runtime/canvas.ts +5 -2
- package/src/runtime/data.ts +2 -1
- package/src/runtime/element.ts +62 -36
- package/src/runtime/graph.ts +13 -10
- package/src/runtime/layout.ts +4 -4
- package/src/runtime/viewport.ts +1 -2
- package/src/spec/data.ts +74 -1
- package/src/spec/element/combo.ts +17 -6
- package/src/spec/element/edge.ts +14 -2
- package/src/spec/element/node.ts +19 -3
- package/src/themes/base.ts +3 -0
- package/src/transforms/arrange-draw-order.ts +1 -1
- package/src/transforms/process-parallel-edges.ts +4 -6
- package/src/transforms/types.ts +1 -1
- package/src/transforms/update-related-edge.ts +1 -2
- package/src/types/callable.ts +2 -2
- package/src/types/data.ts +1 -1
- package/src/types/id.ts +1 -0
- package/src/types/index.ts +1 -0
- package/src/types/style.ts +1 -3
- package/src/utils/animation.ts +2 -2
- package/src/utils/behaviors/brush.ts +1 -2
- package/src/utils/behaviors/lasso.ts +1 -2
- package/src/utils/behaviors/utils.ts +1 -1
- package/src/utils/change.ts +1 -2
- package/src/utils/edge.ts +1 -1
- package/src/utils/id.ts +1 -2
- package/src/utils/palette.ts +1 -1
- package/src/utils/relation.ts +1 -2
- package/src/utils/style.ts +3 -3
- package/dist/lib/runtime/index.d.ts +0 -6
- package/dist/lib/spec/element/base.d.ts +0 -6
- package/esm/runtime/index.d.ts +0 -6
- package/esm/runtime/index.js +0 -7
- package/esm/runtime/index.js.map +0 -1
- package/esm/spec/element/base.d.ts +0 -6
- package/esm/spec/element/base.js +0 -2
- package/esm/spec/element/base.js.map +0 -1
- package/lib/runtime/index.d.ts +0 -6
- package/lib/runtime/index.js +0 -8
- package/lib/runtime/index.js.map +0 -1
- package/lib/spec/element/base.d.ts +0 -6
- package/lib/spec/element/base.js.map +0 -1
- package/src/runtime/index.ts +0 -7
- package/src/spec/element/base.ts +0 -6
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DisplayObjectConfig,
|
|
3
|
+
FederatedMouseEvent,
|
|
4
|
+
HTMLStyleProps as GHTMLStyleProps,
|
|
5
|
+
Group,
|
|
6
|
+
ICanvas,
|
|
7
|
+
IEventTarget,
|
|
8
|
+
} from '@antv/g';
|
|
9
|
+
import { FederatedPointerEvent, HTML as GHTML } from '@antv/g';
|
|
10
|
+
import { isNil, isUndefined, pick } from '@antv/util';
|
|
11
|
+
import { NodeEvent } from '../../constants';
|
|
12
|
+
import type { BaseNodeStyleProps } from './base-node';
|
|
13
|
+
import { BaseNode } from './base-node';
|
|
14
|
+
|
|
15
|
+
export type HTMLStyleProps = BaseNodeStyleProps<{
|
|
16
|
+
innerHTML: string | HTMLElement;
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @see https://github.com/antvis/G/blob/next/packages/g-lite/src/plugins/EventPlugin.ts
|
|
21
|
+
*/
|
|
22
|
+
export class HTML extends BaseNode<HTMLStyleProps> {
|
|
23
|
+
static defaultStyleProps: Partial<HTMLStyleProps> = {
|
|
24
|
+
size: [160, 80],
|
|
25
|
+
halo: false,
|
|
26
|
+
icon: false,
|
|
27
|
+
label: false,
|
|
28
|
+
pointerEvents: 'auto',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
constructor(options: DisplayObjectConfig<HTMLStyleProps>) {
|
|
32
|
+
super({ ...options, style: Object.assign({}, HTML.defaultStyleProps, options.style) });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private rootPointerEvent = new FederatedPointerEvent(null);
|
|
36
|
+
|
|
37
|
+
private get eventService() {
|
|
38
|
+
return this.attributes.context!.canvas.context.eventService;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private get events() {
|
|
42
|
+
return [
|
|
43
|
+
NodeEvent.CLICK,
|
|
44
|
+
NodeEvent.POINTER_DOWN,
|
|
45
|
+
NodeEvent.POINTER_MOVE,
|
|
46
|
+
NodeEvent.POINTER_UP,
|
|
47
|
+
NodeEvent.POINTER_OVER,
|
|
48
|
+
NodeEvent.POINTER_LEAVE,
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected getDomElement() {
|
|
53
|
+
return this.getKey<GHTML>().getDomElement();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected getKeyStyle(attributes: Required<HTMLStyleProps>): GHTMLStyleProps {
|
|
57
|
+
const style = pick(attributes, ['innerHTML', 'pointerEvents', 'cursor']) as unknown as HTMLStyleProps;
|
|
58
|
+
const [width, height] = this.getSize(attributes);
|
|
59
|
+
return { ...style, width, height };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected drawKeyShape(attributes: Required<HTMLStyleProps>, container: Group) {
|
|
63
|
+
return this.upsert('key', GHTML, this.getKeyStyle(attributes), container);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public connectedCallback() {
|
|
67
|
+
const element = this.getDomElement();
|
|
68
|
+
this.events.forEach((eventName) => {
|
|
69
|
+
// @ts-expect-error assert event is PointerEvent
|
|
70
|
+
element.addEventListener(eventName, this.forwardEvents);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public attributeChangedCallback(name: any, oldValue: any, newValue: any) {
|
|
75
|
+
if (name === 'zIndex' && oldValue !== newValue) {
|
|
76
|
+
this.getDomElement().style.zIndex = newValue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public onDestroy() {
|
|
81
|
+
const element = this.getDomElement();
|
|
82
|
+
this.events.forEach((eventName) => {
|
|
83
|
+
// @ts-expect-error assert event is PointerEvent
|
|
84
|
+
element.removeEventListener(eventName, this.forwardEvents);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private forwardEvents = (nativeEvent: PointerEvent) => {
|
|
89
|
+
const canvas = this.attributes.context!.canvas.main;
|
|
90
|
+
const iCanvas = canvas.context.renderingContext.root!.ownerDocument!.defaultView!;
|
|
91
|
+
|
|
92
|
+
const normalizedEvents = this.normalizeToPointerEvent(nativeEvent, iCanvas);
|
|
93
|
+
|
|
94
|
+
normalizedEvents.forEach((normalizedEvent) => {
|
|
95
|
+
const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvent, iCanvas, nativeEvent);
|
|
96
|
+
canvas.context.eventService.mapEvent(event);
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
private normalizeToPointerEvent(event: PointerEvent, canvas: ICanvas): PointerEvent[] {
|
|
101
|
+
const normalizedEvents = [];
|
|
102
|
+
if (canvas.isTouchEvent(event)) {
|
|
103
|
+
for (let i = 0; i < event.changedTouches.length; i++) {
|
|
104
|
+
const touch = event.changedTouches[i] as any;
|
|
105
|
+
|
|
106
|
+
// use changedTouches instead of touches since touchend has no touches
|
|
107
|
+
// @see https://stackoverflow.com/a/10079076
|
|
108
|
+
if (isUndefined(touch.button)) touch.button = 0;
|
|
109
|
+
if (isUndefined(touch.buttons)) touch.buttons = 1;
|
|
110
|
+
if (isUndefined(touch.isPrimary)) {
|
|
111
|
+
touch.isPrimary = event.touches.length === 1 && event.type === 'touchstart';
|
|
112
|
+
}
|
|
113
|
+
if (isUndefined(touch.width)) touch.width = touch.radiusX || 1;
|
|
114
|
+
if (isUndefined(touch.height)) touch.height = touch.radiusY || 1;
|
|
115
|
+
if (isUndefined(touch.tiltX)) touch.tiltX = 0;
|
|
116
|
+
if (isUndefined(touch.tiltY)) touch.tiltY = 0;
|
|
117
|
+
if (isUndefined(touch.pointerType)) touch.pointerType = 'touch';
|
|
118
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Touch/identifier
|
|
119
|
+
if (isUndefined(touch.pointerId)) touch.pointerId = touch.identifier || 0;
|
|
120
|
+
if (isUndefined(touch.pressure)) touch.pressure = touch.force || 0.5;
|
|
121
|
+
if (isUndefined(touch.twist)) touch.twist = 0;
|
|
122
|
+
if (isUndefined(touch.tangentialPressure)) touch.tangentialPressure = 0;
|
|
123
|
+
touch.isNormalized = true;
|
|
124
|
+
touch.type = event.type;
|
|
125
|
+
|
|
126
|
+
normalizedEvents.push(touch);
|
|
127
|
+
}
|
|
128
|
+
} else if (canvas.isMouseEvent(event)) {
|
|
129
|
+
const tempEvent = event as any;
|
|
130
|
+
if (isUndefined(tempEvent.isPrimary)) tempEvent.isPrimary = true;
|
|
131
|
+
if (isUndefined(tempEvent.width)) tempEvent.width = 1;
|
|
132
|
+
if (isUndefined(tempEvent.height)) tempEvent.height = 1;
|
|
133
|
+
if (isUndefined(tempEvent.tiltX)) tempEvent.tiltX = 0;
|
|
134
|
+
if (isUndefined(tempEvent.tiltY)) tempEvent.tiltY = 0;
|
|
135
|
+
if (isUndefined(tempEvent.pointerType)) tempEvent.pointerType = 'mouse';
|
|
136
|
+
if (isUndefined(tempEvent.pointerId)) tempEvent.pointerId = 1;
|
|
137
|
+
if (isUndefined(tempEvent.pressure)) tempEvent.pressure = 0.5;
|
|
138
|
+
if (isUndefined(tempEvent.twist)) tempEvent.twist = 0;
|
|
139
|
+
if (isUndefined(tempEvent.tangentialPressure)) tempEvent.tangentialPressure = 0;
|
|
140
|
+
tempEvent.isNormalized = true;
|
|
141
|
+
|
|
142
|
+
normalizedEvents.push(tempEvent);
|
|
143
|
+
} else {
|
|
144
|
+
normalizedEvents.push(event);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return normalizedEvents as PointerEvent[];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private transferMouseData(event: FederatedMouseEvent, nativeEvent: MouseEvent): void {
|
|
151
|
+
event.isTrusted = nativeEvent.isTrusted;
|
|
152
|
+
event.srcElement = nativeEvent.srcElement as IEventTarget;
|
|
153
|
+
event.timeStamp = performance.now();
|
|
154
|
+
event.type = nativeEvent.type;
|
|
155
|
+
|
|
156
|
+
event.altKey = nativeEvent.altKey;
|
|
157
|
+
event.metaKey = nativeEvent.metaKey;
|
|
158
|
+
event.shiftKey = nativeEvent.shiftKey;
|
|
159
|
+
event.ctrlKey = nativeEvent.ctrlKey;
|
|
160
|
+
event.button = nativeEvent.button;
|
|
161
|
+
event.buttons = nativeEvent.buttons;
|
|
162
|
+
event.client.x = nativeEvent.clientX;
|
|
163
|
+
event.client.y = nativeEvent.clientY;
|
|
164
|
+
event.movement.x = nativeEvent.movementX;
|
|
165
|
+
event.movement.y = nativeEvent.movementY;
|
|
166
|
+
event.page.x = nativeEvent.pageX;
|
|
167
|
+
event.page.y = nativeEvent.pageY;
|
|
168
|
+
event.screen.x = nativeEvent.screenX;
|
|
169
|
+
event.screen.y = nativeEvent.screenY;
|
|
170
|
+
event.relatedTarget = null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private bootstrapEvent(
|
|
174
|
+
event: FederatedPointerEvent,
|
|
175
|
+
normalizedEvent: PointerEvent,
|
|
176
|
+
view: ICanvas,
|
|
177
|
+
nativeEvent: PointerEvent | MouseEvent | TouchEvent,
|
|
178
|
+
): FederatedPointerEvent {
|
|
179
|
+
event.view = view;
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
event.originalEvent = null;
|
|
182
|
+
event.nativeEvent = nativeEvent;
|
|
183
|
+
|
|
184
|
+
event.pointerId = normalizedEvent.pointerId;
|
|
185
|
+
event.width = normalizedEvent.width;
|
|
186
|
+
event.height = normalizedEvent.height;
|
|
187
|
+
event.isPrimary = normalizedEvent.isPrimary;
|
|
188
|
+
event.pointerType = normalizedEvent.pointerType;
|
|
189
|
+
event.pressure = normalizedEvent.pressure;
|
|
190
|
+
event.tangentialPressure = normalizedEvent.tangentialPressure;
|
|
191
|
+
event.tiltX = normalizedEvent.tiltX;
|
|
192
|
+
event.tiltY = normalizedEvent.tiltY;
|
|
193
|
+
event.twist = normalizedEvent.twist;
|
|
194
|
+
this.transferMouseData(event, normalizedEvent);
|
|
195
|
+
|
|
196
|
+
const { x, y } = this.getViewportXY(normalizedEvent);
|
|
197
|
+
event.viewport.x = x;
|
|
198
|
+
event.viewport.y = y;
|
|
199
|
+
const { x: canvasX, y: canvasY } = this.attributes.context!.canvas.viewport2Canvas(event.viewport);
|
|
200
|
+
event.canvas.x = canvasX;
|
|
201
|
+
event.canvas.y = canvasY;
|
|
202
|
+
event.global.copyFrom(event.canvas);
|
|
203
|
+
event.offset.copyFrom(event.canvas);
|
|
204
|
+
|
|
205
|
+
event.isTrusted = nativeEvent.isTrusted;
|
|
206
|
+
if (event.type === 'pointerleave') {
|
|
207
|
+
event.type = 'pointerout';
|
|
208
|
+
}
|
|
209
|
+
return event;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private getViewportXY(nativeEvent: PointerEvent | WheelEvent) {
|
|
213
|
+
let x: number;
|
|
214
|
+
let y: number;
|
|
215
|
+
const { offsetX, offsetY, clientX, clientY } = nativeEvent;
|
|
216
|
+
if (
|
|
217
|
+
this.attributes.context?.canvas.main.context.config.supportsCSSTransform &&
|
|
218
|
+
!isNil(offsetX) &&
|
|
219
|
+
!isNil(offsetY)
|
|
220
|
+
) {
|
|
221
|
+
x = offsetX;
|
|
222
|
+
y = offsetY;
|
|
223
|
+
} else {
|
|
224
|
+
const point = this.eventService.client2Viewport({ x: clientX, y: clientY });
|
|
225
|
+
x = point.x;
|
|
226
|
+
y = point.y;
|
|
227
|
+
}
|
|
228
|
+
return { x, y };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { BaseNode } from './base-node';
|
|
2
2
|
export { Circle } from './circle';
|
|
3
3
|
export { Diamond } from './diamond';
|
|
4
|
+
export { Donut } from './donut';
|
|
4
5
|
export { Ellipse } from './ellipse';
|
|
5
6
|
export { Hexagon } from './hexagon';
|
|
7
|
+
export { HTML } from './html';
|
|
6
8
|
export { Image } from './image';
|
|
7
9
|
export { Rect } from './rect';
|
|
8
10
|
export { Star } from './star';
|
|
@@ -11,8 +13,10 @@ export { Triangle } from './triangle';
|
|
|
11
13
|
export type { BaseNodeStyleProps } from './base-node';
|
|
12
14
|
export type { CircleStyleProps } from './circle';
|
|
13
15
|
export type { DiamondStyleProps } from './diamond';
|
|
16
|
+
export type { DonutStyleProps } from './donut';
|
|
14
17
|
export type { EllipseStyleProps } from './ellipse';
|
|
15
18
|
export type { HexagonStyleProps } from './hexagon';
|
|
19
|
+
export type { HTMLStyleProps } from './html';
|
|
16
20
|
export type { ImageStyleProps } from './image';
|
|
17
21
|
export type { RectStyleProps } from './rect';
|
|
18
22
|
export type { StarStyleProps } from './star';
|
package/src/exports.ts
CHANGED
|
@@ -16,13 +16,26 @@ export {
|
|
|
16
16
|
} from './constants';
|
|
17
17
|
export { BaseCombo, CircleCombo, RectCombo } from './elements/combos';
|
|
18
18
|
export { BaseEdge, Cubic, CubicHorizontal, CubicVertical, Line, Polyline, Quadratic } from './elements/edges';
|
|
19
|
-
export {
|
|
19
|
+
export {
|
|
20
|
+
BaseNode,
|
|
21
|
+
Circle,
|
|
22
|
+
Diamond,
|
|
23
|
+
Donut,
|
|
24
|
+
Ellipse,
|
|
25
|
+
HTML,
|
|
26
|
+
Hexagon,
|
|
27
|
+
Image,
|
|
28
|
+
Rect,
|
|
29
|
+
Star,
|
|
30
|
+
Triangle,
|
|
31
|
+
} from './elements/nodes';
|
|
20
32
|
export { BaseShape } from './elements/shapes';
|
|
21
33
|
export { BasePlugin, CameraSetting, History } from './plugins';
|
|
22
34
|
export { getExtension, getExtensions, register } from './registry';
|
|
23
35
|
export { Graph } from './runtime/graph';
|
|
24
36
|
export { BaseTransform } from './transforms';
|
|
25
37
|
export { Shortcut } from './utils/shortcut';
|
|
38
|
+
export { parseSize } from './utils/size';
|
|
26
39
|
|
|
27
40
|
export type { BaseBehaviorOptions, DragCanvasOptions, ZoomCanvasOptions } from './behaviors';
|
|
28
41
|
export type { BaseComboStyleProps, CircleComboStyleProps, RectComboStyleProps } from './elements/combos';
|
|
@@ -40,6 +53,7 @@ export type {
|
|
|
40
53
|
CircleStyleProps,
|
|
41
54
|
DiamondStyleProps,
|
|
42
55
|
EllipseStyleProps,
|
|
56
|
+
HTMLStyleProps,
|
|
43
57
|
HexagonStyleProps,
|
|
44
58
|
ImageStyleProps,
|
|
45
59
|
RectStyleProps,
|
|
@@ -67,7 +81,11 @@ export type {
|
|
|
67
81
|
} from './spec';
|
|
68
82
|
export type { BaseTransformOptions } from './transforms';
|
|
69
83
|
export type {
|
|
84
|
+
Combo,
|
|
85
|
+
Edge,
|
|
86
|
+
Element,
|
|
70
87
|
IAnimateEvent,
|
|
88
|
+
ID,
|
|
71
89
|
IDragEvent,
|
|
72
90
|
IElementLifeCycleEvent,
|
|
73
91
|
IEvent,
|
|
@@ -76,6 +94,7 @@ export type {
|
|
|
76
94
|
IPointerEvent,
|
|
77
95
|
IViewportEvent,
|
|
78
96
|
IWheelEvent,
|
|
97
|
+
Node,
|
|
79
98
|
Point,
|
|
80
99
|
Vector2,
|
|
81
100
|
Vector3,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { ID } from '@antv/graphlib';
|
|
2
1
|
import { PathArray, isEqual, isFunction } from '@antv/util';
|
|
3
2
|
import hull from 'hull.js';
|
|
4
3
|
import { GraphEvent } from '../../constants';
|
|
5
4
|
import type { RuntimeContext } from '../../runtime/types';
|
|
6
|
-
import type { CallableValue, Point } from '../../types';
|
|
5
|
+
import type { CallableValue, ID, Point } from '../../types';
|
|
7
6
|
import type { ElementLifeCycleEvent } from '../../utils/event';
|
|
8
7
|
import { idOf } from '../../utils/id';
|
|
9
8
|
import { positionOf } from '../../utils/position';
|
package/src/plugins/legend.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { CategoryOptions } from '@antv/component';
|
|
2
2
|
import { Category, Layout, Selection } from '@antv/component';
|
|
3
|
-
import type { ID } from '@antv/graphlib';
|
|
4
3
|
import { get, isFunction } from '@antv/util';
|
|
5
4
|
import { GraphEvent } from '../constants';
|
|
6
5
|
import type { RuntimeContext } from '../runtime/types';
|
|
7
|
-
import type { ElementDatum, ElementType, State } from '../types';
|
|
6
|
+
import type { ElementDatum, ElementType, ID, State } from '../types';
|
|
8
7
|
import type { CardinalPlacement } from '../types/placement';
|
|
9
8
|
import type { BasePluginOptions } from './base-plugin';
|
|
10
9
|
import { BasePlugin } from './base-plugin';
|
|
@@ -198,8 +197,9 @@ export class Legend extends BasePlugin<LegendOptions> {
|
|
|
198
197
|
data.forEach((item) => {
|
|
199
198
|
const { id } = item;
|
|
200
199
|
const value = get(item, ['data', getField(item)]);
|
|
201
|
-
const
|
|
202
|
-
|
|
200
|
+
const marker = element?.getElementType(type, item) || 'circle';
|
|
201
|
+
const { color = '#1783ff' } = getElementStyle(type, item);
|
|
202
|
+
if (id && value && value.replace(/\s+/g, '')) {
|
|
203
203
|
this.setFieldMap(value, id, type);
|
|
204
204
|
if (!items[value]) {
|
|
205
205
|
items[value] = {
|
package/src/registry/build-in.ts
CHANGED
|
@@ -19,7 +19,9 @@ import {
|
|
|
19
19
|
CubicHorizontal,
|
|
20
20
|
CubicVertical,
|
|
21
21
|
Diamond,
|
|
22
|
+
Donut,
|
|
22
23
|
Ellipse,
|
|
24
|
+
HTML,
|
|
23
25
|
Hexagon,
|
|
24
26
|
Image,
|
|
25
27
|
Line,
|
|
@@ -113,13 +115,15 @@ export const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
|
|
|
113
115
|
},
|
|
114
116
|
node: {
|
|
115
117
|
circle: Circle,
|
|
118
|
+
diamond: Diamond,
|
|
116
119
|
ellipse: Ellipse,
|
|
120
|
+
hexagon: Hexagon,
|
|
121
|
+
html: HTML,
|
|
117
122
|
image: Image,
|
|
118
123
|
rect: Rect,
|
|
119
124
|
star: Star,
|
|
125
|
+
donut: Donut,
|
|
120
126
|
triangle: Triangle,
|
|
121
|
-
diamond: Diamond,
|
|
122
|
-
hexagon: Hexagon,
|
|
123
127
|
},
|
|
124
128
|
palette: {
|
|
125
129
|
spectral,
|
package/src/runtime/canvas.ts
CHANGED
|
@@ -153,6 +153,7 @@ export class Canvas {
|
|
|
153
153
|
|
|
154
154
|
public setBackground(background = this.config.background) {
|
|
155
155
|
const container = this.getContainer();
|
|
156
|
+
this.config.background = background;
|
|
156
157
|
if (container && background) {
|
|
157
158
|
container.style.background = background;
|
|
158
159
|
container.style.transition = 'background 0.5s';
|
|
@@ -248,7 +249,7 @@ export class Canvas {
|
|
|
248
249
|
renderer: new CanvasRenderer(),
|
|
249
250
|
devicePixelRatio,
|
|
250
251
|
container,
|
|
251
|
-
background: this.
|
|
252
|
+
background: this.config.background,
|
|
252
253
|
});
|
|
253
254
|
|
|
254
255
|
await offscreenCanvas.ready;
|
|
@@ -286,7 +287,9 @@ export class Canvas {
|
|
|
286
287
|
const contextService = offscreenCanvas.getContextService();
|
|
287
288
|
|
|
288
289
|
return new Promise<string>((resolve) => {
|
|
289
|
-
offscreenCanvas.on(CanvasEvent.
|
|
290
|
+
offscreenCanvas.on(CanvasEvent.RERENDER, async () => {
|
|
291
|
+
// 等待图片渲染完成 / Wait for the image to render
|
|
292
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
290
293
|
const url = await contextService.toDataURL(restOptions);
|
|
291
294
|
resolve(url);
|
|
292
295
|
});
|
package/src/runtime/data.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Graph as GraphLib
|
|
1
|
+
import { Graph as GraphLib } from '@antv/graphlib';
|
|
2
2
|
import { isEqual, isUndefined } from '@antv/util';
|
|
3
3
|
import { COMBO_KEY, ChangeType, TREE_KEY } from '../constants';
|
|
4
4
|
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
DataRemoved,
|
|
10
10
|
DataUpdated,
|
|
11
11
|
ElementDatum,
|
|
12
|
+
ID,
|
|
12
13
|
NodeLikeData,
|
|
13
14
|
PartialEdgeData,
|
|
14
15
|
PartialGraphData,
|
package/src/runtime/element.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
/* eslint-disable jsdoc/require-param */
|
|
3
3
|
import type { BaseStyleProps, DisplayObject, IAnimation } from '@antv/g';
|
|
4
4
|
import { Group } from '@antv/g';
|
|
5
|
-
import
|
|
6
|
-
import { groupBy, isEmpty } from '@antv/util';
|
|
5
|
+
import { groupBy, isEmpty, isString } from '@antv/util';
|
|
7
6
|
import { executor as animationExecutor } from '../animations';
|
|
8
7
|
import type { AnimationContext } from '../animations/types';
|
|
9
8
|
import { AnimationType, ChangeType, GraphEvent } from '../constants';
|
|
@@ -21,6 +20,7 @@ import type {
|
|
|
21
20
|
ElementData,
|
|
22
21
|
ElementDatum,
|
|
23
22
|
ElementType,
|
|
23
|
+
ID,
|
|
24
24
|
Node,
|
|
25
25
|
State,
|
|
26
26
|
StyleIterationContext,
|
|
@@ -64,7 +64,8 @@ export class ElementController {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
private emit(event: BaseEvent) {
|
|
67
|
+
private emit(event: BaseEvent, context: DrawContext) {
|
|
68
|
+
if (context.silence) return;
|
|
68
69
|
emit(this.context.graph, event);
|
|
69
70
|
}
|
|
70
71
|
|
|
@@ -75,6 +76,17 @@ export class ElementController {
|
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
public getElementType(elementType: ElementType, datum: ElementDatum) {
|
|
80
|
+
const { options } = this.context;
|
|
81
|
+
const userDefinedType = options[elementType]?.type || datum.type;
|
|
82
|
+
|
|
83
|
+
if (!userDefinedType) {
|
|
84
|
+
return { node: 'circle', edge: 'line', combo: 'circle' }[elementType];
|
|
85
|
+
}
|
|
86
|
+
if (isString(userDefinedType)) return userDefinedType;
|
|
87
|
+
return userDefinedType(datum as any);
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
private getTheme(elementType: ElementType) {
|
|
79
91
|
const { theme } = this.context.options;
|
|
80
92
|
if (!theme) return {};
|
|
@@ -125,7 +137,7 @@ export class ElementController {
|
|
|
125
137
|
*
|
|
126
138
|
* <en/> compute default style of single element
|
|
127
139
|
*/
|
|
128
|
-
private
|
|
140
|
+
private computeElementDefaultStyle(elementType: ElementType, context: StyleIterationContext) {
|
|
129
141
|
const { options } = this.context;
|
|
130
142
|
const defaultStyle = options[elementType]?.style || {};
|
|
131
143
|
this.defaultStyle[idOf(context.datum)] = computeElementCallbackStyle(defaultStyle as any, context);
|
|
@@ -135,8 +147,8 @@ export class ElementController {
|
|
|
135
147
|
this.forEachElementData((elementType, elementData) => {
|
|
136
148
|
elementData
|
|
137
149
|
.filter((datum) => ids === undefined || ids.includes(idOf(datum)))
|
|
138
|
-
.forEach((datum
|
|
139
|
-
this.
|
|
150
|
+
.forEach((datum) => {
|
|
151
|
+
this.computeElementDefaultStyle(elementType, { datum });
|
|
140
152
|
});
|
|
141
153
|
});
|
|
142
154
|
}
|
|
@@ -189,9 +201,9 @@ export class ElementController {
|
|
|
189
201
|
this.forEachElementData((elementType, elementData) => {
|
|
190
202
|
elementData
|
|
191
203
|
.filter((datum) => ids === undefined || ids.includes(idOf(datum)))
|
|
192
|
-
.forEach((datum
|
|
204
|
+
.forEach((datum) => {
|
|
193
205
|
const states = this.getElementState(idOf(datum));
|
|
194
|
-
this.computeElementStatesStyle(elementType, states, { datum
|
|
206
|
+
this.computeElementStatesStyle(elementType, states, { datum });
|
|
195
207
|
});
|
|
196
208
|
});
|
|
197
209
|
}
|
|
@@ -309,10 +321,6 @@ export class ElementController {
|
|
|
309
321
|
Object.assign(style, { childrenNode, childrenData });
|
|
310
322
|
}
|
|
311
323
|
|
|
312
|
-
if (!style.type) {
|
|
313
|
-
style.type = { node: 'circle', edge: 'line', combo: 'circle' }[elementType];
|
|
314
|
-
}
|
|
315
|
-
|
|
316
324
|
return style;
|
|
317
325
|
}
|
|
318
326
|
|
|
@@ -344,14 +352,22 @@ export class ElementController {
|
|
|
344
352
|
before: () =>
|
|
345
353
|
this.emit(
|
|
346
354
|
new GraphLifeCycleEvent(GraphEvent.BEFORE_DRAW, { dataChanges, animation: drawContext.animation }),
|
|
355
|
+
drawContext,
|
|
347
356
|
),
|
|
348
357
|
beforeAnimate: (animation) =>
|
|
349
|
-
this.emit(
|
|
358
|
+
this.emit(
|
|
359
|
+
new AnimateEvent(GraphEvent.BEFORE_ANIMATE, AnimationType.DRAW, animation, drawData),
|
|
360
|
+
drawContext,
|
|
361
|
+
),
|
|
350
362
|
afterAnimate: (animation) =>
|
|
351
|
-
this.emit(
|
|
363
|
+
this.emit(
|
|
364
|
+
new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationType.DRAW, animation, drawData),
|
|
365
|
+
drawContext,
|
|
366
|
+
),
|
|
352
367
|
after: () =>
|
|
353
368
|
this.emit(
|
|
354
369
|
new GraphLifeCycleEvent(GraphEvent.AFTER_DRAW, { dataChanges, animation: drawContext.animation }),
|
|
370
|
+
drawContext,
|
|
355
371
|
),
|
|
356
372
|
},
|
|
357
373
|
)?.finished;
|
|
@@ -415,17 +431,17 @@ export class ElementController {
|
|
|
415
431
|
}
|
|
416
432
|
|
|
417
433
|
private createElement(elementType: ElementType, datum: ElementDatum, context: DrawContext) {
|
|
418
|
-
const { animator } = context;
|
|
419
434
|
const id = idOf(datum);
|
|
420
435
|
const currentShape = this.getElement(id);
|
|
421
436
|
if (currentShape) return () => null;
|
|
422
|
-
const
|
|
437
|
+
const type = this.getElementType(elementType, datum);
|
|
438
|
+
const style = this.getElementComputedStyle(elementType, datum);
|
|
423
439
|
|
|
424
440
|
// get shape constructor
|
|
425
441
|
const Ctor = getExtension(elementType, type);
|
|
426
442
|
if (!Ctor) return () => null;
|
|
427
443
|
|
|
428
|
-
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum));
|
|
444
|
+
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum), context);
|
|
429
445
|
|
|
430
446
|
const shape = this.container[elementType].appendChild(
|
|
431
447
|
new Ctor({
|
|
@@ -440,10 +456,11 @@ export class ElementController {
|
|
|
440
456
|
this.shapeTypeMap[id] = type;
|
|
441
457
|
this.elementMap[id] = shape;
|
|
442
458
|
|
|
459
|
+
const { animation, animator } = context;
|
|
443
460
|
return () =>
|
|
444
|
-
withAnimationCallbacks(animator?.(id, shape, { ...shape.attributes, opacity: 0 })
|
|
461
|
+
withAnimationCallbacks(animation ? animator?.(id, shape, { ...shape.attributes, opacity: 0 }) : null, {
|
|
445
462
|
after: () => {
|
|
446
|
-
this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_CREATE, elementType, datum));
|
|
463
|
+
this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_CREATE, elementType, datum), context);
|
|
447
464
|
shape.onCreate();
|
|
448
465
|
},
|
|
449
466
|
});
|
|
@@ -495,20 +512,21 @@ export class ElementController {
|
|
|
495
512
|
const shape = this.getElement(id);
|
|
496
513
|
if (!shape) return () => null;
|
|
497
514
|
|
|
498
|
-
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_UPDATE, elementType, datum));
|
|
515
|
+
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_UPDATE, elementType, datum), context);
|
|
499
516
|
const afterUpdate = () => {
|
|
500
|
-
this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_UPDATE, elementType, datum));
|
|
517
|
+
this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_UPDATE, elementType, datum), context);
|
|
501
518
|
shape.onUpdate();
|
|
502
519
|
};
|
|
503
520
|
|
|
504
|
-
const
|
|
521
|
+
const type = this.getElementType(elementType, datum);
|
|
522
|
+
const style = this.getElementComputedStyle(elementType, datum);
|
|
505
523
|
|
|
506
524
|
// 如果类型不同,需要先销毁原有元素,再创建新元素
|
|
507
525
|
// If the type is different, you need to destroy the original element first, and then create a new element
|
|
508
526
|
if (this.shapeTypeMap[id] !== type) {
|
|
527
|
+
this.destroyElement(elementType, datum, { animation: false, silence: true })();
|
|
528
|
+
this.createElement(elementType, datum, { animation: false, silence: true })();
|
|
509
529
|
return () => {
|
|
510
|
-
this.destroyElement(elementType, datum, { ...context, animation: false })();
|
|
511
|
-
this.createElement(elementType, datum, { ...context, animation: false })();
|
|
512
530
|
afterUpdate();
|
|
513
531
|
return null;
|
|
514
532
|
};
|
|
@@ -527,7 +545,7 @@ export class ElementController {
|
|
|
527
545
|
updateStyle(shape, { visibility: 'visible' });
|
|
528
546
|
return () =>
|
|
529
547
|
withAnimationCallbacks(
|
|
530
|
-
animator?.(id, shape, { ...shape.attributes, opacity: 0 }, { opacity: originalOpacity })
|
|
548
|
+
animator?.(id, shape, { ...shape.attributes, opacity: 0 }, { opacity: originalOpacity }),
|
|
531
549
|
{ after: afterUpdate },
|
|
532
550
|
);
|
|
533
551
|
}
|
|
@@ -535,7 +553,7 @@ export class ElementController {
|
|
|
535
553
|
else if (style.visibility === 'hidden') {
|
|
536
554
|
return () =>
|
|
537
555
|
withAnimationCallbacks(
|
|
538
|
-
animator?.(id, shape, { ...shape.attributes, opacity: originalOpacity }, { opacity: 0 })
|
|
556
|
+
animator?.(id, shape, { ...shape.attributes, opacity: originalOpacity }, { opacity: 0 }),
|
|
539
557
|
{
|
|
540
558
|
after: () => {
|
|
541
559
|
updateStyle(shape, { visibility: this.latestElementVisibilityMap.get(shape) });
|
|
@@ -549,8 +567,19 @@ export class ElementController {
|
|
|
549
567
|
const originalStyle = { ...shape.attributes };
|
|
550
568
|
updateStyle(shape, style);
|
|
551
569
|
|
|
570
|
+
// 如果边的端点节点已经销毁,则更新端点节点
|
|
571
|
+
// If the endpoint node of the edge has been destroyed, update the endpoint node
|
|
572
|
+
if (elementType === 'edge') {
|
|
573
|
+
if (originalStyle.sourceNode.destroyed) {
|
|
574
|
+
originalStyle.sourceNode = style.sourceNode;
|
|
575
|
+
}
|
|
576
|
+
if (originalStyle.targetNode.destroyed) {
|
|
577
|
+
originalStyle.targetNode = style.targetNode;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
552
581
|
return () =>
|
|
553
|
-
withAnimationCallbacks(animator?.(id, shape, originalStyle)
|
|
582
|
+
withAnimationCallbacks(animator?.(id, shape, originalStyle), {
|
|
554
583
|
after: afterUpdate,
|
|
555
584
|
});
|
|
556
585
|
}
|
|
@@ -582,20 +611,17 @@ export class ElementController {
|
|
|
582
611
|
const element = this.elementMap[id];
|
|
583
612
|
if (!element) return () => null;
|
|
584
613
|
|
|
585
|
-
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_DESTROY, elementType, datum));
|
|
614
|
+
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_DESTROY, elementType, datum), context);
|
|
586
615
|
|
|
587
|
-
return () =>
|
|
588
|
-
|
|
589
|
-
withAnimationCallbacks(result, {
|
|
616
|
+
return () =>
|
|
617
|
+
withAnimationCallbacks(animator?.(id, element, { ...element.attributes }, { opacity: 0 }), {
|
|
590
618
|
after: () => {
|
|
591
619
|
this.clearElement(id);
|
|
592
620
|
element.destroy();
|
|
593
621
|
element.onDestroy();
|
|
594
|
-
this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_DESTROY, elementType, datum));
|
|
622
|
+
this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_DESTROY, elementType, datum), context);
|
|
595
623
|
},
|
|
596
624
|
});
|
|
597
|
-
return result;
|
|
598
|
-
};
|
|
599
625
|
}
|
|
600
626
|
|
|
601
627
|
private getDestroyTasks(data: ProcedureData, context: Omit<DrawContext, 'animator'>): AnimatableTask[] {
|
|
@@ -606,11 +632,11 @@ export class ElementController {
|
|
|
606
632
|
['node', nodes],
|
|
607
633
|
];
|
|
608
634
|
|
|
609
|
-
const { animation, stage } = context;
|
|
635
|
+
const { animation, stage = 'exit' } = context;
|
|
610
636
|
const tasks: AnimatableTask[] = [];
|
|
611
637
|
iteration.forEach(([elementType, elementData]) => {
|
|
612
638
|
if (elementData.size === 0) return [];
|
|
613
|
-
const animator = this.getAnimationExecutor(elementType, stage
|
|
639
|
+
const animator = this.getAnimationExecutor(elementType, stage, animation);
|
|
614
640
|
elementData.forEach((datum) =>
|
|
615
641
|
tasks.push(() => this.destroyElement(elementType, datum, { ...context, animator })),
|
|
616
642
|
);
|