@antv/g6 5.0.18 → 5.0.20
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/drag-canvas.d.ts +9 -0
- package/dist/lib/behaviors/drag-element.d.ts +0 -1
- package/dist/lib/behaviors/hover-activate.d.ts +14 -1
- package/dist/lib/behaviors/scroll-canvas.d.ts +9 -0
- package/dist/lib/elements/combos/circle.d.ts +1 -1
- package/dist/lib/elements/edges/cubic-radial.d.ts +24 -0
- package/dist/lib/elements/edges/index.d.ts +2 -0
- package/dist/lib/elements/effect.d.ts +7 -30
- package/dist/lib/elements/nodes/base-node.d.ts +2 -1
- package/dist/lib/elements/nodes/circle.d.ts +1 -1
- package/dist/lib/elements/nodes/ellipse.d.ts +1 -1
- package/dist/lib/elements/shapes/base-shape.d.ts +1 -1
- package/dist/lib/elements/shapes/polygon.d.ts +1 -1
- package/dist/lib/exports.d.ts +6 -5
- package/dist/lib/runtime/data.d.ts +1 -0
- package/dist/lib/runtime/element.d.ts +1 -0
- package/dist/lib/runtime/graph.d.ts +2 -0
- package/dist/lib/runtime/layout.d.ts +1 -0
- package/dist/lib/transforms/base-transform.d.ts +1 -0
- package/dist/lib/transforms/index.d.ts +3 -0
- package/dist/lib/transforms/position-radial-labels.d.ts +27 -0
- package/dist/lib/types/element.d.ts +2 -1
- package/dist/lib/utils/data.d.ts +14 -0
- package/dist/lib/utils/diff.d.ts +2 -1
- package/dist/lib/utils/point.d.ts +17 -5
- package/dist/lib/utils/position.d.ts +8 -0
- package/dist/lib/utils/relation.d.ts +6 -4
- package/dist/lib/utils/vector.d.ts +8 -0
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/drag-canvas.d.ts +9 -0
- package/esm/behaviors/drag-canvas.js +28 -3
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/behaviors/drag-element.d.ts +0 -1
- package/esm/behaviors/drag-element.js +14 -7
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/hover-activate.d.ts +14 -1
- package/esm/behaviors/hover-activate.js +3 -2
- package/esm/behaviors/hover-activate.js.map +1 -1
- package/esm/behaviors/scroll-canvas.d.ts +9 -0
- package/esm/behaviors/scroll-canvas.js +31 -4
- package/esm/behaviors/scroll-canvas.js.map +1 -1
- package/esm/elements/combos/base-combo.js +6 -12
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/combos/circle.d.ts +1 -1
- package/esm/elements/combos/circle.js +2 -2
- package/esm/elements/combos/circle.js.map +1 -1
- package/esm/elements/edges/base-edge.js +18 -29
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/edges/cubic-radial.d.ts +24 -0
- package/esm/elements/edges/cubic-radial.js +52 -0
- package/esm/elements/edges/cubic-radial.js.map +1 -0
- package/esm/elements/edges/index.d.ts +2 -0
- package/esm/elements/edges/index.js +1 -0
- package/esm/elements/edges/index.js.map +1 -1
- package/esm/elements/effect.d.ts +7 -30
- package/esm/elements/effect.js +20 -50
- package/esm/elements/effect.js.map +1 -1
- package/esm/elements/nodes/base-node.d.ts +2 -1
- package/esm/elements/nodes/base-node.js +24 -31
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/nodes/circle.d.ts +1 -1
- package/esm/elements/nodes/circle.js +2 -2
- package/esm/elements/nodes/circle.js.map +1 -1
- package/esm/elements/nodes/ellipse.d.ts +1 -1
- package/esm/elements/nodes/ellipse.js +2 -2
- package/esm/elements/nodes/ellipse.js.map +1 -1
- package/esm/elements/shapes/base-shape.d.ts +1 -1
- package/esm/elements/shapes/base-shape.js +1 -1
- package/esm/elements/shapes/polygon.d.ts +1 -1
- package/esm/elements/shapes/polygon.js +2 -2
- package/esm/elements/shapes/polygon.js.map +1 -1
- package/esm/exports.d.ts +6 -5
- package/esm/exports.js +4 -3
- package/esm/exports.js.map +1 -1
- package/esm/plugins/tooltip.js +5 -2
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/registry/build-in.js +4 -2
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/animation.js +12 -10
- package/esm/runtime/animation.js.map +1 -1
- package/esm/runtime/data.d.ts +1 -0
- package/esm/runtime/data.js +21 -13
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +1 -0
- package/esm/runtime/element.js +45 -18
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +2 -0
- package/esm/runtime/graph.js +44 -22
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +1 -0
- package/esm/runtime/layout.js +5 -0
- package/esm/runtime/layout.js.map +1 -1
- package/esm/transforms/base-transform.d.ts +1 -0
- package/esm/transforms/base-transform.js +1 -0
- package/esm/transforms/base-transform.js.map +1 -1
- package/esm/transforms/collapse-expand-combo.js +3 -0
- package/esm/transforms/collapse-expand-combo.js.map +1 -1
- package/esm/transforms/collapse-expand-node.js +2 -0
- package/esm/transforms/collapse-expand-node.js.map +1 -1
- package/esm/transforms/index.d.ts +3 -0
- package/esm/transforms/index.js +1 -0
- package/esm/transforms/index.js.map +1 -1
- package/esm/transforms/position-radial-labels.d.ts +27 -0
- package/esm/transforms/position-radial-labels.js +50 -0
- package/esm/transforms/position-radial-labels.js.map +1 -0
- package/esm/types/element.d.ts +2 -1
- package/esm/utils/data.d.ts +14 -0
- package/esm/utils/data.js +39 -0
- package/esm/utils/data.js.map +1 -1
- package/esm/utils/diff.d.ts +2 -1
- package/esm/utils/diff.js +3 -2
- package/esm/utils/diff.js.map +1 -1
- package/esm/utils/point.d.ts +17 -5
- package/esm/utils/point.js +24 -8
- package/esm/utils/point.js.map +1 -1
- package/esm/utils/position.d.ts +8 -0
- package/esm/utils/position.js +11 -0
- package/esm/utils/position.js.map +1 -1
- package/esm/utils/relation.d.ts +6 -4
- package/esm/utils/relation.js +10 -8
- package/esm/utils/relation.js.map +1 -1
- package/esm/utils/vector.d.ts +8 -0
- package/esm/utils/vector.js +13 -0
- package/esm/utils/vector.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/drag-canvas.d.ts +9 -0
- package/lib/behaviors/drag-canvas.js +27 -2
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/behaviors/drag-element.d.ts +0 -1
- package/lib/behaviors/drag-element.js +14 -7
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/hover-activate.d.ts +14 -1
- package/lib/behaviors/hover-activate.js +3 -2
- package/lib/behaviors/hover-activate.js.map +1 -1
- package/lib/behaviors/scroll-canvas.d.ts +9 -0
- package/lib/behaviors/scroll-canvas.js +31 -4
- package/lib/behaviors/scroll-canvas.js.map +1 -1
- package/lib/elements/combos/base-combo.js +5 -11
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/combos/circle.d.ts +1 -1
- package/lib/elements/combos/circle.js +2 -2
- package/lib/elements/combos/circle.js.map +1 -1
- package/lib/elements/edges/base-edge.js +18 -29
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/edges/cubic-radial.d.ts +24 -0
- package/lib/elements/edges/cubic-radial.js +56 -0
- package/lib/elements/edges/cubic-radial.js.map +1 -0
- package/lib/elements/edges/index.d.ts +2 -0
- package/lib/elements/edges/index.js +3 -1
- package/lib/elements/edges/index.js.map +1 -1
- package/lib/elements/effect.d.ts +7 -30
- package/lib/elements/effect.js +20 -50
- package/lib/elements/effect.js.map +1 -1
- package/lib/elements/nodes/base-node.d.ts +2 -1
- package/lib/elements/nodes/base-node.js +24 -31
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/nodes/circle.d.ts +1 -1
- package/lib/elements/nodes/circle.js +2 -2
- package/lib/elements/nodes/circle.js.map +1 -1
- package/lib/elements/nodes/ellipse.d.ts +1 -1
- package/lib/elements/nodes/ellipse.js +2 -2
- package/lib/elements/nodes/ellipse.js.map +1 -1
- package/lib/elements/shapes/base-shape.d.ts +1 -1
- package/lib/elements/shapes/base-shape.js +1 -1
- package/lib/elements/shapes/polygon.d.ts +1 -1
- package/lib/elements/shapes/polygon.js +2 -2
- package/lib/elements/shapes/polygon.js.map +1 -1
- package/lib/exports.d.ts +6 -5
- package/lib/exports.js +12 -6
- package/lib/exports.js.map +1 -1
- package/lib/plugins/tooltip.js +5 -2
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/registry/build-in.js +2 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/animation.js +12 -10
- package/lib/runtime/animation.js.map +1 -1
- package/lib/runtime/data.d.ts +1 -0
- package/lib/runtime/data.js +19 -11
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +1 -0
- package/lib/runtime/element.js +45 -18
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +2 -0
- package/lib/runtime/graph.js +44 -22
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +1 -0
- package/lib/runtime/layout.js +5 -0
- package/lib/runtime/layout.js.map +1 -1
- package/lib/transforms/base-transform.d.ts +1 -0
- package/lib/transforms/base-transform.js +1 -0
- package/lib/transforms/base-transform.js.map +1 -1
- package/lib/transforms/collapse-expand-combo.js +3 -0
- package/lib/transforms/collapse-expand-combo.js.map +1 -1
- package/lib/transforms/collapse-expand-node.js +2 -0
- package/lib/transforms/collapse-expand-node.js.map +1 -1
- package/lib/transforms/index.d.ts +3 -0
- package/lib/transforms/index.js +3 -1
- package/lib/transforms/index.js.map +1 -1
- package/lib/transforms/position-radial-labels.d.ts +27 -0
- package/lib/transforms/position-radial-labels.js +54 -0
- package/lib/transforms/position-radial-labels.js.map +1 -0
- package/lib/types/element.d.ts +2 -1
- package/lib/utils/data.d.ts +14 -0
- package/lib/utils/data.js +40 -0
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/diff.d.ts +2 -1
- package/lib/utils/diff.js +3 -2
- package/lib/utils/diff.js.map +1 -1
- package/lib/utils/point.d.ts +17 -5
- package/lib/utils/point.js +25 -8
- package/lib/utils/point.js.map +1 -1
- package/lib/utils/position.d.ts +8 -0
- package/lib/utils/position.js +12 -0
- package/lib/utils/position.js.map +1 -1
- package/lib/utils/relation.d.ts +6 -4
- package/lib/utils/relation.js +10 -8
- package/lib/utils/relation.js.map +1 -1
- package/lib/utils/vector.d.ts +8 -0
- package/lib/utils/vector.js +14 -0
- package/lib/utils/vector.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +3 -3
- package/src/behaviors/drag-canvas.ts +42 -3
- package/src/behaviors/drag-element.ts +17 -7
- package/src/behaviors/hover-activate.ts +17 -3
- package/src/behaviors/scroll-canvas.ts +45 -4
- package/src/elements/combos/base-combo.ts +5 -4
- package/src/elements/combos/circle.ts +2 -2
- package/src/elements/edges/base-edge.ts +14 -11
- package/src/elements/edges/cubic-radial.ts +77 -0
- package/src/elements/edges/index.ts +2 -0
- package/src/elements/effect.ts +20 -54
- package/src/elements/nodes/base-node.ts +24 -18
- package/src/elements/nodes/circle.ts +2 -2
- package/src/elements/nodes/ellipse.ts +2 -2
- package/src/elements/shapes/base-shape.ts +1 -1
- package/src/elements/shapes/polygon.ts +2 -2
- package/src/exports.ts +18 -7
- package/src/plugins/tooltip.ts +4 -2
- package/src/registry/build-in.ts +4 -0
- package/src/runtime/animation.ts +16 -11
- package/src/runtime/data.ts +20 -13
- package/src/runtime/element.ts +44 -18
- package/src/runtime/graph.ts +52 -22
- package/src/runtime/layout.ts +7 -0
- package/src/transforms/base-transform.ts +2 -0
- package/src/transforms/collapse-expand-combo.ts +2 -0
- package/src/transforms/collapse-expand-node.ts +3 -0
- package/src/transforms/index.ts +3 -0
- package/src/transforms/position-radial-labels.ts +76 -0
- package/src/types/element.ts +2 -1
- package/src/utils/data.ts +49 -0
- package/src/utils/diff.ts +8 -2
- package/src/utils/point.ts +25 -7
- package/src/utils/position.ts +12 -0
- package/src/utils/relation.ts +22 -9
- package/src/utils/vector.ts +13 -0
- package/src/version.ts +1 -1
package/src/runtime/element.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
ElementType,
|
|
20
20
|
ID,
|
|
21
21
|
Node,
|
|
22
|
+
NodeLikeData,
|
|
22
23
|
State,
|
|
23
24
|
StyleIterationContext,
|
|
24
25
|
} from '../types';
|
|
@@ -287,7 +288,6 @@ export class ElementController {
|
|
|
287
288
|
const { animation, silence } = context;
|
|
288
289
|
|
|
289
290
|
const { type = 'draw' } = context;
|
|
290
|
-
const willRender = type === 'render';
|
|
291
291
|
|
|
292
292
|
return this.context.animation!.animate(
|
|
293
293
|
animation,
|
|
@@ -296,7 +296,7 @@ export class ElementController {
|
|
|
296
296
|
: {
|
|
297
297
|
before: () =>
|
|
298
298
|
this.emit(
|
|
299
|
-
new GraphLifeCycleEvent(GraphEvent.BEFORE_DRAW, { dataChanges, animation, render:
|
|
299
|
+
new GraphLifeCycleEvent(GraphEvent.BEFORE_DRAW, { dataChanges, animation, render: type === 'render' }),
|
|
300
300
|
context,
|
|
301
301
|
),
|
|
302
302
|
beforeAnimate: (animation) =>
|
|
@@ -305,7 +305,7 @@ export class ElementController {
|
|
|
305
305
|
this.emit(new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationType.DRAW, animation, drawData), context),
|
|
306
306
|
after: () =>
|
|
307
307
|
this.emit(
|
|
308
|
-
new GraphLifeCycleEvent(GraphEvent.AFTER_DRAW, { dataChanges, animation, render:
|
|
308
|
+
new GraphLifeCycleEvent(GraphEvent.AFTER_DRAW, { dataChanges, animation, render: type === 'render' }),
|
|
309
309
|
context,
|
|
310
310
|
),
|
|
311
311
|
},
|
|
@@ -433,8 +433,24 @@ export class ElementController {
|
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
+
private getUpdateStageStyle(elementType: ElementType, datum: ElementDatum, context: DrawContext) {
|
|
437
|
+
const { stage = 'update' } = context;
|
|
438
|
+
|
|
439
|
+
// 优化 translate 阶段,直接返回 x, y, z,避免计算样式
|
|
440
|
+
// Optimize the translate stage, return x, y, z directly to avoid calculating style
|
|
441
|
+
if (stage === 'translate') {
|
|
442
|
+
if (elementType === 'node' || elementType === 'combo') {
|
|
443
|
+
const { style: { x = 0, y = 0, z = 0 } = {} } = datum as NodeLikeData;
|
|
444
|
+
return { x, y, z };
|
|
445
|
+
} else return {};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return this.getElementComputedStyle(elementType, datum);
|
|
449
|
+
}
|
|
450
|
+
|
|
436
451
|
private updateElement(elementType: ElementType, datum: ElementDatum, context: DrawContext) {
|
|
437
452
|
const id = idOf(datum);
|
|
453
|
+
const { stage = 'update' } = context;
|
|
438
454
|
|
|
439
455
|
const element = this.getElement(id);
|
|
440
456
|
if (!element) return () => null;
|
|
@@ -442,7 +458,7 @@ export class ElementController {
|
|
|
442
458
|
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_UPDATE, elementType, datum), context);
|
|
443
459
|
|
|
444
460
|
const type = this.getElementType(elementType, datum);
|
|
445
|
-
const style = this.
|
|
461
|
+
const style = this.getUpdateStageStyle(elementType, datum, context);
|
|
446
462
|
|
|
447
463
|
// 如果类型不同,需要先销毁原有元素,再创建新元素
|
|
448
464
|
// If the type is different, you need to destroy the original element first, and then create a new element
|
|
@@ -454,8 +470,6 @@ export class ElementController {
|
|
|
454
470
|
this.createElement(elementType, datum, { animation: false, silence: true });
|
|
455
471
|
}
|
|
456
472
|
|
|
457
|
-
const { stage = 'update' } = context;
|
|
458
|
-
|
|
459
473
|
const exactStage = stage !== 'visibility' ? stage : style.visibility === 'hidden' ? 'hide' : 'show';
|
|
460
474
|
|
|
461
475
|
// 避免立即将 visibility 设置为 hidden,导致元素不可见,而是在 after 阶段再设置
|
|
@@ -587,9 +601,10 @@ export class ElementController {
|
|
|
587
601
|
public async collapseNode(id: ID, animation: boolean): Promise<void> {
|
|
588
602
|
const { model, layout } = this.context;
|
|
589
603
|
|
|
590
|
-
const
|
|
604
|
+
const preLayoutData = this.computeChangesAndDrawData({ stage: 'collapse', animation });
|
|
605
|
+
if (!preLayoutData) return;
|
|
591
606
|
|
|
592
|
-
this.markDestroyElement(
|
|
607
|
+
this.markDestroyElement(preLayoutData.drawData);
|
|
593
608
|
|
|
594
609
|
// 进行预布局,计算出所有元素的位置
|
|
595
610
|
// Perform pre-layout to calculate the position of all elements
|
|
@@ -597,7 +612,9 @@ export class ElementController {
|
|
|
597
612
|
model.updateData(result);
|
|
598
613
|
|
|
599
614
|
// 重新计算数据 / Recalculate data
|
|
600
|
-
const
|
|
615
|
+
const data = this.computeChangesAndDrawData({ stage: 'collapse', animation });
|
|
616
|
+
if (!data) return;
|
|
617
|
+
const { drawData } = data;
|
|
601
618
|
const { add, remove, update } = drawData;
|
|
602
619
|
this.markDestroyElement(drawData);
|
|
603
620
|
const context = { animation, stage: 'collapse', data: drawData } as const;
|
|
@@ -637,11 +654,14 @@ export class ElementController {
|
|
|
637
654
|
|
|
638
655
|
const position = positionOf(model.getNodeData([id])[0]);
|
|
639
656
|
|
|
657
|
+
const preLayoutData = this.computeChangesAndDrawData({ stage: 'expand', animation });
|
|
658
|
+
if (!preLayoutData) return;
|
|
659
|
+
|
|
640
660
|
// 首先创建展开的元素,然后进行预布局
|
|
641
661
|
// First create the expanded element, then perform pre-layout
|
|
642
662
|
const {
|
|
643
663
|
drawData: { add },
|
|
644
|
-
} =
|
|
664
|
+
} = preLayoutData;
|
|
645
665
|
this.createElements(add, { animation: false, stage: 'expand', target: id });
|
|
646
666
|
// 重置动画 / Reset animation
|
|
647
667
|
this.context.animation!.clear();
|
|
@@ -651,16 +671,16 @@ export class ElementController {
|
|
|
651
671
|
|
|
652
672
|
// 重新计算数据 / Recalculate data
|
|
653
673
|
this.computeStyle('expand');
|
|
654
|
-
const
|
|
674
|
+
const data = this.computeChangesAndDrawData({ stage: 'collapse', animation });
|
|
675
|
+
if (!data) return;
|
|
676
|
+
const { drawData } = data;
|
|
655
677
|
const { update } = drawData;
|
|
656
678
|
|
|
657
679
|
const context = { animation, stage: 'expand', data: drawData } as const;
|
|
658
680
|
|
|
659
|
-
//
|
|
660
|
-
add.edges.forEach((edge) =>
|
|
661
|
-
|
|
662
|
-
if (!update.edges.has(id)) update.edges.set(id, edge);
|
|
663
|
-
});
|
|
681
|
+
// 将新增节点/边添加到更新列表 / Add new nodes/edges to the update list
|
|
682
|
+
add.edges.forEach((edge) => update.edges.set(idOf(edge), edge));
|
|
683
|
+
add.nodes.forEach((node) => update.nodes.set(idOf(node), node));
|
|
664
684
|
|
|
665
685
|
this.updateElements(update, context);
|
|
666
686
|
|
|
@@ -693,7 +713,10 @@ export class ElementController {
|
|
|
693
713
|
collapsed: true,
|
|
694
714
|
});
|
|
695
715
|
|
|
696
|
-
const
|
|
716
|
+
const data = this.computeChangesAndDrawData({ stage: 'collapse', animation });
|
|
717
|
+
if (!data) return;
|
|
718
|
+
|
|
719
|
+
const { dataChanges, drawData } = data;
|
|
697
720
|
this.markDestroyElement(drawData);
|
|
698
721
|
const { update, remove } = drawData;
|
|
699
722
|
const context = { animation, stage: 'collapse', data: drawData } as const;
|
|
@@ -729,7 +752,10 @@ export class ElementController {
|
|
|
729
752
|
|
|
730
753
|
// 重新计算数据 / Recalculate data
|
|
731
754
|
this.computeStyle('expand');
|
|
732
|
-
const
|
|
755
|
+
const data = this.computeChangesAndDrawData({ stage: 'expand', animation });
|
|
756
|
+
if (!data) return;
|
|
757
|
+
|
|
758
|
+
const { dataChanges, drawData } = data;
|
|
733
759
|
const { add, update } = drawData;
|
|
734
760
|
const context = { animation, stage: 'expand', data: drawData, target: id } as const;
|
|
735
761
|
|
package/src/runtime/graph.ts
CHANGED
|
@@ -41,6 +41,7 @@ import type {
|
|
|
41
41
|
} from '../types';
|
|
42
42
|
import { isCollapsed } from '../utils/collapsibility';
|
|
43
43
|
import { sizeOf } from '../utils/dom';
|
|
44
|
+
import { getSubgraphRelatedEdges } from '../utils/edge';
|
|
44
45
|
import { GraphLifeCycleEvent, emit } from '../utils/event';
|
|
45
46
|
import { idOf } from '../utils/id';
|
|
46
47
|
import { format } from '../utils/print';
|
|
@@ -87,7 +88,7 @@ export class Graph extends EventEmitter {
|
|
|
87
88
|
constructor(options: GraphOptions) {
|
|
88
89
|
super();
|
|
89
90
|
this.options = Object.assign({}, Graph.defaultOptions, options);
|
|
90
|
-
this.
|
|
91
|
+
this._setOptions(this.options, true);
|
|
91
92
|
this.context.graph = this;
|
|
92
93
|
|
|
93
94
|
// Listening window.resize to autoResize.
|
|
@@ -117,32 +118,28 @@ export class Graph extends EventEmitter {
|
|
|
117
118
|
* @apiCategory option
|
|
118
119
|
*/
|
|
119
120
|
public setOptions(options: GraphOptions): void {
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
this._setOptions(options, false);
|
|
122
|
+
}
|
|
122
123
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (canvas) {
|
|
126
|
-
this.emit(GraphEvent.BEFORE_RENDERER_CHANGE, { renderer: this.options.renderer });
|
|
127
|
-
canvas.setRenderer(renderer);
|
|
128
|
-
this.emit(GraphEvent.AFTER_RENDERER_CHANGE, { renderer });
|
|
129
|
-
}
|
|
130
|
-
}
|
|
124
|
+
private _setOptions(options: GraphOptions, isInit: boolean) {
|
|
125
|
+
this.updateCanvas(options);
|
|
131
126
|
|
|
127
|
+
if (isInit) {
|
|
128
|
+
const { data } = options;
|
|
129
|
+
if (data) this.addData(data);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
132
|
Object.assign(this.options, options);
|
|
133
|
-
|
|
134
|
-
if (cursor) this.context.canvas?.setCursor(cursor);
|
|
133
|
+
const { behaviors, combo, data, edge, layout, node, plugins, theme, transforms } = options;
|
|
135
134
|
if (behaviors) this.setBehaviors(behaviors);
|
|
136
|
-
if (combo) this.setCombo(combo);
|
|
137
135
|
if (data) this.setData(data);
|
|
136
|
+
if (node) this.setNode(node);
|
|
138
137
|
if (edge) this.setEdge(edge);
|
|
138
|
+
if (combo) this.setCombo(combo);
|
|
139
139
|
if (layout) this.setLayout(layout);
|
|
140
|
-
if (node) this.setNode(node);
|
|
141
140
|
if (theme) this.setTheme(theme);
|
|
142
141
|
if (plugins) this.setPlugins(plugins);
|
|
143
142
|
if (transforms) this.setTransforms(transforms);
|
|
144
|
-
if (isNumber(width) || isNumber(height))
|
|
145
|
-
this.setSize(width ?? this.options.width ?? 0, height ?? this.options.height ?? 0);
|
|
146
143
|
}
|
|
147
144
|
|
|
148
145
|
/**
|
|
@@ -1015,10 +1012,19 @@ export class Graph extends EventEmitter {
|
|
|
1015
1012
|
private async initCanvas() {
|
|
1016
1013
|
if (this.context.canvas) return await this.context.canvas.ready;
|
|
1017
1014
|
|
|
1018
|
-
const {
|
|
1015
|
+
const {
|
|
1016
|
+
container = 'container',
|
|
1017
|
+
width,
|
|
1018
|
+
height,
|
|
1019
|
+
renderer,
|
|
1020
|
+
cursor,
|
|
1021
|
+
background,
|
|
1022
|
+
devicePixelRatio = window.devicePixelRatio ?? 1,
|
|
1023
|
+
} = this.options;
|
|
1019
1024
|
if (container instanceof Canvas) {
|
|
1020
1025
|
this.context.canvas = container;
|
|
1021
1026
|
if (cursor) container.setCursor(cursor);
|
|
1027
|
+
if (renderer) container.setRenderer(renderer);
|
|
1022
1028
|
await container.ready;
|
|
1023
1029
|
} else {
|
|
1024
1030
|
const $container = isString(container) ? document.getElementById(container!) : container;
|
|
@@ -1033,6 +1039,7 @@ export class Graph extends EventEmitter {
|
|
|
1033
1039
|
background,
|
|
1034
1040
|
renderer,
|
|
1035
1041
|
cursor,
|
|
1042
|
+
devicePixelRatio,
|
|
1036
1043
|
});
|
|
1037
1044
|
|
|
1038
1045
|
this.context.canvas = canvas;
|
|
@@ -1041,6 +1048,23 @@ export class Graph extends EventEmitter {
|
|
|
1041
1048
|
}
|
|
1042
1049
|
}
|
|
1043
1050
|
|
|
1051
|
+
private updateCanvas(options: GraphOptions) {
|
|
1052
|
+
const { renderer, cursor, height, width } = options;
|
|
1053
|
+
const canvas = this.context.canvas;
|
|
1054
|
+
if (!canvas) return;
|
|
1055
|
+
|
|
1056
|
+
if (renderer) {
|
|
1057
|
+
this.emit(GraphEvent.BEFORE_RENDERER_CHANGE, { renderer: this.options.renderer });
|
|
1058
|
+
canvas.setRenderer(renderer);
|
|
1059
|
+
this.emit(GraphEvent.AFTER_RENDERER_CHANGE, { renderer });
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
if (cursor) canvas.setCursor(cursor);
|
|
1063
|
+
|
|
1064
|
+
if (isNumber(width) || isNumber(height))
|
|
1065
|
+
this.setSize(width ?? this.options.width ?? 0, height ?? this.options.height ?? 0);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1044
1068
|
private initRuntime() {
|
|
1045
1069
|
this.context.options = this.options;
|
|
1046
1070
|
if (!this.context.batch) this.context.batch = new BatchController(this.context);
|
|
@@ -1620,7 +1644,7 @@ export class Graph extends EventEmitter {
|
|
|
1620
1644
|
public async frontElement(id: ID | ID[]): Promise<void> {
|
|
1621
1645
|
const ids = Array.isArray(id) ? id : [id];
|
|
1622
1646
|
const { model, element } = this.context;
|
|
1623
|
-
const
|
|
1647
|
+
const zIndexes: Record<ID, number> = {};
|
|
1624
1648
|
|
|
1625
1649
|
ids.map((_id) => {
|
|
1626
1650
|
const zIndex = element!.getFrontZIndex(_id);
|
|
@@ -1630,12 +1654,18 @@ export class Graph extends EventEmitter {
|
|
|
1630
1654
|
const combos = [ancestor, ...model.getDescendantsData(idOf(ancestor))];
|
|
1631
1655
|
const delta = zIndex - element!.getElementZIndex(_id);
|
|
1632
1656
|
combos.forEach((combo) => {
|
|
1633
|
-
|
|
1657
|
+
zIndexes[idOf(combo)] = this.getElementZIndex(idOf(combo)) + delta;
|
|
1658
|
+
});
|
|
1659
|
+
|
|
1660
|
+
const { internal } = getSubgraphRelatedEdges(combos.map(idOf), (id) => model.getRelatedEdgesData(id));
|
|
1661
|
+
internal.forEach((edge) => {
|
|
1662
|
+
const edgeId = idOf(edge);
|
|
1663
|
+
zIndexes[edgeId] = this.getElementZIndex(edgeId) + delta;
|
|
1634
1664
|
});
|
|
1635
|
-
} else
|
|
1665
|
+
} else zIndexes[_id] = zIndex;
|
|
1636
1666
|
});
|
|
1637
1667
|
|
|
1638
|
-
await this.setElementZIndex(
|
|
1668
|
+
await this.setElementZIndex(zIndexes);
|
|
1639
1669
|
}
|
|
1640
1670
|
|
|
1641
1671
|
/**
|
package/src/runtime/layout.ts
CHANGED
|
@@ -69,6 +69,13 @@ export class LayoutController {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
emit(graph, new GraphLifeCycleEvent(GraphEvent.AFTER_LAYOUT));
|
|
72
|
+
this.transformDataAfterLayout();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private transformDataAfterLayout() {
|
|
76
|
+
const transforms = this.context.transform.getTransformInstance();
|
|
77
|
+
|
|
78
|
+
Object.values(transforms).forEach((transform) => transform.afterLayout());
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { COMBO_KEY } from '../constants';
|
|
1
2
|
import type { DrawContext } from '../runtime/element';
|
|
2
3
|
import type { ComboData } from '../spec';
|
|
3
4
|
import { isCollapsed } from '../utils/collapsibility';
|
|
@@ -16,6 +17,7 @@ import { reassignTo } from './utils';
|
|
|
16
17
|
export class CollapseExpandCombo extends BaseTransform {
|
|
17
18
|
public beforeDraw(input: DrawData, context: DrawContext): DrawData {
|
|
18
19
|
if (context.stage === 'visibility') return input;
|
|
20
|
+
if (!this.context.model.model.hasTreeStructure(COMBO_KEY)) return input;
|
|
19
21
|
|
|
20
22
|
const { model } = this.context;
|
|
21
23
|
const { add, update } = input;
|
|
@@ -47,6 +47,9 @@ export class CollapseExpandNode extends BaseTransform {
|
|
|
47
47
|
|
|
48
48
|
public beforeDraw(input: DrawData): DrawData {
|
|
49
49
|
const { graph, model } = this.context;
|
|
50
|
+
|
|
51
|
+
if (!model.model.hasTreeStructure(TREE_KEY)) return input;
|
|
52
|
+
|
|
50
53
|
const {
|
|
51
54
|
add: { nodes: nodesToAdd, edges: edgesToAdd },
|
|
52
55
|
update: { nodes: nodesToUpdate },
|
package/src/transforms/index.ts
CHANGED
|
@@ -3,7 +3,10 @@ export { BaseTransform } from './base-transform';
|
|
|
3
3
|
export { CollapseExpandCombo } from './collapse-expand-combo';
|
|
4
4
|
export { CollapseExpandNode } from './collapse-expand-node';
|
|
5
5
|
export { GetEdgeActualEnds } from './get-edge-actual-ends';
|
|
6
|
+
export { PositionRadialLabels } from './position-radial-labels';
|
|
6
7
|
export { ProcessParallelEdges } from './process-parallel-edges';
|
|
7
8
|
export { UpdateRelatedEdge } from './update-related-edge';
|
|
8
9
|
|
|
9
10
|
export type { BaseTransformOptions } from './base-transform';
|
|
11
|
+
export type { PositionRadialLabelsOptions } from './position-radial-labels';
|
|
12
|
+
export type { ProcessParallelEdgesOptions } from './process-parallel-edges';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { rad2deg } from '@antv/g';
|
|
2
|
+
import type { RuntimeContext } from '../runtime/types';
|
|
3
|
+
import type { NodeData } from '../spec';
|
|
4
|
+
import { idOf } from '../utils/id';
|
|
5
|
+
import { positionOf } from '../utils/position';
|
|
6
|
+
import { parseSize } from '../utils/size';
|
|
7
|
+
import { rad, subtract } from '../utils/vector';
|
|
8
|
+
import type { BaseTransformOptions } from './base-transform';
|
|
9
|
+
import { BaseTransform } from './base-transform';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* <zh/> 根据径向布局自动调整节点标签样式的配置项
|
|
13
|
+
*
|
|
14
|
+
* <en/> Options for automatically adjusting the style of node labels according to the radial layout
|
|
15
|
+
*/
|
|
16
|
+
export interface PositionRadialLabelsOptions extends BaseTransformOptions {
|
|
17
|
+
/**
|
|
18
|
+
* <zh/> 偏移量
|
|
19
|
+
*
|
|
20
|
+
* <en/> Offset
|
|
21
|
+
*/
|
|
22
|
+
offset?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* <zh/> 根据径向布局自动调整节点标签样式,包括位置和旋转角度
|
|
27
|
+
*
|
|
28
|
+
* <en/> Automatically adjust the style of node labels according to the radial layout, including position and rotation angle
|
|
29
|
+
*/
|
|
30
|
+
export class PositionRadialLabels extends BaseTransform<PositionRadialLabelsOptions> {
|
|
31
|
+
static defaultOptions: Partial<PositionRadialLabelsOptions> = {
|
|
32
|
+
offset: 5,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
constructor(context: RuntimeContext, options: PositionRadialLabelsOptions) {
|
|
36
|
+
super(context, Object.assign({}, PositionRadialLabels.defaultOptions, options));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private get ref(): NodeData {
|
|
40
|
+
return this.context.model.getRootsData()[0];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public afterLayout() {
|
|
44
|
+
const refPoint = positionOf(this.ref);
|
|
45
|
+
|
|
46
|
+
const { graph, model } = this.context;
|
|
47
|
+
const data = model.getData();
|
|
48
|
+
|
|
49
|
+
data.nodes?.forEach((datum) => {
|
|
50
|
+
if (idOf(datum) === idOf(this.ref)) return;
|
|
51
|
+
|
|
52
|
+
const radian = rad(subtract(positionOf(datum), refPoint));
|
|
53
|
+
const isLeft = Math.abs(radian) > Math.PI / 2;
|
|
54
|
+
|
|
55
|
+
const isLeaf = !datum.children || datum.children.length === 0;
|
|
56
|
+
const nodeHalfWidth = parseSize(graph.getElementRenderStyle(idOf(datum)).size)[0] / 2;
|
|
57
|
+
const offset = (isLeaf ? 1 : -1) * (nodeHalfWidth + this.options.offset);
|
|
58
|
+
|
|
59
|
+
const translate = `translate(${offset * Math.cos(radian)},${offset * Math.sin(radian)})`;
|
|
60
|
+
const rotate = `rotate(${isLeft ? rad2deg(radian) + 180 : rad2deg(radian)}deg)`;
|
|
61
|
+
|
|
62
|
+
model.updateNodeData([
|
|
63
|
+
{
|
|
64
|
+
id: idOf(datum),
|
|
65
|
+
style: {
|
|
66
|
+
labelTextAlign: isLeft === isLeaf ? 'right' : 'left',
|
|
67
|
+
labelTextBaseline: 'middle',
|
|
68
|
+
labelTransform: `${translate} ${rotate}`,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
graph.draw();
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/types/element.ts
CHANGED
|
@@ -29,13 +29,14 @@ export interface Node extends DisplayObject, ElementHooks, ElementMethods {
|
|
|
29
29
|
*
|
|
30
30
|
* <en/> Get the intersection point
|
|
31
31
|
* @param point - <zh/> 外部位置 | <en/> external position
|
|
32
|
+
* @param useExtendedLine - <zh/> 是否使用延长线 | <en/> whether to use the extended line
|
|
32
33
|
* @returns <zh/> 交点位置 | <en/> intersection point
|
|
33
34
|
* @remarks
|
|
34
35
|
* <zh/> 给定一个外部位置,返回当前节点与该位置的连边与节点的交点位置
|
|
35
36
|
*
|
|
36
37
|
* <en/> Given an external position, return the intersection point of the edge between the current node and the position and the node
|
|
37
38
|
*/
|
|
38
|
-
getIntersectPoint(point: Point): Point;
|
|
39
|
+
getIntersectPoint(point: Point, useExtendedLine?: boolean): Point;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
/**
|
package/src/utils/data.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { get } from '@antv/util';
|
|
2
2
|
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
|
|
3
|
+
import type { ElementDatum, ID } from '../types';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* <zh/> 合并两个 节点/边/Combo 的数据
|
|
@@ -62,3 +63,51 @@ export function cloneElementData<T extends NodeData | EdgeData | ComboData>(data
|
|
|
62
63
|
export function isEmptyData(data: GraphData) {
|
|
63
64
|
return !get(data, ['nodes', 'length']) && !get(data, ['edges', 'length']) && !get(data, ['combos', 'length']);
|
|
64
65
|
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* <zh/> 判断两个元素数据是否相等
|
|
69
|
+
*
|
|
70
|
+
* <en/> Determine if two element data are equal
|
|
71
|
+
* @param original - <zh/> 原始数据 | <en/> original data
|
|
72
|
+
* @param modified - <zh/> 修改后的数据 | <en/> modified data
|
|
73
|
+
* @returns <zh/> 是否相等 | <en/> is equal
|
|
74
|
+
* @remarks
|
|
75
|
+
* <zh/> 相比于 isEqual,这个方法不会比较更下层的数据
|
|
76
|
+
*
|
|
77
|
+
* <en/> Compared to isEqual, this method does not compare data at a lower level
|
|
78
|
+
*/
|
|
79
|
+
export function isElementDataEqual(original: Partial<ElementDatum> = {}, modified: Partial<ElementDatum> = {}) {
|
|
80
|
+
const {
|
|
81
|
+
states: originalStates = [],
|
|
82
|
+
data: originalData = {},
|
|
83
|
+
style: originalStyle = {},
|
|
84
|
+
children: originalChildren = [],
|
|
85
|
+
...originalAttrs
|
|
86
|
+
} = original;
|
|
87
|
+
const {
|
|
88
|
+
states: modifiedStates = [],
|
|
89
|
+
data: modifiedData = {},
|
|
90
|
+
style: modifiedStyle = {},
|
|
91
|
+
children: modifiedChildren = [],
|
|
92
|
+
...modifiedAttrs
|
|
93
|
+
} = modified;
|
|
94
|
+
|
|
95
|
+
const isArrayEqual = (arr1: unknown[], arr2: unknown[]) => {
|
|
96
|
+
if (arr1.length !== arr2.length) return false;
|
|
97
|
+
return arr1.every((item, index) => item === arr2[index]);
|
|
98
|
+
};
|
|
99
|
+
const isObjectEqual = (obj1: Record<string, unknown>, obj2: Record<string, unknown>) => {
|
|
100
|
+
const keys1 = Object.keys(obj1);
|
|
101
|
+
const keys2 = Object.keys(obj2);
|
|
102
|
+
if (keys1.length !== keys2.length) return false;
|
|
103
|
+
return keys1.every((key) => obj1[key] === obj2[key]);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
if (!isObjectEqual(originalAttrs, modifiedAttrs)) return false;
|
|
107
|
+
if (!isArrayEqual(originalChildren as ID[], modifiedChildren as ID[])) return false;
|
|
108
|
+
if (!isArrayEqual(originalStates, modifiedStates)) return false;
|
|
109
|
+
if (!isObjectEqual(originalData, modifiedData)) return false;
|
|
110
|
+
if (!isObjectEqual(originalStyle, modifiedStyle)) return false;
|
|
111
|
+
|
|
112
|
+
return true;
|
|
113
|
+
}
|
package/src/utils/diff.ts
CHANGED
|
@@ -7,9 +7,15 @@ import { isEqual } from '@antv/util';
|
|
|
7
7
|
* @param original - <zh/> 原始数组 | <en/> original array
|
|
8
8
|
* @param modified - <zh/> 修改后的数组 | <en/> modified array
|
|
9
9
|
* @param key - <zh/> 比较的 key | <en/> key to compare
|
|
10
|
+
* @param comparator - <zh/> 比较函数 | <en/> compare function
|
|
10
11
|
* @returns <zh/> 数组差异 | <en/> array diff
|
|
11
12
|
*/
|
|
12
|
-
export function arrayDiff<T>(
|
|
13
|
+
export function arrayDiff<T>(
|
|
14
|
+
original: T[],
|
|
15
|
+
modified: T[],
|
|
16
|
+
key: (d: T) => string | number,
|
|
17
|
+
comparator: (a?: T, b?: T) => boolean = isEqual,
|
|
18
|
+
) {
|
|
13
19
|
const originalMap = new Map(original.map((d) => [key(d), d]));
|
|
14
20
|
const modifiedMap = new Map(modified.map((d) => [key(d), d]));
|
|
15
21
|
|
|
@@ -23,7 +29,7 @@ export function arrayDiff<T>(original: T[], modified: T[], key: (d: T) => string
|
|
|
23
29
|
|
|
24
30
|
modifiedSet.forEach((key) => {
|
|
25
31
|
if (originalSet.has(key)) {
|
|
26
|
-
if (!
|
|
32
|
+
if (!comparator(originalMap.get(key), modifiedMap.get(key))) {
|
|
27
33
|
update.push(modifiedMap.get(key)!);
|
|
28
34
|
} else {
|
|
29
35
|
keep.push(modifiedMap.get(key)!);
|
package/src/utils/point.ts
CHANGED
|
@@ -132,6 +132,18 @@ export function isCollinear(p1: Point, p2: Point, p3: Point): boolean {
|
|
|
132
132
|
return isLinesParallel([p1, p2], [p2, p3]);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* <zh/> 计算一个点相对于另一个点的中心对称点
|
|
137
|
+
*
|
|
138
|
+
* <en/> Calculate the center symmetric point of a point relative to another point
|
|
139
|
+
* @param p - <zh/> 要计算的点 | <en/> the point to calculate
|
|
140
|
+
* @param center - <zh/> 中心点 | <en/> the center point
|
|
141
|
+
* @returns <zh/> 中心对称点 | <en/> the center symmetric point
|
|
142
|
+
*/
|
|
143
|
+
export function getSymmetricPoint(p: Point, center: Point): Point {
|
|
144
|
+
return [2 * center[0] - p[0], 2 * center[1] - p[1]];
|
|
145
|
+
}
|
|
146
|
+
|
|
135
147
|
/**
|
|
136
148
|
* <zh/> 获取从多边形中心到给定点的连线与多边形边缘的交点
|
|
137
149
|
*
|
|
@@ -140,6 +152,7 @@ export function isCollinear(p1: Point, p2: Point, p3: Point): boolean {
|
|
|
140
152
|
* @param center - <zh/> 多边形中心 | <en/> the center of the polygon
|
|
141
153
|
* @param points - <zh/> 多边形顶点 | <en/> the vertices of the polygon
|
|
142
154
|
* @param isRelativePos - <zh/> 顶点坐标是否相对中心点 | <en/> whether the vertex coordinates are relative to the center point
|
|
155
|
+
* @param useExtendedLine - <zh/> 是否使用延长线 | <en/> whether to use the extended line
|
|
143
156
|
* @returns <zh/> 交点与相交线段 | <en/> intersection and intersecting line segment
|
|
144
157
|
*/
|
|
145
158
|
export function getPolygonIntersectPoint(
|
|
@@ -147,6 +160,7 @@ export function getPolygonIntersectPoint(
|
|
|
147
160
|
center: Point,
|
|
148
161
|
points: Point[],
|
|
149
162
|
isRelativePos = true,
|
|
163
|
+
useExtendedLine = false,
|
|
150
164
|
): { point: Point; line?: LineSegment } {
|
|
151
165
|
for (let i = 0; i < points.length; i++) {
|
|
152
166
|
let start = points[i];
|
|
@@ -157,7 +171,8 @@ export function getPolygonIntersectPoint(
|
|
|
157
171
|
end = add(center, end);
|
|
158
172
|
}
|
|
159
173
|
|
|
160
|
-
const
|
|
174
|
+
const refP = useExtendedLine ? getSymmetricPoint(p, center) : p;
|
|
175
|
+
const intersect = getLinesIntersection([center, refP], [start, end]);
|
|
161
176
|
if (intersect) {
|
|
162
177
|
return {
|
|
163
178
|
point: intersect,
|
|
@@ -200,14 +215,15 @@ export function isPointInPolygon(point: Point, points: Point[], start?: number,
|
|
|
200
215
|
}
|
|
201
216
|
|
|
202
217
|
/**
|
|
203
|
-
* <zh/>
|
|
218
|
+
* <zh/> 获取给定点到矩形中心的连线与矩形边缘的交点
|
|
204
219
|
*
|
|
205
220
|
* <en/> Gets the intersection point between the line from the center of a rectangle to a given point and the rectangle's edge
|
|
206
221
|
* @param p - <zh/> 从矩形中心到矩形边缘的连线的外部点 | <en/> The point outside the rectangle from which the line to the rectangle's center is drawn
|
|
207
222
|
* @param bbox - <zh/> 矩形包围盒 | <en/> the bounding box of the rectangle
|
|
223
|
+
* @param useExtendedLine - <zh/> 是否使用延长线 | <en/> whether to use the extended line
|
|
208
224
|
* @returns <zh/> 交点 | <en/> intersection
|
|
209
225
|
*/
|
|
210
|
-
export function getRectIntersectPoint(p: Point, bbox: AABB): Point {
|
|
226
|
+
export function getRectIntersectPoint(p: Point, bbox: AABB, useExtendedLine = false): Point {
|
|
211
227
|
const center = getXYByPlacement(bbox, 'center');
|
|
212
228
|
const corners = [
|
|
213
229
|
getXYByPlacement(bbox, 'left-top'),
|
|
@@ -215,21 +231,23 @@ export function getRectIntersectPoint(p: Point, bbox: AABB): Point {
|
|
|
215
231
|
getXYByPlacement(bbox, 'right-bottom'),
|
|
216
232
|
getXYByPlacement(bbox, 'left-bottom'),
|
|
217
233
|
];
|
|
218
|
-
return getPolygonIntersectPoint(p, center, corners, false).point;
|
|
234
|
+
return getPolygonIntersectPoint(p, center, corners, false, useExtendedLine).point;
|
|
219
235
|
}
|
|
220
236
|
|
|
221
237
|
/**
|
|
222
|
-
* <zh/>
|
|
238
|
+
* <zh/> 获取给定点到椭圆中心的连线与椭圆边缘的交点
|
|
223
239
|
*
|
|
224
240
|
* <en/> Gets the intersection point between the line from the center of an ellipse to a given point and the ellipse's edge
|
|
225
241
|
* @param p - <zh/> 从椭圆中心到椭圆边缘的连线的外部点 | <en/> The point outside the ellipse from which the line to the ellipse's center is drawn
|
|
226
242
|
* The point outside the ellipse from which the line to the ellipse's center is drawn.
|
|
227
243
|
* @param bbox - <zh/> 椭圆包围盒 | <en/> the bounding box of the ellipse
|
|
244
|
+
* @param useExtendedLine - <zh/> 是否使用延长线 | <en/> whether to use the extended line
|
|
228
245
|
* @returns <zh/> 交点 | <en/> intersection
|
|
229
246
|
*/
|
|
230
|
-
export function getEllipseIntersectPoint(p: Point, bbox: AABB): Point {
|
|
247
|
+
export function getEllipseIntersectPoint(p: Point, bbox: AABB, useExtendedLine = false): Point {
|
|
231
248
|
const center = bbox.center;
|
|
232
|
-
const
|
|
249
|
+
const refP = useExtendedLine ? getSymmetricPoint(p, center) : p;
|
|
250
|
+
const vec = subtract(refP, bbox.center);
|
|
233
251
|
const angle = Math.atan2(vec[1], vec[0]);
|
|
234
252
|
if (isNaN(angle)) return center;
|
|
235
253
|
|
package/src/utils/position.ts
CHANGED
|
@@ -15,6 +15,18 @@ export function positionOf(datum: NodeLikeData): Point {
|
|
|
15
15
|
return [+x, +y, +z];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* <zh/> 检查数据是否有位置坐标
|
|
20
|
+
*
|
|
21
|
+
* <en/> Check if the data has a position coordinate
|
|
22
|
+
* @param datum - <zh/> 节点/ combo 的数据 | <en/> data of node/combo
|
|
23
|
+
* @returns - <zh/> 是否有位置坐标 | <en/> Whether there is a position coordinate
|
|
24
|
+
*/
|
|
25
|
+
export function hasPosition(datum: NodeLikeData): boolean {
|
|
26
|
+
const { x, y, z } = datum.style || {};
|
|
27
|
+
return x !== undefined || y !== undefined || z !== undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
/**
|
|
19
31
|
* <zh/> 获取相对位置坐标
|
|
20
32
|
*
|