@antv/g6 5.0.0-beta.39 → 5.0.0-beta.40
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/constants/events/canvas.d.ts +23 -18
- package/dist/lib/constants/events/combo.d.ts +109 -2
- package/dist/lib/constants/events/edge.d.ts +19 -14
- package/dist/lib/constants/events/node.d.ts +22 -17
- package/dist/lib/elements/nodes/base-node.d.ts +0 -5
- package/dist/lib/elements/nodes/circle.d.ts +2 -1
- package/dist/lib/elements/nodes/ellipse.d.ts +2 -1
- package/dist/lib/elements/nodes/html.d.ts +2 -2
- package/dist/lib/elements/shapes/badge.d.ts +1 -2
- package/dist/lib/elements/shapes/base-shape.d.ts +6 -6
- package/dist/lib/elements/shapes/icon.d.ts +0 -1
- package/dist/lib/elements/shapes/polygon.d.ts +2 -1
- package/dist/lib/runtime/graph.d.ts +18 -1
- package/dist/lib/utils/edge.d.ts +0 -6
- package/esm/behaviors/brush-select.js +3 -3
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/click-select.js +3 -3
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/create-edge.js +13 -13
- package/esm/behaviors/create-edge.js.map +1 -1
- package/esm/behaviors/drag-element.js +3 -3
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/scroll-canvas.js +4 -5
- package/esm/behaviors/scroll-canvas.js.map +1 -1
- package/esm/behaviors/zoom-canvas.js +3 -3
- package/esm/constants/events/canvas.d.ts +23 -18
- package/esm/constants/events/canvas.js +23 -18
- package/esm/constants/events/canvas.js.map +1 -1
- package/esm/constants/events/combo.d.ts +109 -2
- package/esm/constants/events/combo.js +110 -2
- package/esm/constants/events/combo.js.map +1 -1
- package/esm/constants/events/edge.d.ts +19 -14
- package/esm/constants/events/edge.js +19 -14
- package/esm/constants/events/edge.js.map +1 -1
- package/esm/constants/events/node.d.ts +22 -17
- package/esm/constants/events/node.js +22 -17
- package/esm/constants/events/node.js.map +1 -1
- package/esm/elements/combos/base-combo.js +1 -1
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/combos/circle.js +1 -1
- package/esm/elements/combos/circle.js.map +1 -1
- package/esm/elements/edges/base-edge.js +14 -12
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/nodes/base-node.d.ts +0 -5
- package/esm/elements/nodes/base-node.js +7 -14
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/nodes/circle.d.ts +2 -1
- package/esm/elements/nodes/circle.js +1 -1
- package/esm/elements/nodes/circle.js.map +1 -1
- package/esm/elements/nodes/donut.js +1 -1
- package/esm/elements/nodes/donut.js.map +1 -1
- package/esm/elements/nodes/ellipse.d.ts +2 -1
- package/esm/elements/nodes/ellipse.js +1 -1
- package/esm/elements/nodes/ellipse.js.map +1 -1
- package/esm/elements/nodes/html.d.ts +2 -2
- package/esm/elements/nodes/html.js +9 -9
- package/esm/elements/nodes/html.js.map +1 -1
- package/esm/elements/nodes/star.js +1 -1
- package/esm/elements/nodes/star.js.map +1 -1
- package/esm/elements/nodes/triangle.js +2 -2
- package/esm/elements/nodes/triangle.js.map +1 -1
- package/esm/elements/shapes/badge.d.ts +1 -2
- package/esm/elements/shapes/badge.js +0 -3
- package/esm/elements/shapes/badge.js.map +1 -1
- package/esm/elements/shapes/base-shape.d.ts +6 -6
- package/esm/elements/shapes/base-shape.js +9 -10
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/elements/shapes/icon.d.ts +0 -1
- package/esm/elements/shapes/icon.js +0 -3
- package/esm/elements/shapes/icon.js.map +1 -1
- package/esm/elements/shapes/polygon.d.ts +2 -1
- package/esm/runtime/behavior.js +30 -30
- package/esm/runtime/graph.d.ts +18 -1
- package/esm/runtime/graph.js +5 -0
- package/esm/runtime/graph.js.map +1 -1
- package/esm/utils/bbox.js +1 -1
- package/esm/utils/bbox.js.map +1 -1
- package/esm/utils/edge.d.ts +0 -6
- package/esm/utils/edge.js +0 -6
- package/esm/utils/edge.js.map +1 -1
- package/esm/utils/element.js +1 -1
- package/esm/utils/element.js.map +1 -1
- package/lib/behaviors/brush-select.js +2 -2
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/click-select.js +2 -2
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/create-edge.js +12 -12
- package/lib/behaviors/create-edge.js.map +1 -1
- package/lib/behaviors/drag-element.js +2 -2
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/scroll-canvas.js +3 -4
- package/lib/behaviors/scroll-canvas.js.map +1 -1
- package/lib/behaviors/zoom-canvas.js +2 -2
- package/lib/constants/events/canvas.d.ts +23 -18
- package/lib/constants/events/canvas.js +23 -18
- package/lib/constants/events/canvas.js.map +1 -1
- package/lib/constants/events/combo.d.ts +109 -2
- package/lib/constants/events/combo.js +110 -2
- package/lib/constants/events/combo.js.map +1 -1
- package/lib/constants/events/edge.d.ts +19 -14
- package/lib/constants/events/edge.js +19 -14
- package/lib/constants/events/edge.js.map +1 -1
- package/lib/constants/events/node.d.ts +22 -17
- package/lib/constants/events/node.js +22 -17
- package/lib/constants/events/node.js.map +1 -1
- package/lib/elements/combos/base-combo.js +1 -1
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/combos/circle.js +1 -1
- package/lib/elements/combos/circle.js.map +1 -1
- package/lib/elements/edges/base-edge.js +13 -11
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/base-node.d.ts +0 -5
- package/lib/elements/nodes/base-node.js +7 -14
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/nodes/circle.d.ts +2 -1
- package/lib/elements/nodes/circle.js +1 -1
- package/lib/elements/nodes/circle.js.map +1 -1
- package/lib/elements/nodes/donut.js +1 -1
- package/lib/elements/nodes/donut.js.map +1 -1
- package/lib/elements/nodes/ellipse.d.ts +2 -1
- package/lib/elements/nodes/ellipse.js +1 -1
- package/lib/elements/nodes/ellipse.js.map +1 -1
- package/lib/elements/nodes/html.d.ts +2 -2
- package/lib/elements/nodes/html.js +8 -8
- package/lib/elements/nodes/html.js.map +1 -1
- package/lib/elements/nodes/star.js +1 -1
- package/lib/elements/nodes/star.js.map +1 -1
- package/lib/elements/nodes/triangle.js +2 -2
- package/lib/elements/nodes/triangle.js.map +1 -1
- package/lib/elements/shapes/badge.d.ts +1 -2
- package/lib/elements/shapes/badge.js +0 -3
- package/lib/elements/shapes/badge.js.map +1 -1
- package/lib/elements/shapes/base-shape.d.ts +6 -6
- package/lib/elements/shapes/base-shape.js +9 -10
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/elements/shapes/icon.d.ts +0 -1
- package/lib/elements/shapes/icon.js +0 -3
- package/lib/elements/shapes/icon.js.map +1 -1
- package/lib/elements/shapes/polygon.d.ts +2 -1
- package/lib/runtime/behavior.js +29 -29
- package/lib/runtime/graph.d.ts +18 -1
- package/lib/runtime/graph.js +5 -0
- package/lib/runtime/graph.js.map +1 -1
- package/lib/utils/bbox.js +1 -1
- package/lib/utils/bbox.js.map +1 -1
- package/lib/utils/edge.d.ts +0 -6
- package/lib/utils/edge.js +0 -6
- package/lib/utils/edge.js.map +1 -1
- package/lib/utils/element.js +1 -1
- package/lib/utils/element.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/brush-select.ts +3 -3
- package/src/behaviors/click-select.ts +3 -3
- package/src/behaviors/create-edge.ts +13 -13
- package/src/behaviors/drag-element.ts +3 -3
- package/src/behaviors/scroll-canvas.ts +4 -5
- package/src/behaviors/zoom-canvas.ts +3 -3
- package/src/constants/events/canvas.ts +23 -18
- package/src/constants/events/combo.ts +109 -3
- package/src/constants/events/edge.ts +19 -14
- package/src/constants/events/node.ts +22 -17
- package/src/elements/combos/base-combo.ts +1 -1
- package/src/elements/combos/circle.ts +1 -1
- package/src/elements/edges/base-edge.ts +15 -20
- package/src/elements/nodes/base-node.ts +9 -17
- package/src/elements/nodes/circle.ts +1 -1
- package/src/elements/nodes/donut.ts +5 -4
- package/src/elements/nodes/ellipse.ts +1 -1
- package/src/elements/nodes/html.ts +10 -10
- package/src/elements/nodes/star.ts +1 -1
- package/src/elements/nodes/triangle.ts +2 -2
- package/src/elements/shapes/badge.ts +0 -4
- package/src/elements/shapes/base-shape.ts +14 -15
- package/src/elements/shapes/icon.ts +0 -4
- package/src/runtime/behavior.ts +30 -30
- package/src/runtime/graph.ts +22 -0
- package/src/utils/bbox.ts +1 -1
- package/src/utils/edge.ts +0 -6
- package/src/utils/element.ts +1 -1
|
@@ -3,12 +3,13 @@ import { isNumber, isString } from '@antv/util';
|
|
|
3
3
|
import { getPaletteColors } from '../../utils/palette';
|
|
4
4
|
import { subStyleProps } from '../../utils/prefix';
|
|
5
5
|
import { parseSize } from '../../utils/size';
|
|
6
|
+
import { mergeOptions } from '../../utils/style';
|
|
6
7
|
import { Circle } from './circle';
|
|
7
8
|
|
|
8
9
|
import type { BaseStyleProps, DisplayObjectConfig, Group } from '@antv/g';
|
|
10
|
+
import type { PathArray } from '@antv/util';
|
|
9
11
|
import type { CategoricalPalette } from '../../palettes/types';
|
|
10
12
|
import type { DonutRound, Prefix } from '../../types';
|
|
11
|
-
import { mergeOptions } from '../../utils/style';
|
|
12
13
|
import type { CircleStyleProps } from './circle';
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -109,7 +110,7 @@ export class Donut extends Circle {
|
|
|
109
110
|
|
|
110
111
|
const point = (x: number, y: number, r: number, angel: number) => [x + Math.sin(angel) * r, y - Math.cos(angel) * r];
|
|
111
112
|
|
|
112
|
-
const full = (x: number, y: number, R: number, r: number) => {
|
|
113
|
+
const full = (x: number, y: number, R: number, r: number): PathArray => {
|
|
113
114
|
if (r <= 0 || R <= r) {
|
|
114
115
|
return [['M', x - R, y], ['A', R, R, 0, 1, 1, x + R, y], ['A', R, R, 0, 1, 1, x - R, y], ['Z']];
|
|
115
116
|
}
|
|
@@ -125,7 +126,7 @@ const full = (x: number, y: number, R: number, r: number) => {
|
|
|
125
126
|
];
|
|
126
127
|
};
|
|
127
128
|
|
|
128
|
-
const part = (x: number, y: number, R: number, r: number, start: number, end: number) => {
|
|
129
|
+
const part = (x: number, y: number, R: number, r: number, start: number, end: number): PathArray => {
|
|
129
130
|
const [s, e] = [(start / 360) * 2 * Math.PI, (end / 360) * 2 * Math.PI];
|
|
130
131
|
const P = [point(x, y, r, s), point(x, y, R, s), point(x, y, R, e), point(x, y, r, e)];
|
|
131
132
|
const flag = e - s > Math.PI ? 1 : 0;
|
|
@@ -139,7 +140,7 @@ const part = (x: number, y: number, R: number, r: number, start: number, end: nu
|
|
|
139
140
|
];
|
|
140
141
|
};
|
|
141
142
|
|
|
142
|
-
const arc = (R = 0, r = 0, start: number, end: number) => {
|
|
143
|
+
const arc = (R = 0, r = 0, start: number, end: number): PathArray => {
|
|
143
144
|
const [x, y] = [0, 0];
|
|
144
145
|
if (Math.abs(start - end) % 360 < 0.000001) return full(x, y, R, r);
|
|
145
146
|
return part(x, y, R, r, start, end);
|
|
@@ -52,7 +52,7 @@ export class Ellipse extends BaseNode {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
public getIntersectPoint(point: Point): Point {
|
|
55
|
-
const keyShapeBounds = this.
|
|
55
|
+
const keyShapeBounds = this.getShape('key').getBounds();
|
|
56
56
|
return getEllipseIntersectPoint(point, keyShapeBounds);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
Rect,
|
|
11
11
|
} from '@antv/g';
|
|
12
12
|
import { isNil, isUndefined, pick } from '@antv/util';
|
|
13
|
-
import {
|
|
13
|
+
import { CommonEvent } from '../../constants';
|
|
14
14
|
import type { BaseNodeStyleProps } from './base-node';
|
|
15
15
|
import { BaseNode } from './base-node';
|
|
16
16
|
|
|
@@ -55,17 +55,17 @@ export class HTML extends BaseNode<HTMLStyleProps> {
|
|
|
55
55
|
|
|
56
56
|
private get events() {
|
|
57
57
|
return [
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
CommonEvent.CLICK,
|
|
59
|
+
CommonEvent.POINTER_DOWN,
|
|
60
|
+
CommonEvent.POINTER_MOVE,
|
|
61
|
+
CommonEvent.POINTER_UP,
|
|
62
|
+
CommonEvent.POINTER_OVER,
|
|
63
|
+
CommonEvent.POINTER_LEAVE,
|
|
64
64
|
];
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
protected getDomElement() {
|
|
68
|
-
return this.
|
|
68
|
+
return this.getShape<GHTML>('key').getDomElement();
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
protected getKeyStyle(attributes: Required<HTMLStyleProps>): GHTMLStyleProps {
|
|
@@ -76,8 +76,8 @@ export class HTML extends BaseNode<HTMLStyleProps> {
|
|
|
76
76
|
|
|
77
77
|
protected drawKeyShape(attributes: Required<HTMLStyleProps>, container: Group) {
|
|
78
78
|
const style = this.getKeyStyle(attributes);
|
|
79
|
-
const { width, height } = style;
|
|
80
|
-
const bounds = this.upsert('key-container', Rect, { width, height, opacity: 0 }, container)
|
|
79
|
+
const { width = 0, height = 0 } = style;
|
|
80
|
+
const bounds = this.upsert('key-container', Rect, { width, height, opacity: 0 }, container)!;
|
|
81
81
|
return this.upsert('key', GHTML, style, bounds);
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -49,7 +49,7 @@ export class Star extends Polygon<StarStyleProps> {
|
|
|
49
49
|
|
|
50
50
|
protected getPortXY(attributes: Required<StarStyleProps>, style: NodePortStyleProps): Point {
|
|
51
51
|
const { placement = 'top' } = style;
|
|
52
|
-
const bbox = this.
|
|
52
|
+
const bbox = this.getShape('key').getLocalBounds();
|
|
53
53
|
const ports = getStarPorts(this.getOuterR(attributes), this.getInnerR(attributes));
|
|
54
54
|
return getPortXYByPlacement(bbox, placement as StarPortPlacement, ports, false);
|
|
55
55
|
}
|
|
@@ -49,7 +49,7 @@ export class Triangle extends Polygon<TriangleStyleProps> {
|
|
|
49
49
|
protected getPortXY(attributes: Required<TriangleStyleProps>, style: NodePortStyleProps): Point {
|
|
50
50
|
const { direction } = attributes;
|
|
51
51
|
const { placement = 'top' } = style;
|
|
52
|
-
const bbox = this.
|
|
52
|
+
const bbox = this.getShape('key').getLocalBounds();
|
|
53
53
|
const [width, height] = this.getSize(attributes);
|
|
54
54
|
const ports = getTrianglePorts(width, height, direction);
|
|
55
55
|
return getPortXYByPlacement(bbox, placement as TrianglePortPlacement, ports, false);
|
|
@@ -63,7 +63,7 @@ export class Triangle extends Polygon<TriangleStyleProps> {
|
|
|
63
63
|
if (icon === false || isEmpty(iconText || iconSrc)) return false;
|
|
64
64
|
|
|
65
65
|
const iconStyle = subStyleProps<IconStyleProps>(this.getGraphicStyle(attributes), 'icon');
|
|
66
|
-
const bbox = this.
|
|
66
|
+
const bbox = this.getShape('key').getLocalBounds();
|
|
67
67
|
const [x, y] = getTriangleCenter(bbox, direction);
|
|
68
68
|
const size = getIncircleRadius(bbox, direction) * 2 * ICON_SIZE_RATIO;
|
|
69
69
|
|
|
@@ -28,8 +28,4 @@ export class Badge extends BaseShape<BadgeStyleProps> {
|
|
|
28
28
|
public render(attributes: ParsedBadgeStyleProps = this.parsedAttributes, container: Group = this) {
|
|
29
29
|
this.upsert('label', Label, this.getBadgeStyle(attributes), container);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
connectedCallback() {
|
|
33
|
-
this.upsert('label', Label, this.getBadgeStyle(this.parsedAttributes), this);
|
|
34
|
-
}
|
|
35
31
|
}
|
|
@@ -39,35 +39,34 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
39
39
|
* <zh> 创建、更新或删除图形
|
|
40
40
|
*
|
|
41
41
|
* <en> create, update or remove shape
|
|
42
|
-
* @param
|
|
42
|
+
* @param className - <zh> 图形名称 | <en> shape name
|
|
43
43
|
* @param Ctor - <zh> 图形类型 | <en> shape type
|
|
44
44
|
* @param style - <zh> 图形样式 | <en> shape style
|
|
45
45
|
* @param container - <zh> 容器 | <en> container
|
|
46
46
|
* @returns <zh> 图形实例 | <en> shape instance
|
|
47
47
|
*/
|
|
48
|
-
protected upsert(
|
|
49
|
-
|
|
50
|
-
Ctor: { new (...args: any[]):
|
|
51
|
-
style:
|
|
48
|
+
protected upsert<T extends DisplayObject>(
|
|
49
|
+
className: string,
|
|
50
|
+
Ctor: { new (...args: any[]): T },
|
|
51
|
+
style: T['attributes'] | false,
|
|
52
52
|
container: DisplayObject,
|
|
53
|
-
):
|
|
54
|
-
const target = this.shapeMap[
|
|
53
|
+
): T | undefined {
|
|
54
|
+
const target = this.shapeMap[className] as T | undefined;
|
|
55
55
|
// remove
|
|
56
56
|
// 如果 style 为 false,则删除图形 / remove shape if style is false
|
|
57
57
|
if (style === false) {
|
|
58
58
|
if (target) {
|
|
59
59
|
container.removeChild(target);
|
|
60
|
-
delete this.shapeMap[
|
|
60
|
+
delete this.shapeMap[className];
|
|
61
61
|
}
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// create
|
|
66
66
|
if (!target) {
|
|
67
|
-
const instance = new Ctor({ style });
|
|
68
|
-
instance.id = key;
|
|
67
|
+
const instance = new Ctor({ className, style });
|
|
69
68
|
container.appendChild(instance);
|
|
70
|
-
this.shapeMap[
|
|
69
|
+
this.shapeMap[className] = instance;
|
|
71
70
|
return instance;
|
|
72
71
|
}
|
|
73
72
|
|
|
@@ -104,8 +103,8 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
104
103
|
*/
|
|
105
104
|
public getGraphicStyle<T extends Record<string, any>>(
|
|
106
105
|
attributes: T,
|
|
107
|
-
): Omit<T, 'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'context' | 'zIndex'> {
|
|
108
|
-
const { x, y, z, className, transform, transformOrigin, context, zIndex, ...style } = attributes;
|
|
106
|
+
): Omit<T, 'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'context' | 'zIndex'> {
|
|
107
|
+
const { x, y, z, class: cls, className, transform, transformOrigin, context, zIndex, ...style } = attributes;
|
|
109
108
|
return style;
|
|
110
109
|
}
|
|
111
110
|
|
|
@@ -183,8 +182,8 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
183
182
|
return createAnimationsProxy(animationMap);
|
|
184
183
|
}
|
|
185
184
|
|
|
186
|
-
public getShape(
|
|
187
|
-
return this.shapeMap[
|
|
185
|
+
public getShape<T extends DisplayObject>(name: string): T {
|
|
186
|
+
return this.shapeMap[name] as T;
|
|
188
187
|
}
|
|
189
188
|
|
|
190
189
|
private setVisibility() {
|
|
@@ -36,8 +36,4 @@ export class Icon extends BaseShape<IconStyleProps> {
|
|
|
36
36
|
public render(attributes = this.attributes, container: Group = this): void {
|
|
37
37
|
this.upsert('icon', (this.isGImage() ? GImage : GText) as any, this.getIconStyle(attributes), container);
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
connectedCallback() {
|
|
41
|
-
this.upsert('icon', (this.isGImage() ? GImage : GText) as any, this.getIconStyle(this.attributes), this);
|
|
42
|
-
}
|
|
43
39
|
}
|
package/src/runtime/behavior.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DisplayObject, FederatedPointerEvent, FederatedWheelEvent } from '@antv/g';
|
|
2
2
|
import type { BaseBehavior } from '../behaviors/base-behavior';
|
|
3
|
-
import {
|
|
3
|
+
import { CommonEvent, ContainerEvent } from '../constants';
|
|
4
4
|
import { ExtensionController } from '../registry/extension';
|
|
5
5
|
import type { BehaviorOptions, CustomBehaviorOption } from '../spec/behavior';
|
|
6
6
|
import type { Target } from '../types';
|
|
@@ -38,24 +38,24 @@ export class BehaviorController extends ExtensionController<BaseBehavior<CustomB
|
|
|
38
38
|
const canvas = this.context.canvas.document;
|
|
39
39
|
if (canvas) {
|
|
40
40
|
[
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
CommonEvent.CLICK,
|
|
42
|
+
CommonEvent.DBLCLICK,
|
|
43
|
+
CommonEvent.POINTER_OVER,
|
|
44
|
+
CommonEvent.POINTER_LEAVE,
|
|
45
|
+
CommonEvent.POINTER_ENTER,
|
|
46
|
+
CommonEvent.POINTER_MOVE,
|
|
47
|
+
CommonEvent.POINTER_OUT,
|
|
48
|
+
CommonEvent.POINTER_DOWN,
|
|
49
|
+
CommonEvent.POINTER_UP,
|
|
50
|
+
CommonEvent.CONTEXT_MENU,
|
|
51
|
+
CommonEvent.DRAG_START,
|
|
52
|
+
CommonEvent.DRAG,
|
|
53
|
+
CommonEvent.DRAG_END,
|
|
54
|
+
CommonEvent.DRAG_ENTER,
|
|
55
|
+
CommonEvent.DRAG_OVER,
|
|
56
|
+
CommonEvent.DRAG_LEAVE,
|
|
57
|
+
CommonEvent.DROP,
|
|
58
|
+
CommonEvent.WHEEL,
|
|
59
59
|
].forEach((name) => {
|
|
60
60
|
canvas.addEventListener(name, this.forwardCanvasEvents);
|
|
61
61
|
});
|
|
@@ -71,42 +71,42 @@ export class BehaviorController extends ExtensionController<BaseBehavior<CustomB
|
|
|
71
71
|
const { type, detail, button } = event;
|
|
72
72
|
const stdEvent = { ...event, target: targetElement, targetType, originalTarget };
|
|
73
73
|
|
|
74
|
-
if (type ===
|
|
74
|
+
if (type === CommonEvent.POINTER_MOVE) {
|
|
75
75
|
if (this.currentTarget !== targetElement) {
|
|
76
76
|
if (this.currentTarget) {
|
|
77
|
-
graph.emit(`${targetType}:${
|
|
77
|
+
graph.emit(`${targetType}:${CommonEvent.POINTER_LEAVE}`, { ...stdEvent, target: this.currentTarget });
|
|
78
78
|
}
|
|
79
79
|
if (targetElement) {
|
|
80
|
-
graph.emit(`${targetType}:${
|
|
80
|
+
graph.emit(`${targetType}:${CommonEvent.POINTER_ENTER}`, stdEvent);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
this.currentTarget = targetElement;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// 非右键点击事件 / Click event except right click
|
|
87
|
-
if (!(type ===
|
|
87
|
+
if (!(type === CommonEvent.CLICK && button === 2)) {
|
|
88
88
|
graph.emit(`${targetType}:${type}`, stdEvent);
|
|
89
89
|
graph.emit(type, stdEvent);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
// 双击事件 / Double click event
|
|
93
|
-
if (type ===
|
|
94
|
-
graph.emit(`${targetType}:${
|
|
95
|
-
graph.emit(
|
|
93
|
+
if (type === CommonEvent.CLICK && detail === 2) {
|
|
94
|
+
graph.emit(`${targetType}:${CommonEvent.DBLCLICK}`, stdEvent);
|
|
95
|
+
graph.emit(CommonEvent.DBLCLICK, stdEvent);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// 右键菜单 / Contextmenu
|
|
99
|
-
if (type ===
|
|
99
|
+
if (type === CommonEvent.POINTER_DOWN && button === 2) {
|
|
100
100
|
const contextMenuEvent = {
|
|
101
101
|
...stdEvent,
|
|
102
102
|
preventDefault: () => {
|
|
103
|
-
canvas.getContainer()?.addEventListener(
|
|
103
|
+
canvas.getContainer()?.addEventListener(CommonEvent.CONTEXT_MENU, (e) => e.preventDefault(), {
|
|
104
104
|
once: true,
|
|
105
105
|
});
|
|
106
106
|
},
|
|
107
107
|
};
|
|
108
|
-
graph.emit(`${targetType}:${
|
|
109
|
-
graph.emit(
|
|
108
|
+
graph.emit(`${targetType}:${CommonEvent.CONTEXT_MENU}`, contextMenuEvent);
|
|
109
|
+
graph.emit(CommonEvent.CONTEXT_MENU, contextMenuEvent);
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
|
package/src/runtime/graph.ts
CHANGED
|
@@ -442,6 +442,28 @@ export class Graph extends EventEmitter {
|
|
|
442
442
|
return this.context.model.getData();
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
+
/**
|
|
446
|
+
* <zh/> 获取单个元素数据
|
|
447
|
+
*
|
|
448
|
+
* <en/> Get element data by ID
|
|
449
|
+
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
450
|
+
* @returns <zh/> 元素数据 | <en/> element data
|
|
451
|
+
* @apiCategory data
|
|
452
|
+
*/
|
|
453
|
+
public getElementData(id: ID): ElementDatum;
|
|
454
|
+
/**
|
|
455
|
+
* <zh/> 批量获取多个元素数据
|
|
456
|
+
*
|
|
457
|
+
* <en/> Get multiple element data in batch
|
|
458
|
+
* @param ids - <zh/> 元素 ID 数组 | <en/> element ID array
|
|
459
|
+
* @apiCategory data
|
|
460
|
+
*/
|
|
461
|
+
public getElementData(ids: ID[]): ElementDatum[];
|
|
462
|
+
public getElementData(ids: ID | ID[]): ElementDatum | ElementDatum[] {
|
|
463
|
+
if (Array.isArray(ids)) return ids.map((id) => this.context.model.getElementDataById(id));
|
|
464
|
+
return this.context.model.getElementDataById(ids);
|
|
465
|
+
}
|
|
466
|
+
|
|
445
467
|
/**
|
|
446
468
|
* <zh/> 获取所有节点数据
|
|
447
469
|
*
|
package/src/utils/bbox.ts
CHANGED
|
@@ -45,7 +45,7 @@ export function getBBoxSize(bbox: AABB): [number, number] {
|
|
|
45
45
|
* @returns <zh/> 包围盒 | <en/> bounding box
|
|
46
46
|
*/
|
|
47
47
|
export function getNodeBBox(node: Point | Node, padding?: Padding): AABB {
|
|
48
|
-
const bbox = isPoint(node) ? getPointBBox(node) : node.
|
|
48
|
+
const bbox = isPoint(node) ? getPointBBox(node) : node.getShape('key').getBounds();
|
|
49
49
|
return padding ? getExpandedBBox(bbox, padding) : bbox;
|
|
50
50
|
}
|
|
51
51
|
|
package/src/utils/edge.ts
CHANGED
|
@@ -289,8 +289,6 @@ export const getRadians = (bbox: AABB): Record<LoopPlacement, [number, number]>
|
|
|
289
289
|
* @param clockwise - <zh/> 是否顺时针 | <en/> Whether to draw the loop clockwise
|
|
290
290
|
* @param sourcePort - <zh/> 起点连接桩 | <en/> Source port
|
|
291
291
|
* @param targetPort - <zh/> 终点连接桩 | <en/> Target port
|
|
292
|
-
* @param rawSourcePoint - <zh/> 起点 | <en/> Source point
|
|
293
|
-
* @param rawTargetPoint - <zh/> 终点 | <en/> Target point
|
|
294
292
|
* @returns <zh/> 起点和终点 | <en/> Start and end points
|
|
295
293
|
*/
|
|
296
294
|
export function getLoopEndpoints(
|
|
@@ -336,8 +334,6 @@ export function getLoopEndpoints(
|
|
|
336
334
|
* @param dist - <zh/> 从节点 keyShape 边缘到自环顶部的距离 | <en/> The distance from the edge of the node keyShape to the top of the self-loop
|
|
337
335
|
* @param sourcePortKey - <zh/> 起点连接桩 key | <en/> Source port key
|
|
338
336
|
* @param targetPortKey - <zh/> 终点连接桩 key | <en/> Target port key
|
|
339
|
-
* @param rawSourcePoint - <zh/> 起点 | <en/> Source point
|
|
340
|
-
* @param rawTargetPoint - <zh/> 终点 | <en/> Target point
|
|
341
337
|
* @returns <zh/> 返回绘制环形边的路径 | <en/> Returns the path of the loop edge
|
|
342
338
|
*/
|
|
343
339
|
export function getCubicLoopPath(
|
|
@@ -409,8 +405,6 @@ export function getCubicLoopControlPoints(
|
|
|
409
405
|
* @param dist - <zh/> 从节点 keyShape 边缘到自环顶部的距离 | <en/> The distance from the edge of the node keyShape to the top of the self-loop
|
|
410
406
|
* @param sourcePortKey - <zh/> 起点连接桩 key | <en/> Source port key
|
|
411
407
|
* @param targetPortKey - <zh/> 终点连接桩 key | <en/> Target port key
|
|
412
|
-
* @param rawSourcePoint - <zh/> 起点 | <en/> Source point
|
|
413
|
-
* @param rawTargetPoint - <zh/> 终点 | <en/> Target point
|
|
414
408
|
* @returns <zh/> 返回绘制环形折线边的路径 | <en/> Returns the path of the loop polyline edge
|
|
415
409
|
*/
|
|
416
410
|
export function getPolylineLoopPath(
|
package/src/utils/element.ts
CHANGED
|
@@ -122,7 +122,7 @@ export function getAllPorts(node: Node): Record<string, Port> {
|
|
|
122
122
|
portsStyle.forEach((portStyle: NodePortStyleProps, i: number) => {
|
|
123
123
|
const { key, placement } = portStyle;
|
|
124
124
|
if (isSimplePort(portStyle)) {
|
|
125
|
-
ports[key || i] ||= getXYByPlacement(node.
|
|
125
|
+
ports[key || i] ||= getXYByPlacement(node.getShape('key').getBounds(), placement);
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
return ports;
|