@antv/infographic 0.2.13 → 0.2.15
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/README.md +12 -5
- package/README.zh-CN.md +12 -5
- package/dist/infographic.min.js +180 -171
- package/dist/infographic.min.js.map +1 -1
- package/esm/designs/structures/index.d.ts +1 -0
- package/esm/designs/structures/index.js +1 -0
- package/esm/designs/structures/relation-dagre-flow.js +4 -139
- package/esm/designs/structures/sequence-interaction.d.ts +54 -0
- package/esm/designs/structures/sequence-interaction.js +440 -0
- package/esm/designs/utils/geometry.d.ts +44 -0
- package/esm/designs/utils/geometry.js +244 -0
- package/esm/designs/utils/index.d.ts +1 -0
- package/esm/designs/utils/index.js +1 -0
- package/esm/editor/commands/UpdateOptions.d.ts +4 -4
- package/esm/editor/commands/UpdateOptions.js +6 -3
- package/esm/editor/editor.d.ts +5 -1
- package/esm/editor/editor.js +16 -5
- package/esm/editor/index.d.ts +1 -0
- package/esm/editor/index.js +1 -0
- package/esm/editor/interactions/brush-select.d.ts +0 -1
- package/esm/editor/interactions/brush-select.js +2 -10
- package/esm/editor/interactions/drag-canvas.d.ts +35 -0
- package/esm/editor/interactions/drag-canvas.js +161 -0
- package/esm/editor/interactions/drag-element.js +4 -3
- package/esm/editor/interactions/index.d.ts +1 -0
- package/esm/editor/interactions/index.js +1 -0
- package/esm/editor/interactions/zoom-wheel.d.ts +9 -0
- package/esm/editor/interactions/zoom-wheel.js +32 -15
- package/esm/editor/managers/index.d.ts +1 -0
- package/esm/editor/managers/index.js +1 -0
- package/esm/editor/managers/state.d.ts +4 -2
- package/esm/editor/managers/state.js +14 -13
- package/esm/editor/managers/sync-registry.d.ts +16 -0
- package/esm/editor/managers/sync-registry.js +51 -0
- package/esm/editor/plugins/{edit-bar/components → components}/button.js +1 -1
- package/esm/editor/plugins/{edit-bar/components → components}/color-picker.js +1 -1
- package/esm/editor/plugins/{edit-bar/components → components}/icons.d.ts +1 -0
- package/esm/editor/plugins/{edit-bar/components → components}/icons.js +1 -0
- package/esm/editor/plugins/{edit-bar/components → components}/popover.js +2 -2
- package/esm/editor/plugins/{edit-bar/components → components}/select.js +1 -1
- package/esm/editor/plugins/core-sync.d.ts +8 -0
- package/esm/editor/plugins/core-sync.js +30 -0
- package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-color.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-family.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-size.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +1 -1
- package/esm/editor/plugins/edit-bar/index.d.ts +2 -2
- package/esm/editor/plugins/edit-bar/index.js +1 -1
- package/esm/editor/plugins/index.d.ts +2 -0
- package/esm/editor/plugins/index.js +2 -0
- package/esm/editor/plugins/reset-viewbox.d.ts +33 -0
- package/esm/editor/plugins/reset-viewbox.js +186 -0
- package/esm/editor/types/editor.d.ts +14 -0
- package/esm/editor/types/index.d.ts +1 -0
- package/esm/editor/types/interaction.d.ts +9 -0
- package/esm/editor/types/state.d.ts +4 -2
- package/esm/editor/types/sync.d.ts +27 -0
- package/esm/editor/types/sync.js +1 -0
- package/esm/editor/utils/data.js +3 -1
- package/esm/editor/utils/event.d.ts +1 -0
- package/esm/editor/utils/event.js +8 -0
- package/esm/editor/utils/index.d.ts +1 -0
- package/esm/editor/utils/index.js +1 -0
- package/esm/editor/utils/object.d.ts +15 -0
- package/esm/editor/utils/object.js +77 -0
- package/esm/index.d.ts +4 -3
- package/esm/index.js +3 -2
- package/esm/options/types.d.ts +7 -0
- package/esm/runtime/Infographic.js +20 -7
- package/esm/runtime/options.js +7 -2
- package/esm/syntax/index.js +40 -20
- package/esm/syntax/relations.js +26 -2
- package/esm/syntax/schema.js +1 -0
- package/esm/templates/built-in.js +27 -2
- package/esm/templates/sequence-interaction.d.ts +2 -0
- package/esm/templates/sequence-interaction.js +76 -0
- package/esm/types/data.d.ts +1 -0
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/measure-text.js +40 -9
- package/esm/utils/padding.d.ts +1 -0
- package/esm/utils/padding.js +6 -2
- package/esm/utils/types.d.ts +16 -0
- package/esm/utils/types.js +12 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/designs/structures/index.d.ts +1 -0
- package/lib/designs/structures/index.js +1 -0
- package/lib/designs/structures/relation-dagre-flow.js +5 -140
- package/lib/designs/structures/sequence-interaction.d.ts +54 -0
- package/lib/designs/structures/sequence-interaction.js +444 -0
- package/lib/designs/utils/geometry.d.ts +44 -0
- package/lib/designs/utils/geometry.js +256 -0
- package/lib/designs/utils/index.d.ts +1 -0
- package/lib/designs/utils/index.js +1 -0
- package/lib/editor/commands/UpdateOptions.d.ts +4 -4
- package/lib/editor/commands/UpdateOptions.js +6 -3
- package/lib/editor/editor.d.ts +5 -1
- package/lib/editor/editor.js +16 -5
- package/lib/editor/index.d.ts +1 -0
- package/lib/editor/index.js +1 -0
- package/lib/editor/interactions/brush-select.d.ts +0 -1
- package/lib/editor/interactions/brush-select.js +1 -9
- package/lib/editor/interactions/drag-canvas.d.ts +35 -0
- package/lib/editor/interactions/drag-canvas.js +165 -0
- package/lib/editor/interactions/drag-element.js +4 -3
- package/lib/editor/interactions/index.d.ts +1 -0
- package/lib/editor/interactions/index.js +3 -1
- package/lib/editor/interactions/zoom-wheel.d.ts +9 -0
- package/lib/editor/interactions/zoom-wheel.js +32 -15
- package/lib/editor/managers/index.d.ts +1 -0
- package/lib/editor/managers/index.js +1 -0
- package/lib/editor/managers/state.d.ts +4 -2
- package/lib/editor/managers/state.js +12 -11
- package/lib/editor/managers/sync-registry.d.ts +16 -0
- package/lib/editor/managers/sync-registry.js +55 -0
- package/lib/editor/plugins/{edit-bar/components → components}/button.js +1 -1
- package/lib/editor/plugins/{edit-bar/components → components}/color-picker.js +1 -1
- package/lib/editor/plugins/{edit-bar/components → components}/icons.d.ts +1 -0
- package/lib/editor/plugins/{edit-bar/components → components}/icons.js +2 -1
- package/lib/editor/plugins/{edit-bar/components → components}/popover.js +2 -2
- package/lib/editor/plugins/{edit-bar/components → components}/select.js +1 -1
- package/lib/editor/plugins/core-sync.d.ts +8 -0
- package/lib/editor/plugins/core-sync.js +34 -0
- package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-color.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-family.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-size.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +1 -1
- package/lib/editor/plugins/edit-bar/index.d.ts +2 -2
- package/lib/editor/plugins/edit-bar/index.js +1 -1
- package/lib/editor/plugins/index.d.ts +2 -0
- package/lib/editor/plugins/index.js +5 -1
- package/lib/editor/plugins/reset-viewbox.d.ts +33 -0
- package/lib/editor/plugins/reset-viewbox.js +190 -0
- package/lib/editor/types/editor.d.ts +14 -0
- package/lib/editor/types/index.d.ts +1 -0
- package/lib/editor/types/interaction.d.ts +9 -0
- package/lib/editor/types/state.d.ts +4 -2
- package/lib/editor/types/sync.d.ts +27 -0
- package/lib/editor/types/sync.js +2 -0
- package/lib/editor/utils/data.js +3 -1
- package/lib/editor/utils/event.d.ts +1 -0
- package/lib/editor/utils/event.js +9 -0
- package/lib/editor/utils/index.d.ts +1 -0
- package/lib/editor/utils/index.js +1 -0
- package/lib/editor/utils/object.d.ts +15 -0
- package/lib/editor/utils/object.js +80 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +9 -2
- package/lib/options/types.d.ts +7 -0
- package/lib/runtime/Infographic.js +19 -6
- package/lib/runtime/options.js +6 -1
- package/lib/syntax/index.js +40 -20
- package/lib/syntax/relations.js +26 -2
- package/lib/syntax/schema.js +1 -0
- package/lib/templates/built-in.js +27 -2
- package/lib/templates/sequence-interaction.d.ts +2 -0
- package/lib/templates/sequence-interaction.js +79 -0
- package/lib/types/data.d.ts +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/measure-text.js +39 -8
- package/lib/utils/padding.d.ts +1 -0
- package/lib/utils/padding.js +7 -2
- package/lib/utils/types.d.ts +16 -0
- package/lib/utils/types.js +13 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/designs/structures/index.ts +1 -0
- package/src/designs/structures/relation-dagre-flow.tsx +14 -178
- package/src/designs/structures/sequence-interaction.tsx +885 -0
- package/src/designs/utils/geometry.tsx +315 -0
- package/src/designs/utils/index.ts +1 -0
- package/src/editor/commands/UpdateOptions.ts +11 -6
- package/src/editor/editor.ts +26 -5
- package/src/editor/index.ts +1 -0
- package/src/editor/interactions/brush-select.ts +2 -8
- package/src/editor/interactions/drag-canvas.ts +203 -0
- package/src/editor/interactions/drag-element.ts +5 -4
- package/src/editor/interactions/index.ts +1 -0
- package/src/editor/interactions/zoom-wheel.ts +49 -13
- package/src/editor/managers/index.ts +1 -0
- package/src/editor/managers/state.ts +21 -21
- package/src/editor/managers/sync-registry.ts +66 -0
- package/src/editor/plugins/{edit-bar/components → components}/button.ts +1 -1
- package/src/editor/plugins/{edit-bar/components → components}/color-picker.ts +1 -1
- package/src/editor/plugins/{edit-bar/components → components}/icons.ts +4 -0
- package/src/editor/plugins/{edit-bar/components → components}/popover.ts +2 -2
- package/src/editor/plugins/{edit-bar/components → components}/select.ts +1 -1
- package/src/editor/plugins/core-sync.ts +44 -0
- package/src/editor/plugins/edit-bar/edit-items/align-elements.ts +2 -2
- package/src/editor/plugins/edit-bar/edit-items/font-align.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-color.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-family.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-size.ts +3 -3
- package/src/editor/plugins/edit-bar/edit-items/icon-color.ts +1 -1
- package/src/editor/plugins/edit-bar/index.ts +2 -2
- package/src/editor/plugins/index.ts +2 -0
- package/src/editor/plugins/reset-viewbox.ts +258 -0
- package/src/editor/types/editor.ts +18 -0
- package/src/editor/types/index.ts +1 -0
- package/src/editor/types/interaction.ts +31 -0
- package/src/editor/types/state.ts +14 -2
- package/src/editor/types/sync.ts +33 -0
- package/src/editor/utils/data.ts +2 -1
- package/src/editor/utils/event.ts +7 -0
- package/src/editor/utils/index.ts +1 -0
- package/src/editor/utils/object.ts +116 -0
- package/src/index.ts +26 -2
- package/src/options/types.ts +11 -0
- package/src/runtime/Infographic.tsx +27 -17
- package/src/runtime/options.ts +8 -1
- package/src/syntax/index.ts +51 -18
- package/src/syntax/relations.ts +29 -2
- package/src/syntax/schema.ts +1 -0
- package/src/templates/built-in.ts +30 -0
- package/src/templates/sequence-interaction.ts +101 -0
- package/src/types/data.ts +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/measure-text.ts +41 -9
- package/src/utils/padding.ts +10 -2
- package/src/utils/types.ts +61 -0
- package/src/version.ts +1 -1
- /package/esm/editor/plugins/{edit-bar/components → components}/button.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/color-picker.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/index.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/index.js +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/popover.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/select.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/button.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/color-picker.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/index.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/index.js +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/popover.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/select.d.ts +0 -0
- /package/src/editor/plugins/{edit-bar/components → components}/index.ts +0 -0
|
@@ -0,0 +1,885 @@
|
|
|
1
|
+
import type { ComponentType, JSXElement } from '../../jsx';
|
|
2
|
+
import { Defs, getElementBounds, Group, Path, Rect, Text } from '../../jsx';
|
|
3
|
+
import type { RelationEdgeDatum } from '../../types';
|
|
4
|
+
import {
|
|
5
|
+
BtnAdd,
|
|
6
|
+
BtnRemove,
|
|
7
|
+
BtnsGroup,
|
|
8
|
+
ItemLabel,
|
|
9
|
+
ItemsGroup,
|
|
10
|
+
} from '../components';
|
|
11
|
+
import { FlexLayout } from '../layouts';
|
|
12
|
+
import {
|
|
13
|
+
createArrowElements,
|
|
14
|
+
getColorPrimary,
|
|
15
|
+
getEdgePathD,
|
|
16
|
+
getLabelPosition,
|
|
17
|
+
getNodesAnchors,
|
|
18
|
+
getPaletteColor,
|
|
19
|
+
getTangentAngle,
|
|
20
|
+
getThemeColors,
|
|
21
|
+
} from '../utils';
|
|
22
|
+
import { registerStructure } from './registry';
|
|
23
|
+
import type { BaseStructureProps } from './types';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 泳道内的节点数据
|
|
27
|
+
*/
|
|
28
|
+
export interface InteractionChildDatum {
|
|
29
|
+
id: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
desc?: string;
|
|
32
|
+
icon?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 手动指定节点的垂直顺序(层级),默认为数组索引
|
|
35
|
+
* 相同 step 的节点会处于同一高度
|
|
36
|
+
*/
|
|
37
|
+
step?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 泳道数据(顶层item)
|
|
42
|
+
* label 作为泳道标题
|
|
43
|
+
* children 作为泳道内的节点列表
|
|
44
|
+
*/
|
|
45
|
+
export interface InteractionLaneDatum {
|
|
46
|
+
label: string;
|
|
47
|
+
desc?: string;
|
|
48
|
+
icon?: string;
|
|
49
|
+
children?: InteractionChildDatum[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 交互流程的数据结构
|
|
54
|
+
* items: 泳道列表,每个泳道有 label 和 children
|
|
55
|
+
* relations: 节点间的关系
|
|
56
|
+
*/
|
|
57
|
+
export interface InteractionFlowData {
|
|
58
|
+
title?: string;
|
|
59
|
+
desc?: string;
|
|
60
|
+
items?: InteractionLaneDatum[];
|
|
61
|
+
relations?: RelationEdgeDatum[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 创建节点ID到位置的映射
|
|
65
|
+
interface NodeLayout {
|
|
66
|
+
x: number;
|
|
67
|
+
y: number;
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
centerX: number;
|
|
71
|
+
centerY: number;
|
|
72
|
+
laneIndex: number;
|
|
73
|
+
rowIndex: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface SequenceInteractionProps extends BaseStructureProps {
|
|
77
|
+
laneGap?: number;
|
|
78
|
+
nodeGap?: number;
|
|
79
|
+
lifelineWidth?: number;
|
|
80
|
+
arrowWidth?: number;
|
|
81
|
+
showLifeline?: boolean;
|
|
82
|
+
padding?: number;
|
|
83
|
+
arrowType?: 'arrow' | 'triangle';
|
|
84
|
+
showLaneHeader?: boolean;
|
|
85
|
+
laneHeaderHeight?: number;
|
|
86
|
+
edgeStyle?: 'solid' | 'dashed';
|
|
87
|
+
animated?: boolean;
|
|
88
|
+
edgeColorMode?: 'solid' | 'gradient';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const DEFAULT_LANE_GAP = 350;
|
|
92
|
+
const DEFAULT_NODE_GAP = 80;
|
|
93
|
+
const DEFAULT_LIFELINE_WIDTH = 2;
|
|
94
|
+
const DEFAULT_ARROW_WIDTH = 2;
|
|
95
|
+
const DEFAULT_PADDING = 40;
|
|
96
|
+
const DEFAULT_LANE_HEADER_HEIGHT = 60;
|
|
97
|
+
const DEFAULT_ITEM_WIDTH = 120;
|
|
98
|
+
const DEFAULT_ITEM_HEIGHT = 50;
|
|
99
|
+
|
|
100
|
+
const FONT_SIZE = 14;
|
|
101
|
+
const ARROW_SIZE = 14;
|
|
102
|
+
const CORNER_RADIUS_NODE = 6;
|
|
103
|
+
const LANE_PADDING = 60;
|
|
104
|
+
|
|
105
|
+
const BTN_HALF_SIZE = 12;
|
|
106
|
+
const BTN_MARGIN = 10;
|
|
107
|
+
const BTN_LANE_ADD_Gap = 20;
|
|
108
|
+
const BOTTOM_AREA_HEIGHT = 60;
|
|
109
|
+
|
|
110
|
+
const LANE_HEADER_MARGIN = 10;
|
|
111
|
+
const LABEL_OFFSET_Y = 10;
|
|
112
|
+
const FIRST_GAP = 20;
|
|
113
|
+
|
|
114
|
+
const PATH_OFFSET = 40;
|
|
115
|
+
|
|
116
|
+
const calculateEdgePath = (
|
|
117
|
+
fromId: string,
|
|
118
|
+
toId: string,
|
|
119
|
+
fromLayout: NodeLayout,
|
|
120
|
+
toLayout: NodeLayout,
|
|
121
|
+
edgeMap: Map<string, RelationEdgeDatum[]>,
|
|
122
|
+
fromOutDegree: number,
|
|
123
|
+
toInDegree: number,
|
|
124
|
+
fromInDegree: number,
|
|
125
|
+
toOutDegree: number,
|
|
126
|
+
) => {
|
|
127
|
+
const fromAnchors = getNodesAnchors(fromLayout);
|
|
128
|
+
const toAnchors = getNodesAnchors(toLayout);
|
|
129
|
+
|
|
130
|
+
const reverseKey = `${toId}-${fromId}`;
|
|
131
|
+
const hasReverse = edgeMap.has(reverseKey);
|
|
132
|
+
|
|
133
|
+
const isStartLane = fromLayout.laneIndex === 0;
|
|
134
|
+
|
|
135
|
+
let points: [number, number][] = [];
|
|
136
|
+
|
|
137
|
+
if (fromId === toId) {
|
|
138
|
+
// 1. 自连接 (A->A)
|
|
139
|
+
// RT -> Right Arc -> RB
|
|
140
|
+
const start = isStartLane ? fromAnchors.LT : fromAnchors.RT;
|
|
141
|
+
const end = isStartLane ? fromAnchors.LB : fromAnchors.RB;
|
|
142
|
+
const offset = isStartLane ? -PATH_OFFSET : PATH_OFFSET;
|
|
143
|
+
|
|
144
|
+
points = [
|
|
145
|
+
[start.x, start.y],
|
|
146
|
+
[start.x + offset, start.y],
|
|
147
|
+
[end.x + offset, end.y],
|
|
148
|
+
[end.x, end.y],
|
|
149
|
+
];
|
|
150
|
+
} else if (fromLayout.laneIndex === toLayout.laneIndex) {
|
|
151
|
+
// 2. 同泳道回环 (Bottom -> Top)
|
|
152
|
+
const start = isStartLane ? fromAnchors.LB : fromAnchors.RB;
|
|
153
|
+
const end = isStartLane ? toAnchors.LT : toAnchors.RT;
|
|
154
|
+
const offset = isStartLane ? -PATH_OFFSET : PATH_OFFSET;
|
|
155
|
+
|
|
156
|
+
points = [
|
|
157
|
+
[start.x, start.y],
|
|
158
|
+
[start.x + offset, start.y],
|
|
159
|
+
[end.x + offset, end.y],
|
|
160
|
+
[end.x, end.y],
|
|
161
|
+
];
|
|
162
|
+
} else {
|
|
163
|
+
// 3. 互连 & 单向连接
|
|
164
|
+
const isToRight = toLayout.centerX > fromLayout.centerX;
|
|
165
|
+
const isToLeft = toLayout.centerX < fromLayout.centerX;
|
|
166
|
+
|
|
167
|
+
const isSameY = Math.abs(fromLayout.centerY - toLayout.centerY) < 1;
|
|
168
|
+
const isTargetBelow = toLayout.centerY > fromLayout.centerY;
|
|
169
|
+
const isTargetStrictRight = toLayout.x >= fromLayout.x + fromLayout.width;
|
|
170
|
+
|
|
171
|
+
let startPoint: { x: number; y: number };
|
|
172
|
+
let endPoint: { x: number; y: number };
|
|
173
|
+
|
|
174
|
+
// 优先处理同行情况
|
|
175
|
+
if (isSameY) {
|
|
176
|
+
startPoint = isToRight ? fromAnchors.RC : fromAnchors.LC;
|
|
177
|
+
endPoint = isToRight ? toAnchors.LC : toAnchors.RC;
|
|
178
|
+
}
|
|
179
|
+
// 处理互连情况 (避免重叠,使用对角锚点)
|
|
180
|
+
else if (hasReverse) {
|
|
181
|
+
if (isTargetBelow) {
|
|
182
|
+
startPoint = isToRight ? fromAnchors.RB : fromAnchors.LT;
|
|
183
|
+
endPoint = isToRight ? toAnchors.LT : toAnchors.RB;
|
|
184
|
+
} else {
|
|
185
|
+
startPoint = isToRight ? fromAnchors.RT : fromAnchors.LT;
|
|
186
|
+
endPoint = isToRight ? toAnchors.LB : toAnchors.RB;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// 处理普通单向连接
|
|
190
|
+
else {
|
|
191
|
+
// 1. 确定终点 (End Point)
|
|
192
|
+
if (toInDegree === 1 && toOutDegree === 0) {
|
|
193
|
+
endPoint = isToRight ? toAnchors.LC : toAnchors.RC;
|
|
194
|
+
} else if (isTargetBelow) {
|
|
195
|
+
endPoint = isTargetStrictRight ? toAnchors.LT : toAnchors.RT;
|
|
196
|
+
} else {
|
|
197
|
+
endPoint = isTargetStrictRight ? toAnchors.LB : toAnchors.RB;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 2. 确定起点 (Start Point)
|
|
201
|
+
if (fromOutDegree === 1 && fromInDegree === 0) {
|
|
202
|
+
startPoint = isToRight ? fromAnchors.RC : fromAnchors.LC;
|
|
203
|
+
} else if (isToRight) {
|
|
204
|
+
startPoint = fromAnchors.RB;
|
|
205
|
+
} else if (isToLeft) {
|
|
206
|
+
startPoint = fromAnchors.LB;
|
|
207
|
+
} else {
|
|
208
|
+
startPoint = fromAnchors.RB;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (hasReverse && !isSameY) {
|
|
213
|
+
// 1. 跨行(不同 Y 轴)的双向连接
|
|
214
|
+
const startArr: [number, number] = [startPoint.x, startPoint.y];
|
|
215
|
+
const endArr: [number, number] = [endPoint.x, endPoint.y];
|
|
216
|
+
|
|
217
|
+
const cx = (startArr[0] + endArr[0]) / 2;
|
|
218
|
+
const cy = startArr[1];
|
|
219
|
+
|
|
220
|
+
points = [startArr, [cx, cy], endArr];
|
|
221
|
+
} else if (hasReverse && isSameY) {
|
|
222
|
+
// 2. 同行(相同 Y 轴)的双向连接
|
|
223
|
+
const startArr: [number, number] = [startPoint.x, startPoint.y];
|
|
224
|
+
const endArr: [number, number] = [endPoint.x, endPoint.y];
|
|
225
|
+
|
|
226
|
+
const midX = (startArr[0] + endArr[0]) / 2;
|
|
227
|
+
const midY = (startArr[1] + endArr[1]) / 2;
|
|
228
|
+
|
|
229
|
+
const offsetY = 30;
|
|
230
|
+
const isL2R = startArr[0] < endArr[0];
|
|
231
|
+
const cpY = isL2R ? midY - offsetY : midY + offsetY;
|
|
232
|
+
|
|
233
|
+
points = [startArr, [midX, cpY], endArr];
|
|
234
|
+
} else {
|
|
235
|
+
// 3. 普通单向连接
|
|
236
|
+
points = [
|
|
237
|
+
[startPoint.x, startPoint.y],
|
|
238
|
+
[endPoint.x, endPoint.y],
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return { points };
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export const SequenceInteractionFlow: ComponentType<
|
|
247
|
+
SequenceInteractionProps
|
|
248
|
+
> = (props) => {
|
|
249
|
+
// 生成实例级唯一ID以避免多图表冲突
|
|
250
|
+
const instanceId = Math.random().toString(36).slice(2, 9);
|
|
251
|
+
|
|
252
|
+
const {
|
|
253
|
+
Title,
|
|
254
|
+
Item,
|
|
255
|
+
data,
|
|
256
|
+
laneGap = DEFAULT_LANE_GAP,
|
|
257
|
+
nodeGap = DEFAULT_NODE_GAP,
|
|
258
|
+
lifelineWidth = DEFAULT_LIFELINE_WIDTH,
|
|
259
|
+
arrowWidth = DEFAULT_ARROW_WIDTH,
|
|
260
|
+
showLifeline = true,
|
|
261
|
+
padding = DEFAULT_PADDING,
|
|
262
|
+
arrowType = 'triangle',
|
|
263
|
+
showLaneHeader = true,
|
|
264
|
+
laneHeaderHeight = DEFAULT_LANE_HEADER_HEIGHT,
|
|
265
|
+
edgeStyle = 'solid',
|
|
266
|
+
animated = false,
|
|
267
|
+
edgeColorMode = 'gradient',
|
|
268
|
+
options,
|
|
269
|
+
} = props;
|
|
270
|
+
|
|
271
|
+
// 获取主题颜色
|
|
272
|
+
const themeColors = getThemeColors(options.themeConfig, options);
|
|
273
|
+
const colorText = themeColors?.colorText ?? '#333333';
|
|
274
|
+
const colorBg = themeColors?.colorBg ?? '#ffffff';
|
|
275
|
+
const colorBorder = themeColors?.colorTextSecondary ?? '#e0e0e0';
|
|
276
|
+
|
|
277
|
+
const flowData = data as InteractionFlowData;
|
|
278
|
+
const { title, desc, items = [], relations = [] } = flowData;
|
|
279
|
+
|
|
280
|
+
const titleContent = Title ? <Title title={title} desc={desc} /> : null;
|
|
281
|
+
|
|
282
|
+
// 空状态处理
|
|
283
|
+
if (!items || items.length === 0) {
|
|
284
|
+
const btnBounds = getElementBounds(<BtnAdd indexes={[0]} />);
|
|
285
|
+
return (
|
|
286
|
+
<FlexLayout
|
|
287
|
+
id="infographic-container"
|
|
288
|
+
flexDirection="column"
|
|
289
|
+
justifyContent="center"
|
|
290
|
+
alignItems="center"
|
|
291
|
+
>
|
|
292
|
+
{titleContent}
|
|
293
|
+
<Group>
|
|
294
|
+
<BtnsGroup>
|
|
295
|
+
<BtnAdd
|
|
296
|
+
indexes={[0]}
|
|
297
|
+
x={-btnBounds.width / 2}
|
|
298
|
+
y={-btnBounds.height / 2}
|
|
299
|
+
/>
|
|
300
|
+
</BtnsGroup>
|
|
301
|
+
<Text
|
|
302
|
+
x={0}
|
|
303
|
+
y={btnBounds.height / 2 + BTN_MARGIN}
|
|
304
|
+
width={200}
|
|
305
|
+
height={40}
|
|
306
|
+
fontSize={14}
|
|
307
|
+
alignHorizontal="center"
|
|
308
|
+
alignVertical="middle"
|
|
309
|
+
fill={themeColors?.colorTextSecondary ?? '#999'}
|
|
310
|
+
>
|
|
311
|
+
暂无数据
|
|
312
|
+
</Text>
|
|
313
|
+
</Group>
|
|
314
|
+
</FlexLayout>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// 泳道列表(每个顶层item是一个泳道)
|
|
319
|
+
const lanes = items as InteractionLaneDatum[];
|
|
320
|
+
|
|
321
|
+
// 计算最大行数(所有泳道中 children 的最大 step 或 索引),至少为1
|
|
322
|
+
let maxStep = 0;
|
|
323
|
+
lanes.forEach((lane) => {
|
|
324
|
+
lane.children?.forEach((child, index) => {
|
|
325
|
+
const currentStep = child.step ?? index;
|
|
326
|
+
if (currentStep > maxStep) {
|
|
327
|
+
maxStep = currentStep;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
const maxRows = Math.max(1, maxStep + 1);
|
|
332
|
+
|
|
333
|
+
const nodeLayoutById = new Map<string, NodeLayout>();
|
|
334
|
+
|
|
335
|
+
// 测量Item尺寸
|
|
336
|
+
const designItem = options.design?.item;
|
|
337
|
+
const itemConfig = Array.isArray(designItem) ? designItem[0] : designItem;
|
|
338
|
+
|
|
339
|
+
// 使用类型安全的访问或默认值
|
|
340
|
+
let itemWidth = itemConfig?.width ?? DEFAULT_ITEM_WIDTH;
|
|
341
|
+
let itemHeight = itemConfig?.height ?? DEFAULT_ITEM_HEIGHT;
|
|
342
|
+
|
|
343
|
+
// 构建一个扁平化的节点列表用于Item渲染
|
|
344
|
+
const flatNodes: {
|
|
345
|
+
datum: InteractionChildDatum;
|
|
346
|
+
laneIndex: number;
|
|
347
|
+
rowIndex: number;
|
|
348
|
+
}[] = [];
|
|
349
|
+
lanes.forEach((lane, laneIndex) => {
|
|
350
|
+
lane.children?.forEach((child, rowIndex) => {
|
|
351
|
+
flatNodes.push({ datum: child, laneIndex, rowIndex });
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// 尝试通过采样修正尺寸 (仅当配置未指定时)
|
|
356
|
+
if (
|
|
357
|
+
(!itemConfig?.width || !itemConfig?.height) &&
|
|
358
|
+
Item &&
|
|
359
|
+
flatNodes.length > 0
|
|
360
|
+
) {
|
|
361
|
+
const sampleNode = flatNodes[0];
|
|
362
|
+
const sampleBounds = getElementBounds(
|
|
363
|
+
<Item
|
|
364
|
+
indexes={[0]}
|
|
365
|
+
datum={sampleNode.datum}
|
|
366
|
+
positionH="center"
|
|
367
|
+
positionV="middle"
|
|
368
|
+
/>,
|
|
369
|
+
);
|
|
370
|
+
// 确保尺寸有效
|
|
371
|
+
if (sampleBounds.width > 0) itemWidth = sampleBounds.width;
|
|
372
|
+
if (sampleBounds.height > 0) itemHeight = sampleBounds.height;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// 测量relations标签的最大宽度,自动调整泳道间距
|
|
376
|
+
let maxLabelWidth = 0;
|
|
377
|
+
relations.forEach((relation) => {
|
|
378
|
+
if (relation.label) {
|
|
379
|
+
const labelBounds = getElementBounds(
|
|
380
|
+
<Text fontSize={FONT_SIZE} fontWeight="normal">
|
|
381
|
+
{relation.label}
|
|
382
|
+
</Text>,
|
|
383
|
+
);
|
|
384
|
+
maxLabelWidth = Math.max(maxLabelWidth, labelBounds.width);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// 动态计算泳道宽度:需要兼顾节点宽度、标签宽度需求以及用户设置的间距
|
|
389
|
+
const baseWidth = itemWidth + LANE_PADDING;
|
|
390
|
+
const labelWidthRequirement = itemWidth + maxLabelWidth + LANE_PADDING * 2;
|
|
391
|
+
const laneWidth = Math.max(laneGap, baseWidth, labelWidthRequirement);
|
|
392
|
+
|
|
393
|
+
// 计算行高度和总高度
|
|
394
|
+
const headerOffset = showLaneHeader ? laneHeaderHeight : 0;
|
|
395
|
+
const contentHeight =
|
|
396
|
+
FIRST_GAP + maxRows * itemHeight + Math.max(0, maxRows - 1) * nodeGap;
|
|
397
|
+
const totalHeight =
|
|
398
|
+
headerOffset + contentHeight + padding * 2 + BOTTOM_AREA_HEIGHT;
|
|
399
|
+
const totalWidth = laneWidth * lanes.length + padding * 2;
|
|
400
|
+
|
|
401
|
+
// 计算每个泳道的中心X坐标
|
|
402
|
+
const getLaneCenterX = (laneIndex: number) => {
|
|
403
|
+
return padding + laneWidth / 2 + laneIndex * laneWidth;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// 计算每行的Y坐标
|
|
407
|
+
const getRowY = (rowIndex: number) => {
|
|
408
|
+
return (
|
|
409
|
+
padding +
|
|
410
|
+
headerOffset +
|
|
411
|
+
FIRST_GAP +
|
|
412
|
+
rowIndex * (itemHeight + nodeGap) +
|
|
413
|
+
itemHeight / 2
|
|
414
|
+
);
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
const itemElements: JSXElement[] = [];
|
|
418
|
+
const decorElements: JSXElement[] = [];
|
|
419
|
+
const defsElements: JSXElement[] = [];
|
|
420
|
+
const btnElements: JSXElement[] = [];
|
|
421
|
+
|
|
422
|
+
// 绘制生命线
|
|
423
|
+
if (showLifeline) {
|
|
424
|
+
lanes.forEach((_lane, laneIndex) => {
|
|
425
|
+
const centerX = getLaneCenterX(laneIndex);
|
|
426
|
+
const startY = padding + headerOffset;
|
|
427
|
+
const endY = totalHeight - padding;
|
|
428
|
+
|
|
429
|
+
decorElements.push(
|
|
430
|
+
<Path
|
|
431
|
+
d={`M ${centerX} ${startY} L ${centerX} ${endY}`}
|
|
432
|
+
stroke={colorBorder}
|
|
433
|
+
strokeWidth={lifelineWidth}
|
|
434
|
+
strokeDasharray="5,5"
|
|
435
|
+
fill="none"
|
|
436
|
+
data-element-type="shape"
|
|
437
|
+
/>,
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
// 绘制生命线末端箭头(实心)
|
|
441
|
+
decorElements.push(
|
|
442
|
+
...createArrowElements(
|
|
443
|
+
centerX,
|
|
444
|
+
endY,
|
|
445
|
+
Math.PI / 2,
|
|
446
|
+
'triangle',
|
|
447
|
+
colorBorder,
|
|
448
|
+
1,
|
|
449
|
+
10,
|
|
450
|
+
),
|
|
451
|
+
);
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// 绘制泳道标题
|
|
456
|
+
if (showLaneHeader) {
|
|
457
|
+
lanes.forEach((lane, laneIndex) => {
|
|
458
|
+
const centerX = getLaneCenterX(laneIndex);
|
|
459
|
+
const laneColor = getPaletteColor(options, [laneIndex]);
|
|
460
|
+
const laneThemeColors = getThemeColors(
|
|
461
|
+
{ colorPrimary: laneColor },
|
|
462
|
+
options,
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
// 泳道标题背景
|
|
466
|
+
if (Item) {
|
|
467
|
+
decorElements.push(
|
|
468
|
+
<Item
|
|
469
|
+
indexes={[laneIndex]}
|
|
470
|
+
datum={{
|
|
471
|
+
label: lane.label,
|
|
472
|
+
icon: lane.icon,
|
|
473
|
+
desc: lane.desc,
|
|
474
|
+
}}
|
|
475
|
+
x={centerX - itemWidth / 2}
|
|
476
|
+
y={padding}
|
|
477
|
+
width={itemWidth}
|
|
478
|
+
height={laneHeaderHeight - LANE_HEADER_MARGIN}
|
|
479
|
+
themeColors={laneThemeColors}
|
|
480
|
+
positionH="center"
|
|
481
|
+
/>,
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
// 泳道标题删除按钮 (右上角)
|
|
485
|
+
btnElements.push(
|
|
486
|
+
<BtnRemove
|
|
487
|
+
indexes={[laneIndex]}
|
|
488
|
+
x={centerX + itemWidth / 2 - BTN_MARGIN}
|
|
489
|
+
y={padding - BTN_MARGIN}
|
|
490
|
+
/>,
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// 绘制节点(按行对齐)
|
|
497
|
+
lanes.forEach((lane, laneIndex) => {
|
|
498
|
+
lane.children?.forEach((child, rowIndex) => {
|
|
499
|
+
// 使用 step 属性作为行索引,如果未定义则回退到数组索引
|
|
500
|
+
const effectiveRowIndex = child.step ?? rowIndex;
|
|
501
|
+
|
|
502
|
+
const centerX = getLaneCenterX(laneIndex);
|
|
503
|
+
const centerY = getRowY(effectiveRowIndex);
|
|
504
|
+
|
|
505
|
+
const x = centerX - itemWidth / 2;
|
|
506
|
+
const y = centerY - itemHeight / 2;
|
|
507
|
+
|
|
508
|
+
// 保存节点布局信息
|
|
509
|
+
nodeLayoutById.set(child.id, {
|
|
510
|
+
x,
|
|
511
|
+
y,
|
|
512
|
+
width: itemWidth,
|
|
513
|
+
height: itemHeight,
|
|
514
|
+
centerX,
|
|
515
|
+
centerY,
|
|
516
|
+
laneIndex,
|
|
517
|
+
rowIndex: effectiveRowIndex,
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
const nodeColor = getPaletteColor(options, [laneIndex]);
|
|
521
|
+
const nodeThemeColors = getThemeColors(
|
|
522
|
+
{ colorPrimary: nodeColor },
|
|
523
|
+
options,
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
// 添加节点背景遮挡层,防止生命线虚线透过半透明节点显示
|
|
527
|
+
// 只在节点中心放置窄条遮挡生命线,避免圆角处露出白色背景
|
|
528
|
+
const maskStripWidth = lifelineWidth + 6;
|
|
529
|
+
decorElements.push(
|
|
530
|
+
<Rect
|
|
531
|
+
x={centerX - maskStripWidth / 2}
|
|
532
|
+
y={y}
|
|
533
|
+
width={maskStripWidth}
|
|
534
|
+
height={itemHeight}
|
|
535
|
+
fill={colorBg}
|
|
536
|
+
/>,
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
// 构造类似 hierarchy-tree 的 _originalIndex
|
|
540
|
+
const originalIndex = [laneIndex, rowIndex];
|
|
541
|
+
// 附加到数据上,确保 Item 组件能正确识别
|
|
542
|
+
const childWithIndex = {
|
|
543
|
+
...child,
|
|
544
|
+
_originalIndex: originalIndex,
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
if (Item) {
|
|
548
|
+
itemElements.push(
|
|
549
|
+
<Item
|
|
550
|
+
indexes={originalIndex}
|
|
551
|
+
datum={childWithIndex}
|
|
552
|
+
data={data}
|
|
553
|
+
x={x}
|
|
554
|
+
y={y}
|
|
555
|
+
positionH="center"
|
|
556
|
+
positionV="middle"
|
|
557
|
+
themeColors={nodeThemeColors}
|
|
558
|
+
/>,
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
// 节点删除按钮 (底部剧中)
|
|
562
|
+
btnElements.push(
|
|
563
|
+
<BtnRemove
|
|
564
|
+
indexes={originalIndex}
|
|
565
|
+
x={x + itemWidth / 2 - BTN_MARGIN}
|
|
566
|
+
y={y + itemHeight + BTN_MARGIN / 2}
|
|
567
|
+
/>,
|
|
568
|
+
);
|
|
569
|
+
} else {
|
|
570
|
+
// 默认节点渲染
|
|
571
|
+
decorElements.push(
|
|
572
|
+
<Rect
|
|
573
|
+
x={x}
|
|
574
|
+
y={y}
|
|
575
|
+
width={itemWidth}
|
|
576
|
+
height={itemHeight}
|
|
577
|
+
fill={nodeThemeColors?.colorPrimaryBg ?? colorBg}
|
|
578
|
+
stroke={nodeColor}
|
|
579
|
+
strokeWidth={2}
|
|
580
|
+
rx={CORNER_RADIUS_NODE}
|
|
581
|
+
data-element-type="shape"
|
|
582
|
+
/>,
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
if (child.label) {
|
|
586
|
+
decorElements.push(
|
|
587
|
+
<Text
|
|
588
|
+
x={x}
|
|
589
|
+
y={y}
|
|
590
|
+
width={itemWidth}
|
|
591
|
+
height={itemHeight}
|
|
592
|
+
fontSize={14}
|
|
593
|
+
fontWeight="bold"
|
|
594
|
+
alignHorizontal="center"
|
|
595
|
+
alignVertical="middle"
|
|
596
|
+
fill={colorText}
|
|
597
|
+
>
|
|
598
|
+
{child.label}
|
|
599
|
+
</Text>,
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
// 每个泳道底部的添加节点按钮
|
|
606
|
+
const childCount = lane.children?.length ?? 0;
|
|
607
|
+
|
|
608
|
+
// 找出当前泳道最大的 step
|
|
609
|
+
let lastEffectRowIndex = -1;
|
|
610
|
+
lane.children?.forEach((child, index) => {
|
|
611
|
+
const s = child.step ?? index;
|
|
612
|
+
if (s > lastEffectRowIndex) lastEffectRowIndex = s;
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
const lastRowY =
|
|
616
|
+
lastEffectRowIndex >= 0
|
|
617
|
+
? getRowY(lastEffectRowIndex)
|
|
618
|
+
: padding + headerOffset;
|
|
619
|
+
const addNodeY =
|
|
620
|
+
childCount > 0
|
|
621
|
+
? lastRowY + itemHeight / 2 + BTN_LANE_ADD_Gap
|
|
622
|
+
: lastRowY + FIRST_GAP + BTN_MARGIN;
|
|
623
|
+
const centerX = getLaneCenterX(laneIndex);
|
|
624
|
+
|
|
625
|
+
btnElements.push(
|
|
626
|
+
<BtnAdd
|
|
627
|
+
indexes={[laneIndex, childCount]}
|
|
628
|
+
x={centerX - BTN_HALF_SIZE}
|
|
629
|
+
y={addNodeY}
|
|
630
|
+
/>,
|
|
631
|
+
);
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
// 添加新泳道按钮 (最右侧)
|
|
635
|
+
const lastLaneRightX = getLaneCenterX(lanes.length - 1) + laneWidth / 2;
|
|
636
|
+
const newLaneX =
|
|
637
|
+
lanes.length > 0 ? lastLaneRightX + BTN_LANE_ADD_Gap : padding;
|
|
638
|
+
const newLaneY = padding + headerOffset / 2 - BTN_HALF_SIZE; // 垂直居中于标题栏
|
|
639
|
+
btnElements.push(
|
|
640
|
+
<BtnAdd indexes={[lanes.length]} x={newLaneX} y={newLaneY} />,
|
|
641
|
+
);
|
|
642
|
+
|
|
643
|
+
// 预处理边,方便快速查找反向边
|
|
644
|
+
const edgeMap = new Map<string, RelationEdgeDatum[]>();
|
|
645
|
+
// 统计入度和出度
|
|
646
|
+
const inDegreeMap = new Map<string, number>();
|
|
647
|
+
const outDegreeMap = new Map<string, number>();
|
|
648
|
+
|
|
649
|
+
relations.forEach((r) => {
|
|
650
|
+
const key = `${r.from}-${r.to}`;
|
|
651
|
+
if (!edgeMap.has(key)) edgeMap.set(key, []);
|
|
652
|
+
edgeMap.get(key)?.push(r);
|
|
653
|
+
|
|
654
|
+
const fromId = String(r.from);
|
|
655
|
+
const toId = String(r.to);
|
|
656
|
+
if (fromId === toId) return;
|
|
657
|
+
outDegreeMap.set(fromId, (outDegreeMap.get(fromId) || 0) + 1);
|
|
658
|
+
inDegreeMap.set(toId, (inDegreeMap.get(toId) || 0) + 1);
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
// 绘制消息箭头
|
|
662
|
+
relations.forEach((relation, relIndex) => {
|
|
663
|
+
const fromId = String(relation.from);
|
|
664
|
+
const toId = String(relation.to);
|
|
665
|
+
|
|
666
|
+
// 使用精确的节点布局信息
|
|
667
|
+
const fromLayout = nodeLayoutById.get(fromId);
|
|
668
|
+
const toLayout = nodeLayoutById.get(toId);
|
|
669
|
+
|
|
670
|
+
if (!fromLayout || !toLayout) return;
|
|
671
|
+
|
|
672
|
+
// 颜色处理
|
|
673
|
+
const fromColor =
|
|
674
|
+
getPaletteColor(options, [fromLayout.laneIndex]) || '#000000';
|
|
675
|
+
const toColor = getPaletteColor(options, [toLayout.laneIndex]) || '#000000';
|
|
676
|
+
const themePrimary = getColorPrimary(options);
|
|
677
|
+
|
|
678
|
+
// 确定线条和箭头颜色
|
|
679
|
+
let edgeStroke = themePrimary || '#999999';
|
|
680
|
+
let targetArrowColor = themePrimary || '#999999';
|
|
681
|
+
let sourceArrowColor = themePrimary || '#999999';
|
|
682
|
+
|
|
683
|
+
// 如果是渐变模式,使用渐变色
|
|
684
|
+
const gradientId = `arrow-gradient-${instanceId}-${relIndex}`;
|
|
685
|
+
if (edgeColorMode === 'gradient') {
|
|
686
|
+
edgeStroke = `url(#${gradientId})`;
|
|
687
|
+
targetArrowColor = toColor;
|
|
688
|
+
sourceArrowColor = fromColor;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const { points } = calculateEdgePath(
|
|
692
|
+
fromId,
|
|
693
|
+
toId,
|
|
694
|
+
fromLayout,
|
|
695
|
+
toLayout,
|
|
696
|
+
edgeMap,
|
|
697
|
+
outDegreeMap.get(fromId) || 0,
|
|
698
|
+
inDegreeMap.get(toId) || 0,
|
|
699
|
+
inDegreeMap.get(fromId) || 0,
|
|
700
|
+
outDegreeMap.get(toId) || 0,
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
let maskId: string | undefined;
|
|
704
|
+
let labelRenderNode: JSXElement | null = null;
|
|
705
|
+
|
|
706
|
+
if (relation.label) {
|
|
707
|
+
const labelPoint = getLabelPosition(points);
|
|
708
|
+
|
|
709
|
+
if (labelPoint) {
|
|
710
|
+
const labelX = labelPoint[0];
|
|
711
|
+
const labelY = labelPoint[1] - LABEL_OFFSET_Y;
|
|
712
|
+
|
|
713
|
+
// 预先计算 Label 的尺寸
|
|
714
|
+
const labelBounds = getElementBounds(
|
|
715
|
+
<ItemLabel
|
|
716
|
+
indexes={[relIndex]}
|
|
717
|
+
fontSize={FONT_SIZE}
|
|
718
|
+
fontWeight="normal"
|
|
719
|
+
>
|
|
720
|
+
{relation.label}
|
|
721
|
+
</ItemLabel>,
|
|
722
|
+
);
|
|
723
|
+
|
|
724
|
+
const bgX = labelX - labelBounds.width / 2;
|
|
725
|
+
const bgY = labelY - labelBounds.height / 2;
|
|
726
|
+
const bgW = labelBounds.width;
|
|
727
|
+
const bgH = labelBounds.height;
|
|
728
|
+
|
|
729
|
+
maskId = `edge-mask-${instanceId}-${relIndex}`;
|
|
730
|
+
|
|
731
|
+
// 将 Mask 推入 defsElements
|
|
732
|
+
// 逻辑:白色区域显示(全图),黑色区域隐藏(标签位置)
|
|
733
|
+
defsElements.push(
|
|
734
|
+
<mask
|
|
735
|
+
id={maskId}
|
|
736
|
+
maskUnits="userSpaceOnUse"
|
|
737
|
+
x={0}
|
|
738
|
+
y={0}
|
|
739
|
+
width={totalWidth}
|
|
740
|
+
height={totalHeight}
|
|
741
|
+
>
|
|
742
|
+
{/* 1. 全屏白色底,保证线条其他部分显示 */}
|
|
743
|
+
<Rect
|
|
744
|
+
x={0}
|
|
745
|
+
y={0}
|
|
746
|
+
width={totalWidth}
|
|
747
|
+
height={totalHeight}
|
|
748
|
+
fill="white"
|
|
749
|
+
/>
|
|
750
|
+
{/* 2. 标签位置黑色块,将线条“挖空” */}
|
|
751
|
+
<Rect x={bgX} y={bgY} width={bgW} height={bgH} fill="black" />
|
|
752
|
+
</mask>,
|
|
753
|
+
);
|
|
754
|
+
|
|
755
|
+
labelRenderNode = (
|
|
756
|
+
<ItemLabel
|
|
757
|
+
indexes={[relIndex]}
|
|
758
|
+
x={labelX - labelBounds.width / 2}
|
|
759
|
+
y={labelY - labelBounds.height / 2}
|
|
760
|
+
width={labelBounds.width}
|
|
761
|
+
height={labelBounds.height}
|
|
762
|
+
fontSize={FONT_SIZE}
|
|
763
|
+
fontWeight="normal"
|
|
764
|
+
alignHorizontal="center"
|
|
765
|
+
alignVertical="middle"
|
|
766
|
+
fill={colorText}
|
|
767
|
+
>
|
|
768
|
+
{relation.label}
|
|
769
|
+
</ItemLabel>
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// 生成路径字符串
|
|
775
|
+
const pathD = getEdgePathD(points);
|
|
776
|
+
if (edgeColorMode === 'gradient') {
|
|
777
|
+
const startPoint = points[0];
|
|
778
|
+
const endPoint = points[points.length - 1];
|
|
779
|
+
defsElements.push(
|
|
780
|
+
<linearGradient
|
|
781
|
+
id={gradientId}
|
|
782
|
+
gradientUnits="userSpaceOnUse"
|
|
783
|
+
x1={startPoint[0]}
|
|
784
|
+
y1={startPoint[1]}
|
|
785
|
+
x2={endPoint[0]}
|
|
786
|
+
y2={endPoint[1]}
|
|
787
|
+
>
|
|
788
|
+
<stop offset="0%" stopColor={fromColor} />
|
|
789
|
+
<stop offset="100%" stopColor={toColor} />
|
|
790
|
+
</linearGradient>,
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
decorElements.push(
|
|
795
|
+
<Path
|
|
796
|
+
d={pathD}
|
|
797
|
+
stroke={edgeStroke}
|
|
798
|
+
strokeWidth={arrowWidth}
|
|
799
|
+
fill="none"
|
|
800
|
+
data-element-type="shape"
|
|
801
|
+
// 如果存在 maskId,则应用遮罩
|
|
802
|
+
mask={maskId ? `url(#${maskId})` : undefined}
|
|
803
|
+
strokeDasharray={
|
|
804
|
+
relation.lineStyle === 'solid'
|
|
805
|
+
? undefined
|
|
806
|
+
: (relation.lineStyle ?? edgeStyle) === 'dashed' || animated
|
|
807
|
+
? '5,5'
|
|
808
|
+
: undefined
|
|
809
|
+
}
|
|
810
|
+
>
|
|
811
|
+
{animated && (
|
|
812
|
+
<animate
|
|
813
|
+
attributeName="stroke-dashoffset"
|
|
814
|
+
from="10"
|
|
815
|
+
to="0"
|
|
816
|
+
dur="1s"
|
|
817
|
+
repeatCount="indefinite"
|
|
818
|
+
/>
|
|
819
|
+
)}
|
|
820
|
+
</Path>,
|
|
821
|
+
);
|
|
822
|
+
|
|
823
|
+
// 绘制箭头头部 (箭头不需要遮罩,保持原样)
|
|
824
|
+
const effectiveArrowSize = ARROW_SIZE;
|
|
825
|
+
const direction = relation.direction ?? 'forward';
|
|
826
|
+
|
|
827
|
+
const arrowConfigs = [
|
|
828
|
+
{
|
|
829
|
+
show: direction === 'forward' || direction === 'both',
|
|
830
|
+
angle: getTangentAngle(points, 1),
|
|
831
|
+
point: points[points.length - 1],
|
|
832
|
+
color: targetArrowColor,
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
show: direction === 'both',
|
|
836
|
+
angle: getTangentAngle(points, 0) + Math.PI,
|
|
837
|
+
point: points[0],
|
|
838
|
+
color: sourceArrowColor,
|
|
839
|
+
},
|
|
840
|
+
];
|
|
841
|
+
|
|
842
|
+
arrowConfigs.forEach((cfg) => {
|
|
843
|
+
if (cfg.show) {
|
|
844
|
+
decorElements.push(
|
|
845
|
+
...createArrowElements(
|
|
846
|
+
cfg.point[0],
|
|
847
|
+
cfg.point[1],
|
|
848
|
+
cfg.angle,
|
|
849
|
+
relation.arrowType ?? arrowType,
|
|
850
|
+
cfg.color,
|
|
851
|
+
arrowWidth,
|
|
852
|
+
effectiveArrowSize,
|
|
853
|
+
),
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
if (labelRenderNode) {
|
|
859
|
+
decorElements.push(labelRenderNode);
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
return (
|
|
864
|
+
<FlexLayout
|
|
865
|
+
id="infographic-container"
|
|
866
|
+
flexDirection="column"
|
|
867
|
+
justifyContent="center"
|
|
868
|
+
alignItems="center"
|
|
869
|
+
>
|
|
870
|
+
{Title ? <Title title={title} desc={desc} /> : null}
|
|
871
|
+
<Group>
|
|
872
|
+
<Rect x={0} y={0} width={totalWidth} height={totalHeight} fill="none" />
|
|
873
|
+
<Defs>{defsElements}</Defs>
|
|
874
|
+
<Group>{decorElements}</Group>
|
|
875
|
+
<ItemsGroup>{itemElements}</ItemsGroup>
|
|
876
|
+
<BtnsGroup>{btnElements}</BtnsGroup>
|
|
877
|
+
</Group>
|
|
878
|
+
</FlexLayout>
|
|
879
|
+
);
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
registerStructure('sequence-interaction', {
|
|
883
|
+
component: SequenceInteractionFlow,
|
|
884
|
+
composites: ['title', 'item'],
|
|
885
|
+
});
|