@antv/g6 5.0.40-alpha.0 → 5.0.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 +29 -29
- package/dist/lib/behaviors/drag-element-force.d.ts +10 -0
- package/dist/lib/elements/combos/base-combo.d.ts +1 -2
- package/dist/lib/elements/effect.d.ts +1 -0
- package/dist/lib/utils/style.d.ts +3 -3
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/drag-element-force.d.ts +10 -0
- package/esm/behaviors/drag-element-force.js +2 -0
- package/esm/behaviors/drag-element-force.js.map +1 -1
- package/esm/elements/combos/base-combo.d.ts +1 -2
- package/esm/elements/combos/base-combo.js +17 -24
- 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/combos/rect.js +2 -2
- package/esm/elements/combos/rect.js.map +1 -1
- package/esm/elements/edges/base-edge.js +50 -71
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/effect.d.ts +1 -0
- package/esm/elements/effect.js +2 -0
- package/esm/elements/effect.js.map +1 -1
- package/esm/elements/nodes/base-node.js +43 -80
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/nodes/donut.js +0 -1
- package/esm/elements/nodes/donut.js.map +1 -1
- package/esm/elements/nodes/image.js +7 -9
- package/esm/elements/nodes/image.js.map +1 -1
- package/esm/plugins/utils/canvas.js +4 -3
- package/esm/plugins/utils/canvas.js.map +1 -1
- package/esm/runtime/element.js +3 -6
- package/esm/runtime/element.js.map +1 -1
- package/esm/themes/base.js +65 -69
- package/esm/themes/base.js.map +1 -1
- package/esm/utils/style.d.ts +3 -3
- package/esm/utils/style.js +11 -7
- package/esm/utils/style.js.map +1 -1
- package/esm/utils/transform.js +1 -1
- package/esm/utils/transform.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/esm/version.js.map +1 -1
- package/lib/behaviors/drag-element-force.d.ts +10 -0
- package/lib/behaviors/drag-element-force.js +2 -0
- package/lib/behaviors/drag-element-force.js.map +1 -1
- package/lib/elements/combos/base-combo.d.ts +1 -2
- package/lib/elements/combos/base-combo.js +17 -24
- 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/combos/rect.js +2 -2
- package/lib/elements/combos/rect.js.map +1 -1
- package/lib/elements/edges/base-edge.js +50 -71
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/effect.d.ts +1 -0
- package/lib/elements/effect.js +2 -0
- package/lib/elements/effect.js.map +1 -1
- package/lib/elements/nodes/base-node.js +43 -80
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/nodes/donut.js +0 -1
- package/lib/elements/nodes/donut.js.map +1 -1
- package/lib/elements/nodes/image.js +7 -9
- package/lib/elements/nodes/image.js.map +1 -1
- package/lib/plugins/utils/canvas.js +4 -3
- package/lib/plugins/utils/canvas.js.map +1 -1
- package/lib/runtime/element.js +3 -6
- package/lib/runtime/element.js.map +1 -1
- package/lib/themes/base.js +65 -69
- package/lib/themes/base.js.map +1 -1
- package/lib/utils/style.d.ts +3 -3
- package/lib/utils/style.js +11 -7
- package/lib/utils/style.js.map +1 -1
- package/lib/utils/transform.js +1 -1
- package/lib/utils/transform.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +2 -3
- package/src/behaviors/drag-element-force.ts +14 -1
- package/src/elements/combos/base-combo.ts +18 -26
- package/src/elements/combos/circle.ts +3 -2
- package/src/elements/combos/rect.ts +3 -2
- package/src/elements/edges/base-edge.ts +53 -84
- package/src/elements/effect.ts +2 -0
- package/src/elements/nodes/base-node.ts +48 -104
- package/src/elements/nodes/donut.ts +0 -1
- package/src/elements/nodes/image.ts +7 -11
- package/src/plugins/utils/canvas.ts +14 -11
- package/src/runtime/element.ts +3 -11
- package/src/themes/base.ts +65 -69
- package/src/utils/style.ts +14 -7
- package/src/utils/transform.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -34,10 +34,11 @@ export class CircleCombo extends BaseCombo<CircleComboStyleProps> {
|
|
|
34
34
|
const keyStyle = super.getKeyStyle(attributes);
|
|
35
35
|
|
|
36
36
|
const [width] = this.getKeySize(attributes);
|
|
37
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
...keyStyle,
|
|
38
39
|
...(collapsed && subStyleProps(keyStyle, 'collapsed')),
|
|
39
40
|
r: width / 2,
|
|
40
|
-
}
|
|
41
|
+
};
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
protected getCollapsedKeySize(attributes: Required<CircleComboStyleProps>): STDSize {
|
|
@@ -29,12 +29,13 @@ export class RectCombo extends BaseCombo<RectComboStyleProps> {
|
|
|
29
29
|
const keyStyle = super.getKeyStyle(attributes);
|
|
30
30
|
|
|
31
31
|
const [width, height] = this.getKeySize(attributes);
|
|
32
|
-
return
|
|
32
|
+
return {
|
|
33
|
+
...keyStyle,
|
|
33
34
|
...(attributes.collapsed && subStyleProps(keyStyle, 'collapsed')),
|
|
34
35
|
width,
|
|
35
36
|
height,
|
|
36
37
|
x: -width / 2,
|
|
37
38
|
y: -height / 2,
|
|
38
|
-
}
|
|
39
|
+
};
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
Keyframe,
|
|
13
13
|
LoopStyleProps,
|
|
14
14
|
Node,
|
|
15
|
-
NodeLabelStyleProps,
|
|
16
15
|
Point,
|
|
17
16
|
Prefix,
|
|
18
17
|
} from '../../types';
|
|
@@ -25,45 +24,9 @@ import { mergeOptions } from '../../utils/style';
|
|
|
25
24
|
import * as Symbol from '../../utils/symbol';
|
|
26
25
|
import { getWordWrapWidthByEnds } from '../../utils/text';
|
|
27
26
|
import { BaseElement } from '../base-element';
|
|
28
|
-
import { effect } from '../effect';
|
|
29
27
|
import type { BadgeStyleProps, BaseShapeStyleProps, LabelStyleProps } from '../shapes';
|
|
30
28
|
import { Badge, Label } from '../shapes';
|
|
31
29
|
|
|
32
|
-
const getDefaultKeyStyle = (): Partial<PathStyleProps> => ({
|
|
33
|
-
fillOpacity: 1,
|
|
34
|
-
increasedLineWidthForHitTesting: 2,
|
|
35
|
-
isBillboard: true,
|
|
36
|
-
lineWidth: 1,
|
|
37
|
-
strokeOpacity: 1,
|
|
38
|
-
});
|
|
39
|
-
const getDefaultHaloStyle = (): Partial<PathStyleProps> => ({
|
|
40
|
-
droppable: false,
|
|
41
|
-
lineDash: 0,
|
|
42
|
-
lineWidth: 12,
|
|
43
|
-
pointerEvents: 'none',
|
|
44
|
-
strokeOpacity: 1,
|
|
45
|
-
zIndex: -1,
|
|
46
|
-
});
|
|
47
|
-
const getDefaultLabelStyle = (): Partial<NodeLabelStyleProps> => ({
|
|
48
|
-
background: false,
|
|
49
|
-
backgroundLineWidth: 0,
|
|
50
|
-
backgroundOpacity: 0.75,
|
|
51
|
-
fontSize: 12,
|
|
52
|
-
fontWeight: 400,
|
|
53
|
-
isBillboard: true,
|
|
54
|
-
offsetX: 10,
|
|
55
|
-
opacity: 1,
|
|
56
|
-
padding: [4, 4, 4, 4],
|
|
57
|
-
textBaseline: 'middle',
|
|
58
|
-
});
|
|
59
|
-
const getDefaultBadgeStyle = (): Partial<BadgeStyleProps> => ({});
|
|
60
|
-
const getDefaultArrowStyle = () => ({
|
|
61
|
-
lineDash: 0,
|
|
62
|
-
lineJoin: 'round',
|
|
63
|
-
lineWidth: 1,
|
|
64
|
-
transformOrigin: 'center',
|
|
65
|
-
type: 'vee',
|
|
66
|
-
});
|
|
67
30
|
/**
|
|
68
31
|
* <zh/> 边的通用样式属性
|
|
69
32
|
*
|
|
@@ -211,7 +174,42 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
211
174
|
public type = 'edge';
|
|
212
175
|
|
|
213
176
|
static defaultStyleProps: Partial<BaseEdgeStyleProps> = {
|
|
214
|
-
|
|
177
|
+
badge: true,
|
|
178
|
+
badgeOffsetX: 0,
|
|
179
|
+
badgeOffsetY: 0,
|
|
180
|
+
badgePlacement: 'suffix',
|
|
181
|
+
isBillboard: true,
|
|
182
|
+
label: true,
|
|
183
|
+
labelAutoRotate: true,
|
|
184
|
+
labelIsBillboard: true,
|
|
185
|
+
labelMaxWidth: '80%',
|
|
186
|
+
labelOffsetX: 4,
|
|
187
|
+
labelOffsetY: 0,
|
|
188
|
+
labelPlacement: 'center',
|
|
189
|
+
labelTextBaseline: 'middle',
|
|
190
|
+
labelWordWrap: false,
|
|
191
|
+
halo: false,
|
|
192
|
+
haloDroppable: false,
|
|
193
|
+
haloLineDash: 0,
|
|
194
|
+
haloLineWidth: 12,
|
|
195
|
+
haloPointerEvents: 'none',
|
|
196
|
+
haloStrokeOpacity: 0.25,
|
|
197
|
+
haloZIndex: -1,
|
|
198
|
+
loop: true,
|
|
199
|
+
startArrow: false,
|
|
200
|
+
startArrowLineDash: 0,
|
|
201
|
+
startArrowLineJoin: 'round',
|
|
202
|
+
startArrowLineWidth: 1,
|
|
203
|
+
startArrowTransformOrigin: 'center',
|
|
204
|
+
startArrowType: 'vee',
|
|
205
|
+
endArrow: false,
|
|
206
|
+
endArrowLineDash: 0,
|
|
207
|
+
endArrowLineJoin: 'round',
|
|
208
|
+
endArrowLineWidth: 1,
|
|
209
|
+
endArrowTransformOrigin: 'center',
|
|
210
|
+
endArrowType: 'vee',
|
|
211
|
+
loopPlacement: 'top',
|
|
212
|
+
loopClockwise: true,
|
|
215
213
|
};
|
|
216
214
|
|
|
217
215
|
constructor(options: DisplayObjectConfig<BaseEdgeStyleProps>) {
|
|
@@ -229,21 +227,19 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
protected getKeyStyle(attributes: ParsedBaseEdgeStyleProps): PathStyleProps {
|
|
232
|
-
const { loop
|
|
230
|
+
const { loop, ...style } = this.getGraphicStyle(attributes);
|
|
233
231
|
const { sourceNode, targetNode } = this;
|
|
234
232
|
|
|
235
|
-
const defaultStyle = getDefaultKeyStyle();
|
|
236
|
-
|
|
237
233
|
const d = loop && isSameNode(sourceNode, targetNode) ? this.getLoopPath(attributes) : this.getKeyPath(attributes);
|
|
238
234
|
|
|
239
|
-
|
|
235
|
+
const keyStyle: PathStyleProps = { d };
|
|
240
236
|
|
|
241
237
|
Path.PARSED_STYLE_LIST.forEach((key) => {
|
|
242
238
|
// @ts-expect-error skip type error
|
|
243
|
-
if (key in style)
|
|
239
|
+
if (key in style) keyStyle[key] = style[key];
|
|
244
240
|
});
|
|
245
241
|
|
|
246
|
-
return
|
|
242
|
+
return keyStyle;
|
|
247
243
|
}
|
|
248
244
|
|
|
249
245
|
protected abstract getKeyPath(attributes: ParsedBaseEdgeStyleProps): PathArray;
|
|
@@ -256,8 +252,8 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
256
252
|
const defaultDist = Math.max(getBBoxWidth(bbox), getBBoxHeight(bbox));
|
|
257
253
|
|
|
258
254
|
const {
|
|
259
|
-
placement
|
|
260
|
-
clockwise
|
|
255
|
+
placement,
|
|
256
|
+
clockwise,
|
|
261
257
|
dist = defaultDist,
|
|
262
258
|
} = subStyleProps<Required<LoopStyleProps>>(this.getGraphicStyle(attributes), 'loop');
|
|
263
259
|
|
|
@@ -291,28 +287,19 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
291
287
|
}
|
|
292
288
|
|
|
293
289
|
protected getHaloStyle(attributes: ParsedBaseEdgeStyleProps): false | PathStyleProps {
|
|
294
|
-
|
|
295
|
-
if (halo === false) return false;
|
|
290
|
+
if (attributes.halo === false) return false;
|
|
296
291
|
|
|
297
292
|
const keyStyle = this.getKeyStyle(attributes);
|
|
298
293
|
const haloStyle = subStyleProps<LineStyleProps>(this.getGraphicStyle(attributes), 'halo');
|
|
299
294
|
|
|
300
|
-
return { ...keyStyle, ...
|
|
295
|
+
return { ...keyStyle, ...haloStyle };
|
|
301
296
|
}
|
|
302
297
|
|
|
303
298
|
protected getLabelStyle(attributes: ParsedBaseEdgeStyleProps): false | LabelStyleProps {
|
|
304
|
-
|
|
305
|
-
if (label === false || !labelText) return false;
|
|
299
|
+
if (attributes.label === false || !attributes.labelText) return false;
|
|
306
300
|
|
|
307
301
|
const labelStyle = subStyleProps<Required<EdgeLabelStyleProps>>(this.getGraphicStyle(attributes), 'label');
|
|
308
|
-
const {
|
|
309
|
-
placement = 'center',
|
|
310
|
-
offsetX = 4,
|
|
311
|
-
offsetY = 0,
|
|
312
|
-
autoRotate = true,
|
|
313
|
-
maxWidth = '80%',
|
|
314
|
-
...restStyle
|
|
315
|
-
} = labelStyle;
|
|
302
|
+
const { placement, offsetX, offsetY, autoRotate, maxWidth, ...restStyle } = labelStyle;
|
|
316
303
|
const labelPositionStyle = getLabelPositionStyle(
|
|
317
304
|
this.shapeMap.key as EdgeKey,
|
|
318
305
|
placement,
|
|
@@ -322,31 +309,20 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
322
309
|
);
|
|
323
310
|
|
|
324
311
|
const bbox = this.shapeMap.key.getLocalBounds();
|
|
312
|
+
const wordWrapWidth = getWordWrapWidthByEnds([bbox.min, bbox.max], maxWidth);
|
|
325
313
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (attributes.labelWordWrap) {
|
|
329
|
-
Object.assign(defaultStyle, {
|
|
330
|
-
wordWrap: true,
|
|
331
|
-
wordWrapWidth: getWordWrapWidthByEnds([bbox.min, bbox.max], maxWidth),
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return Object.assign(defaultStyle, labelPositionStyle, restStyle);
|
|
314
|
+
return Object.assign({ wordWrapWidth }, labelPositionStyle, restStyle);
|
|
336
315
|
}
|
|
337
316
|
|
|
338
317
|
protected getBadgeStyle(attributes: ParsedBaseEdgeStyleProps): false | BadgeStyleProps {
|
|
339
318
|
if (attributes.badge === false || !attributes.badgeText) return false;
|
|
340
319
|
|
|
341
|
-
const {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
...badgeStyle
|
|
346
|
-
} = subStyleProps<Required<EdgeBadgeStyleProps>>(attributes, 'badge');
|
|
320
|
+
const { offsetX, offsetY, placement, ...badgeStyle } = subStyleProps<Required<EdgeBadgeStyleProps>>(
|
|
321
|
+
attributes,
|
|
322
|
+
'badge',
|
|
323
|
+
);
|
|
347
324
|
|
|
348
325
|
return Object.assign(
|
|
349
|
-
getDefaultBadgeStyle(),
|
|
350
326
|
badgeStyle,
|
|
351
327
|
getBadgePositionStyle(this.shapeMap, placement, attributes.labelPlacement, offsetX, offsetY),
|
|
352
328
|
);
|
|
@@ -361,7 +337,6 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
361
337
|
|
|
362
338
|
if (enable) {
|
|
363
339
|
const arrowStyle = this.getArrowStyle(attributes, isStart);
|
|
364
|
-
if (!effect(this, `arrow-${type}`, arrowStyle)) return;
|
|
365
340
|
|
|
366
341
|
const [marker, markerOffset, arrowOffset] = isStart
|
|
367
342
|
? (['markerStart', 'markerStartOffset', 'startArrowOffset'] as const)
|
|
@@ -396,11 +371,9 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
396
371
|
const arrowFn = isFunction(type) ? type : Symbol[type] || Symbol.triangle;
|
|
397
372
|
const d = arrowFn(width, height);
|
|
398
373
|
|
|
399
|
-
const defaultStyle = getDefaultArrowStyle();
|
|
400
|
-
|
|
401
374
|
return Object.assign(
|
|
402
375
|
pick(keyStyle, ['stroke', 'strokeOpacity', 'fillOpacity']),
|
|
403
|
-
{
|
|
376
|
+
{ width, height },
|
|
404
377
|
{ ...(d && { d, fill: type === 'simple' ? '' : keyStyle.stroke }) },
|
|
405
378
|
arrowStyle,
|
|
406
379
|
);
|
|
@@ -408,19 +381,16 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
408
381
|
|
|
409
382
|
protected drawLabelShape(attributes: ParsedBaseEdgeStyleProps, container: Group) {
|
|
410
383
|
const style = this.getLabelStyle(attributes);
|
|
411
|
-
if (!effect(this, 'label', style)) return;
|
|
412
384
|
this.upsert('label', Label, style, container);
|
|
413
385
|
}
|
|
414
386
|
|
|
415
387
|
protected drawHaloShape(attributes: ParsedBaseEdgeStyleProps, container: Group) {
|
|
416
388
|
const style = this.getHaloStyle(attributes);
|
|
417
|
-
if (!effect(this, 'halo', style)) return;
|
|
418
389
|
this.upsert('halo', Path, style, container);
|
|
419
390
|
}
|
|
420
391
|
|
|
421
392
|
protected drawBadgeShape(attributes: ParsedBaseEdgeStyleProps, container: Group) {
|
|
422
393
|
const style = this.getBadgeStyle(attributes);
|
|
423
|
-
if (!effect(this, 'badge', style)) return;
|
|
424
394
|
this.upsert('badge', Badge, style, container);
|
|
425
395
|
}
|
|
426
396
|
|
|
@@ -434,7 +404,6 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
434
404
|
|
|
435
405
|
protected drawKeyShape(attributes: ParsedBaseEdgeStyleProps, container: Group): Path | undefined {
|
|
436
406
|
const style = this.getKeyStyle(attributes);
|
|
437
|
-
if (!effect(this, 'key', style)) return;
|
|
438
407
|
return this.upsert('key', Path, style, container);
|
|
439
408
|
}
|
|
440
409
|
|
package/src/elements/effect.ts
CHANGED
|
@@ -10,8 +10,10 @@ const EFFECT_WEAKMAP = new WeakMap<Element, Record<string, any>>();
|
|
|
10
10
|
* @param key - <zh/> 缓存 key | <en/> Cache key
|
|
11
11
|
* @param style - <zh/> 样式属性 | <en/> Style attribute
|
|
12
12
|
* @returns <zh/> 是否执行函数 | <en/> Whether to execute the function
|
|
13
|
+
* @deprecated <zh/> 该方法已废弃,并不能显著提升性能 | <en/> This method is deprecated and does not significantly improve performance
|
|
13
14
|
*/
|
|
14
15
|
export function effect<T extends false | Record<string, any>>(target: Element, key: string, style: T): boolean {
|
|
16
|
+
// return true;
|
|
15
17
|
if (!EFFECT_WEAKMAP.has(target)) EFFECT_WEAKMAP.set(target, {});
|
|
16
18
|
const cache = EFFECT_WEAKMAP.get(target)!;
|
|
17
19
|
if (!cache[key]) {
|
|
@@ -26,56 +26,10 @@ import { mergeOptions } from '../../utils/style';
|
|
|
26
26
|
import { getWordWrapWidthByBox } from '../../utils/text';
|
|
27
27
|
import { setVisibility } from '../../utils/visibility';
|
|
28
28
|
import { BaseElement } from '../base-element';
|
|
29
|
-
import { effect } from '../effect';
|
|
30
29
|
import type { BadgeStyleProps, BaseShapeStyleProps, IconStyleProps, LabelStyleProps } from '../shapes';
|
|
31
30
|
import { Badge, Icon, Label } from '../shapes';
|
|
32
31
|
import { connectImage, dispatchPositionChange } from '../shapes/image';
|
|
33
32
|
|
|
34
|
-
const getDefaultKeyStyle = () => ({
|
|
35
|
-
fillOpacity: 1,
|
|
36
|
-
lineWidth: 0,
|
|
37
|
-
strokeOpacity: 1,
|
|
38
|
-
});
|
|
39
|
-
const getDefaultHaloStyle = () => ({
|
|
40
|
-
droppable: false,
|
|
41
|
-
lineDash: 0,
|
|
42
|
-
lineWidth: 12,
|
|
43
|
-
pointerEvents: 'none',
|
|
44
|
-
strokeOpacity: 0.25,
|
|
45
|
-
zIndex: -1,
|
|
46
|
-
});
|
|
47
|
-
const getDefaultIconStyle = (): Partial<IconStyleProps> => ({
|
|
48
|
-
fill: '#fff',
|
|
49
|
-
opacity: 1,
|
|
50
|
-
zIndex: 1,
|
|
51
|
-
});
|
|
52
|
-
const getDefaultLabelStyle = (): Partial<NodeLabelStyleProps> => ({
|
|
53
|
-
background: false,
|
|
54
|
-
backgroundLineWidth: 0,
|
|
55
|
-
backgroundOpacity: 0.75,
|
|
56
|
-
fillOpacity: 0.85,
|
|
57
|
-
fontSize: 12,
|
|
58
|
-
fontWeight: 400,
|
|
59
|
-
isBillboard: true,
|
|
60
|
-
lineHeight: 16,
|
|
61
|
-
offsetY: 2,
|
|
62
|
-
opacity: 1,
|
|
63
|
-
padding: [0, 2],
|
|
64
|
-
zIndex: 0,
|
|
65
|
-
});
|
|
66
|
-
const getDefaultPortStyle = (): Partial<PortStyleProps> => ({
|
|
67
|
-
lineWidth: 1,
|
|
68
|
-
strokeOpacity: 0.65,
|
|
69
|
-
zIndex: 2,
|
|
70
|
-
});
|
|
71
|
-
const getDefaultBadgeStyle = (): Partial<BadgeStyleProps> => ({
|
|
72
|
-
backgroundOpacity: 1,
|
|
73
|
-
fill: '#fff',
|
|
74
|
-
fontSize: 8,
|
|
75
|
-
padding: [0, 4],
|
|
76
|
-
zIndex: 3,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
33
|
/**
|
|
80
34
|
* <zh/> 节点通用样式配置项
|
|
81
35
|
*
|
|
@@ -241,9 +195,33 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
|
|
|
241
195
|
public type = 'node';
|
|
242
196
|
|
|
243
197
|
static defaultStyleProps: Partial<BaseNodeStyleProps> = {
|
|
198
|
+
x: 0,
|
|
199
|
+
y: 0,
|
|
200
|
+
size: 32,
|
|
244
201
|
droppable: true,
|
|
245
202
|
draggable: true,
|
|
246
|
-
|
|
203
|
+
port: true,
|
|
204
|
+
ports: [],
|
|
205
|
+
portZIndex: 2,
|
|
206
|
+
portLinkToCenter: false,
|
|
207
|
+
badge: true,
|
|
208
|
+
badges: [],
|
|
209
|
+
badgeZIndex: 3,
|
|
210
|
+
halo: false,
|
|
211
|
+
haloDroppable: false,
|
|
212
|
+
haloLineDash: 0,
|
|
213
|
+
haloLineWidth: 12,
|
|
214
|
+
haloStrokeOpacity: 0.25,
|
|
215
|
+
haloPointerEvents: 'none',
|
|
216
|
+
haloZIndex: -1,
|
|
217
|
+
icon: true,
|
|
218
|
+
iconZIndex: 1,
|
|
219
|
+
label: true,
|
|
220
|
+
labelIsBillboard: true,
|
|
221
|
+
labelMaxWidth: '200%',
|
|
222
|
+
labelPlacement: 'bottom',
|
|
223
|
+
labelWordWrap: false,
|
|
224
|
+
labelZIndex: 0,
|
|
247
225
|
};
|
|
248
226
|
|
|
249
227
|
constructor(options: DisplayObjectConfig<S>) {
|
|
@@ -258,28 +236,19 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
|
|
|
258
236
|
protected getKeyStyle(attributes: Required<S>) {
|
|
259
237
|
const style = this.getGraphicStyle(attributes);
|
|
260
238
|
|
|
261
|
-
return Object.assign(
|
|
262
|
-
getDefaultKeyStyle(),
|
|
263
|
-
omitStyleProps(style, ['label', 'halo', 'icon', 'badge', 'port']),
|
|
264
|
-
) as any;
|
|
239
|
+
return Object.assign(omitStyleProps(style, ['label', 'halo', 'icon', 'badge', 'port'])) as any;
|
|
265
240
|
}
|
|
266
241
|
|
|
267
242
|
protected getLabelStyle(attributes: Required<S>): false | LabelStyleProps {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (label === false || !labelText) return false;
|
|
243
|
+
if (attributes.label === false || !attributes.labelText) return false;
|
|
271
244
|
|
|
272
|
-
const {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
offsetY = 2,
|
|
277
|
-
...labelStyle
|
|
278
|
-
} = subStyleProps<Required<NodeLabelStyleProps>>(this.getGraphicStyle(attributes), 'label');
|
|
245
|
+
const { placement, maxWidth, offsetX, offsetY, ...labelStyle } = subStyleProps<Required<NodeLabelStyleProps>>(
|
|
246
|
+
this.getGraphicStyle(attributes),
|
|
247
|
+
'label',
|
|
248
|
+
);
|
|
279
249
|
const keyBounds = this.getShape('key').getLocalBounds();
|
|
280
250
|
|
|
281
251
|
return Object.assign(
|
|
282
|
-
getDefaultLabelStyle(),
|
|
283
252
|
getTextStyleByPlacement(keyBounds, placement, offsetX, offsetY),
|
|
284
253
|
{ wordWrapWidth: getWordWrapWidthByBox(keyBounds, maxWidth) },
|
|
285
254
|
labelStyle,
|
|
@@ -287,55 +256,42 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
|
|
|
287
256
|
}
|
|
288
257
|
|
|
289
258
|
protected getHaloStyle(attributes: Required<S>) {
|
|
290
|
-
|
|
291
|
-
if (!halo) return false;
|
|
259
|
+
if (attributes.halo === false) return false;
|
|
292
260
|
|
|
293
261
|
const { fill, ...keyStyle } = this.getKeyStyle(attributes);
|
|
294
262
|
const haloStyle = subStyleProps(this.getGraphicStyle(attributes), 'halo');
|
|
295
263
|
|
|
296
|
-
return {
|
|
297
|
-
...keyStyle,
|
|
298
|
-
...getDefaultHaloStyle(),
|
|
299
|
-
stroke: fill,
|
|
300
|
-
...haloStyle,
|
|
301
|
-
} as any;
|
|
264
|
+
return { ...keyStyle, stroke: fill, ...haloStyle } as any;
|
|
302
265
|
}
|
|
303
266
|
|
|
304
267
|
protected getIconStyle(attributes: Required<S>): false | IconStyleProps {
|
|
305
|
-
|
|
306
|
-
if (icon === false || (!iconText && !iconSrc)) return false;
|
|
268
|
+
if (attributes.icon === false || (!attributes.iconText && !attributes.iconSrc)) return false;
|
|
307
269
|
|
|
308
270
|
const iconStyle = subStyleProps(this.getGraphicStyle(attributes), 'icon');
|
|
309
271
|
|
|
310
|
-
return Object.assign(
|
|
272
|
+
return Object.assign(inferIconStyle(attributes.size!, iconStyle), iconStyle);
|
|
311
273
|
}
|
|
312
274
|
|
|
313
275
|
protected getBadgesStyle(attributes: Required<S>): Record<string, NodeBadgeStyleProps | false> {
|
|
314
|
-
const
|
|
276
|
+
const badges = subObject(this.shapeMap, 'badge-');
|
|
315
277
|
const badgesShapeStyle: Record<string, NodeBadgeStyleProps | false> = {};
|
|
316
278
|
|
|
317
|
-
Object.keys(
|
|
279
|
+
Object.keys(badges).forEach((key) => {
|
|
318
280
|
badgesShapeStyle[key] = false;
|
|
319
281
|
});
|
|
320
|
-
|
|
321
|
-
const { badge = true, badges = [] } = attributes;
|
|
322
|
-
|
|
323
|
-
if (badge === false || !badges.length) return badgesShapeStyle;
|
|
282
|
+
if (attributes.badge === false || !attributes.badges?.length) return badgesShapeStyle;
|
|
324
283
|
|
|
325
284
|
const { badges: badgeOptions = [], badgePalette, opacity = 1, ...restAttributes } = attributes;
|
|
326
285
|
const colors = getPaletteColors(badgePalette);
|
|
327
286
|
const badgeStyle = subStyleProps<BadgeStyleProps>(this.getGraphicStyle(restAttributes), 'badge');
|
|
328
287
|
|
|
329
288
|
badgeOptions.forEach((option, i) => {
|
|
330
|
-
badgesShapeStyle[i] =
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
badgeStyle,
|
|
337
|
-
this.getBadgeStyle(option),
|
|
338
|
-
);
|
|
289
|
+
badgesShapeStyle[i] = {
|
|
290
|
+
backgroundFill: colors ? colors[i % colors?.length] : undefined,
|
|
291
|
+
opacity,
|
|
292
|
+
...badgeStyle,
|
|
293
|
+
...this.getBadgeStyle(option),
|
|
294
|
+
};
|
|
339
295
|
});
|
|
340
296
|
|
|
341
297
|
return badgesShapeStyle;
|
|
@@ -349,22 +305,20 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
|
|
|
349
305
|
}
|
|
350
306
|
|
|
351
307
|
protected getPortsStyle(attributes: Required<S>): Record<string, PortStyleProps | false> {
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
const portShapes = this.getPorts();
|
|
308
|
+
const ports = this.getPorts();
|
|
355
309
|
const portsShapeStyle: Record<string, PortStyleProps | false> = {};
|
|
356
310
|
|
|
357
|
-
Object.keys(
|
|
311
|
+
Object.keys(ports).forEach((key) => {
|
|
358
312
|
portsShapeStyle[key] = false;
|
|
359
313
|
});
|
|
360
314
|
|
|
361
|
-
if (port === false || !ports
|
|
315
|
+
if (attributes.port === false || !attributes.ports?.length) return portsShapeStyle;
|
|
362
316
|
|
|
363
317
|
const portStyle = subStyleProps<PortStyleProps>(this.getGraphicStyle(attributes), 'port');
|
|
364
318
|
const { ports: portOptions = [] } = attributes;
|
|
365
319
|
portOptions.forEach((option, index) => {
|
|
366
320
|
const key = option.key || index;
|
|
367
|
-
const mergedStyle =
|
|
321
|
+
const mergedStyle = { ...portStyle, ...option };
|
|
368
322
|
if (isSimplePort(mergedStyle)) {
|
|
369
323
|
portsShapeStyle[key] = false;
|
|
370
324
|
} else {
|
|
@@ -410,16 +364,12 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
|
|
|
410
364
|
|
|
411
365
|
protected drawHaloShape(attributes: Required<S>, container: Group): void {
|
|
412
366
|
const style = this.getHaloStyle(attributes);
|
|
413
|
-
if (!effect(this, 'halo', style)) return;
|
|
414
|
-
|
|
415
367
|
const keyShape = this.getShape('key');
|
|
416
368
|
this.upsert('halo', keyShape.constructor as new (...args: unknown[]) => DisplayObject, style, container);
|
|
417
369
|
}
|
|
418
370
|
|
|
419
371
|
protected drawIconShape(attributes: Required<S>, container: Group): void {
|
|
420
372
|
const style = this.getIconStyle(attributes);
|
|
421
|
-
if (!effect(this, 'icon', style)) return;
|
|
422
|
-
|
|
423
373
|
this.upsert('icon', Icon, style, container);
|
|
424
374
|
connectImage(this);
|
|
425
375
|
}
|
|
@@ -428,8 +378,6 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
|
|
|
428
378
|
const badgesStyle = this.getBadgesStyle(attributes);
|
|
429
379
|
Object.keys(badgesStyle).forEach((key) => {
|
|
430
380
|
const style = badgesStyle[key];
|
|
431
|
-
if (!effect(this, `badge-${key}`, style)) return;
|
|
432
|
-
|
|
433
381
|
this.upsert(`badge-${key}`, Badge, style, container);
|
|
434
382
|
});
|
|
435
383
|
}
|
|
@@ -440,16 +388,12 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
|
|
|
440
388
|
Object.keys(portsStyle).forEach((key) => {
|
|
441
389
|
const style = portsStyle[key] as CircleStyleProps;
|
|
442
390
|
const shapeKey = `port-${key}`;
|
|
443
|
-
if (!effect(this, shapeKey, style)) return;
|
|
444
|
-
|
|
445
391
|
this.upsert(shapeKey, GCircle, style, container);
|
|
446
392
|
});
|
|
447
393
|
}
|
|
448
394
|
|
|
449
395
|
protected drawLabelShape(attributes: Required<S>, container: Group): void {
|
|
450
396
|
const style = this.getLabelStyle(attributes);
|
|
451
|
-
if (!effect(this, 'label', style)) return;
|
|
452
|
-
|
|
453
397
|
this.upsert('label', Label, style, container);
|
|
454
398
|
}
|
|
455
399
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DisplayObjectConfig, RectStyleProps as GRectStyleProps, Group } from '@antv/g';
|
|
2
2
|
import { ImageStyleProps as GImageStyleProps, Rect as GRect } from '@antv/g';
|
|
3
3
|
import { ICON_SIZE_RATIO } from '../../constants/element';
|
|
4
|
+
import { subStyleProps } from '../../utils/prefix';
|
|
4
5
|
import { mergeOptions } from '../../utils/style';
|
|
5
6
|
import { add } from '../../utils/vector';
|
|
6
7
|
import type { IconStyleProps } from '../shapes';
|
|
@@ -58,18 +59,13 @@ export class Image extends BaseNode<ImageStyleProps> {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
protected getHaloStyle(attributes: Required<ImageStyleProps>): false | GRectStyleProps {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const haloLineWidth = Number(
|
|
62
|
+
if (attributes.halo === false) return false;
|
|
63
|
+
const { fill: keyStyleFill, stroke: keyStyleStroke, ...keyStyle } = this.getShape<GRect>('key').attributes;
|
|
64
|
+
const haloStyle = subStyleProps(this.getGraphicStyle(attributes), 'halo');
|
|
65
|
+
const haloLineWidth = Number(haloStyle.lineWidth);
|
|
65
66
|
const [width, height] = add(this.getSize(attributes), [haloLineWidth, haloLineWidth]);
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
width,
|
|
69
|
-
height,
|
|
70
|
-
x: -width / 2,
|
|
71
|
-
y: -height / 2,
|
|
72
|
-
});
|
|
67
|
+
const fill = 'transparent';
|
|
68
|
+
return { ...haloStyle, width, height, fill, x: -width / 2, y: -height / 2 };
|
|
73
69
|
}
|
|
74
70
|
|
|
75
71
|
protected getIconStyle(attributes: Required<ImageStyleProps>): false | IconStyleProps {
|
|
@@ -33,18 +33,8 @@ interface Options {
|
|
|
33
33
|
* @returns <zh/> [容器, 画布] | <en/> [container, canvas]
|
|
34
34
|
*/
|
|
35
35
|
export function createPluginCanvas(options: Options): [HTMLElement, GCanvas] {
|
|
36
|
-
const { width, height, renderer
|
|
36
|
+
const { width, height, renderer } = options;
|
|
37
37
|
const $container = getContainer(options);
|
|
38
|
-
const [x, y] = computePosition(options);
|
|
39
|
-
|
|
40
|
-
Object.assign($container.style, {
|
|
41
|
-
position: 'absolute',
|
|
42
|
-
left: x + 'px',
|
|
43
|
-
top: y + 'px',
|
|
44
|
-
width: width + 'px',
|
|
45
|
-
height: height + 'px',
|
|
46
|
-
...containerStyle,
|
|
47
|
-
});
|
|
48
38
|
|
|
49
39
|
const canvas = new GCanvas({
|
|
50
40
|
width,
|
|
@@ -70,6 +60,19 @@ function getContainer(options: Options) {
|
|
|
70
60
|
}
|
|
71
61
|
|
|
72
62
|
const $container = createPluginContainer(className, false);
|
|
63
|
+
|
|
64
|
+
const { width, height, containerStyle } = options;
|
|
65
|
+
const [x, y] = computePosition(options);
|
|
66
|
+
|
|
67
|
+
Object.assign($container.style, {
|
|
68
|
+
position: 'absolute',
|
|
69
|
+
left: x + 'px',
|
|
70
|
+
top: y + 'px',
|
|
71
|
+
width: width + 'px',
|
|
72
|
+
height: height + 'px',
|
|
73
|
+
...containerStyle,
|
|
74
|
+
});
|
|
75
|
+
|
|
73
76
|
graphCanvas.getContainer()?.appendChild($container);
|
|
74
77
|
return $container;
|
|
75
78
|
}
|
package/src/runtime/element.ts
CHANGED
|
@@ -95,11 +95,7 @@ export class ElementController {
|
|
|
95
95
|
|
|
96
96
|
public getThemeStateStyle(elementType: ElementType, states: State[]) {
|
|
97
97
|
const { state = {} } = this.getTheme(elementType);
|
|
98
|
-
return Object.assign(
|
|
99
|
-
{},
|
|
100
|
-
this.context.graph.rendered ? {} : state.default,
|
|
101
|
-
...states.map((name) => state[name] || {}),
|
|
102
|
-
);
|
|
98
|
+
return Object.assign({}, ...states.map((name) => state[name] || {}));
|
|
103
99
|
}
|
|
104
100
|
|
|
105
101
|
private paletteStyle: Record<ID, string> = {};
|
|
@@ -443,18 +439,14 @@ export class ElementController {
|
|
|
443
439
|
this.shapeTypeMap[id] = type;
|
|
444
440
|
this.elementMap[id] = element;
|
|
445
441
|
|
|
446
|
-
const { stage = 'enter'
|
|
447
|
-
|
|
448
|
-
const enableAnimation = animation && this.context.options.animation;
|
|
442
|
+
const { stage = 'enter' } = context;
|
|
449
443
|
|
|
450
444
|
this.context.animation?.add(
|
|
451
445
|
{
|
|
452
446
|
element,
|
|
453
447
|
elementType,
|
|
454
448
|
stage,
|
|
455
|
-
|
|
456
|
-
// <en/> When the animation is turned off, there is no need to deep copy the style
|
|
457
|
-
originalStyle: enableAnimation ? { ...element.attributes } : element.attributes,
|
|
449
|
+
originalStyle: { ...element.attributes },
|
|
458
450
|
updatedStyle: style,
|
|
459
451
|
},
|
|
460
452
|
{
|