@antv/infographic 0.2.14 → 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 +155 -153
- 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/managers/sync-registry.d.ts +2 -1
- package/esm/editor/types/editor.d.ts +2 -1
- package/esm/editor/types/sync.d.ts +2 -1
- package/esm/editor/utils/object.js +46 -39
- package/esm/options/types.d.ts +6 -0
- package/esm/runtime/Infographic.js +20 -7
- 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 +3 -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 +31 -3
- 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/managers/sync-registry.d.ts +2 -1
- package/lib/editor/types/editor.d.ts +2 -1
- package/lib/editor/types/sync.d.ts +2 -1
- package/lib/editor/utils/object.js +45 -38
- package/lib/options/types.d.ts +6 -0
- package/lib/runtime/Infographic.js +19 -6
- 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 +3 -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 +30 -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/managers/sync-registry.ts +2 -1
- package/src/editor/types/editor.ts +2 -1
- package/src/editor/types/sync.ts +3 -1
- package/src/editor/utils/object.ts +50 -40
- package/src/options/types.ts +7 -0
- package/src/runtime/Infographic.tsx +27 -17
- 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 +2 -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 +35 -3
- package/src/utils/types.ts +61 -0
- package/src/version.ts +1 -1
|
@@ -31,6 +31,7 @@ export * from './sequence-cylinders-3d';
|
|
|
31
31
|
export * from './sequence-filter-mesh';
|
|
32
32
|
export * from './sequence-funnel';
|
|
33
33
|
export * from './sequence-horizontal-zigzag';
|
|
34
|
+
export * from './sequence-interaction';
|
|
34
35
|
export * from './sequence-mountain';
|
|
35
36
|
export * from './sequence-pyramid';
|
|
36
37
|
export * from './sequence-roadmap-vertical';
|
|
@@ -31,6 +31,7 @@ export * from './sequence-cylinders-3d.js';
|
|
|
31
31
|
export * from './sequence-filter-mesh.js';
|
|
32
32
|
export * from './sequence-funnel.js';
|
|
33
33
|
export * from './sequence-horizontal-zigzag.js';
|
|
34
|
+
export * from './sequence-interaction.js';
|
|
34
35
|
export * from './sequence-mountain.js';
|
|
35
36
|
export * from './sequence-pyramid.js';
|
|
36
37
|
export * from './sequence-roadmap-vertical.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "../../jsx-runtime.js";
|
|
2
2
|
import { DagreLayout } from '@antv/layout';
|
|
3
|
-
import { Defs, getElementBounds, Group, Path,
|
|
3
|
+
import { Defs, getElementBounds, Group, Path, Text } from '../../jsx/index.js';
|
|
4
4
|
import { BtnAdd, BtnsGroup, ItemsGroup } from '../components/index.js';
|
|
5
5
|
import { FlexLayout } from '../layouts/index.js';
|
|
6
|
-
import { getColorPrimary, getPaletteColor, getThemeColors } from '../utils/index.js';
|
|
6
|
+
import { createArrowElements, createRoundedPath, createStraightPath, getColorPrimary, getMidPoint, getPaletteColor, getThemeColors, } from '../utils/index.js';
|
|
7
7
|
import { registerStructure } from './registry.js';
|
|
8
8
|
const DEFAULT_NODE_SEP = 50;
|
|
9
9
|
const DEFAULT_RANK_SEP = 70;
|
|
@@ -191,141 +191,6 @@ export const RelationDagreFlow = (props) => {
|
|
|
191
191
|
? `${dashPatternLength / (edgeAnimationSpeed * 10)}s`
|
|
192
192
|
: '1s';
|
|
193
193
|
const straightCornerRadius = edgeCornerRadius;
|
|
194
|
-
const createStraightPath = (points, dx, dy) => points
|
|
195
|
-
.map(([x, y], index) => {
|
|
196
|
-
const prefix = index === 0 ? 'M' : 'L';
|
|
197
|
-
return `${prefix} ${x + dx} ${y + dy}`;
|
|
198
|
-
})
|
|
199
|
-
.join(' ');
|
|
200
|
-
const createRoundedPath = (points, radius, dx, dy) => {
|
|
201
|
-
if (points.length < 2)
|
|
202
|
-
return '';
|
|
203
|
-
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
204
|
-
const toPoint = ([x, y]) => ({
|
|
205
|
-
x: x + dx,
|
|
206
|
-
y: y + dy,
|
|
207
|
-
});
|
|
208
|
-
const output = [];
|
|
209
|
-
const first = toPoint(points[0]);
|
|
210
|
-
output.push(`M ${first.x} ${first.y}`);
|
|
211
|
-
if (points.length === 2) {
|
|
212
|
-
const last = toPoint(points[1]);
|
|
213
|
-
output.push(`L ${last.x} ${last.y}`);
|
|
214
|
-
return output.join(' ');
|
|
215
|
-
}
|
|
216
|
-
for (let i = 1; i < points.length - 1; i += 1) {
|
|
217
|
-
const prev = points[i - 1];
|
|
218
|
-
const curr = points[i];
|
|
219
|
-
const next = points[i + 1];
|
|
220
|
-
const v0x = curr[0] - prev[0];
|
|
221
|
-
const v0y = curr[1] - prev[1];
|
|
222
|
-
const v1x = next[0] - curr[0];
|
|
223
|
-
const v1y = next[1] - curr[1];
|
|
224
|
-
const d0 = Math.hypot(v0x, v0y);
|
|
225
|
-
const d1 = Math.hypot(v1x, v1y);
|
|
226
|
-
if (d0 === 0 || d1 === 0) {
|
|
227
|
-
const currPoint = toPoint(curr);
|
|
228
|
-
output.push(`L ${currPoint.x} ${currPoint.y}`);
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
const r = clamp(radius, 0, Math.min(d0, d1) / 2);
|
|
232
|
-
if (r === 0) {
|
|
233
|
-
const currPoint = toPoint(curr);
|
|
234
|
-
output.push(`L ${currPoint.x} ${currPoint.y}`);
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
const u0x = v0x / d0;
|
|
238
|
-
const u0y = v0y / d0;
|
|
239
|
-
const u1x = v1x / d1;
|
|
240
|
-
const u1y = v1y / d1;
|
|
241
|
-
const start = toPoint([curr[0] - u0x * r, curr[1] - u0y * r]);
|
|
242
|
-
const end = toPoint([curr[0] + u1x * r, curr[1] + u1y * r]);
|
|
243
|
-
output.push(`L ${start.x} ${start.y}`);
|
|
244
|
-
const currPoint = toPoint(curr);
|
|
245
|
-
output.push(`Q ${currPoint.x} ${currPoint.y} ${end.x} ${end.y}`);
|
|
246
|
-
}
|
|
247
|
-
const last = toPoint(points[points.length - 1]);
|
|
248
|
-
output.push(`L ${last.x} ${last.y}`);
|
|
249
|
-
return output.join(' ');
|
|
250
|
-
};
|
|
251
|
-
const createArrowElements = (x, y, angle, type, fillColor) => {
|
|
252
|
-
const ux = Math.cos(angle);
|
|
253
|
-
const uy = Math.sin(angle);
|
|
254
|
-
const px = -uy;
|
|
255
|
-
const py = ux;
|
|
256
|
-
const length = arrowSize;
|
|
257
|
-
const halfWidth = arrowSize * 0.55;
|
|
258
|
-
if (type === 'arrow') {
|
|
259
|
-
const leftX = x - ux * length + px * halfWidth;
|
|
260
|
-
const leftY = y - uy * length + py * halfWidth;
|
|
261
|
-
const rightX = x - ux * length - px * halfWidth;
|
|
262
|
-
const rightY = y - uy * length - py * halfWidth;
|
|
263
|
-
return [
|
|
264
|
-
_jsx(Path, { d: `M ${leftX} ${leftY} L ${x} ${y} L ${rightX} ${rightY}`, stroke: fillColor, strokeWidth: Math.max(1.5, edgeWidth), strokeLinecap: "round", strokeLinejoin: "round", fill: "none" }),
|
|
265
|
-
];
|
|
266
|
-
}
|
|
267
|
-
if (type === 'diamond') {
|
|
268
|
-
const diamondLength = length * 1.25;
|
|
269
|
-
const diamondWidth = halfWidth * 0.75;
|
|
270
|
-
const midX = x - ux * diamondLength * 0.5;
|
|
271
|
-
const midY = y - uy * diamondLength * 0.5;
|
|
272
|
-
const diamondPoints = [
|
|
273
|
-
{ x, y },
|
|
274
|
-
{ x: midX + px * diamondWidth, y: midY + py * diamondWidth },
|
|
275
|
-
{ x: x - ux * diamondLength, y: y - uy * diamondLength },
|
|
276
|
-
{ x: midX - px * diamondWidth, y: midY - py * diamondWidth },
|
|
277
|
-
];
|
|
278
|
-
return [
|
|
279
|
-
_jsx(Polygon, { points: diamondPoints, fill: fillColor, stroke: fillColor, strokeWidth: Math.max(1, edgeWidth * 0.8) }),
|
|
280
|
-
];
|
|
281
|
-
}
|
|
282
|
-
const trianglePoints = [
|
|
283
|
-
{ x, y },
|
|
284
|
-
{
|
|
285
|
-
x: x - ux * length + px * halfWidth,
|
|
286
|
-
y: y - uy * length + py * halfWidth,
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
x: x - ux * length - px * halfWidth,
|
|
290
|
-
y: y - uy * length - py * halfWidth,
|
|
291
|
-
},
|
|
292
|
-
];
|
|
293
|
-
return [
|
|
294
|
-
_jsx(Polygon, { points: trianglePoints, fill: fillColor, stroke: fillColor, strokeWidth: Math.max(1, edgeWidth * 0.8) }),
|
|
295
|
-
];
|
|
296
|
-
};
|
|
297
|
-
const getMidPoint = (points) => {
|
|
298
|
-
if (points.length === 0)
|
|
299
|
-
return null;
|
|
300
|
-
if (points.length === 1)
|
|
301
|
-
return points[0];
|
|
302
|
-
let total = 0;
|
|
303
|
-
const segments = [];
|
|
304
|
-
for (let i = 0; i < points.length - 1; i += 1) {
|
|
305
|
-
const start = points[i];
|
|
306
|
-
const end = points[i + 1];
|
|
307
|
-
const length = Math.hypot(end[0] - start[0], end[1] - start[1]);
|
|
308
|
-
segments.push({ length, start, end });
|
|
309
|
-
total += length;
|
|
310
|
-
}
|
|
311
|
-
if (total === 0)
|
|
312
|
-
return points[0];
|
|
313
|
-
let target = total / 2;
|
|
314
|
-
for (let i = 0; i < segments.length; i += 1) {
|
|
315
|
-
const segment = segments[i];
|
|
316
|
-
if (target <= segment.length || i === segments.length - 1) {
|
|
317
|
-
const ratio = segment.length === 0
|
|
318
|
-
? 0
|
|
319
|
-
: Math.max(0, Math.min(1, target / segment.length));
|
|
320
|
-
return [
|
|
321
|
-
segment.start[0] + (segment.end[0] - segment.start[0]) * ratio,
|
|
322
|
-
segment.start[1] + (segment.end[1] - segment.start[1]) * ratio,
|
|
323
|
-
];
|
|
324
|
-
}
|
|
325
|
-
target -= segment.length;
|
|
326
|
-
}
|
|
327
|
-
return points[Math.floor(points.length / 2)];
|
|
328
|
-
};
|
|
329
194
|
const getOrthEdgeEndpoints = (sourceId, targetId) => {
|
|
330
195
|
const source = nodeLayoutById.get(sourceId);
|
|
331
196
|
const target = nodeLayoutById.get(targetId);
|
|
@@ -468,7 +333,7 @@ export const RelationDagreFlow = (props) => {
|
|
|
468
333
|
const tail = points[lastIndex - 1];
|
|
469
334
|
const angle = Math.atan2(head[1] - tail[1], head[0] - tail[0]);
|
|
470
335
|
const arrowFill = edgeColorMode === 'gradient' ? targetColor : defaultStroke;
|
|
471
|
-
const arrowElements = createArrowElements(head[0] + pointsOffsetX, head[1] + pointsOffsetY, angle, edgeArrowType, arrowFill);
|
|
336
|
+
const arrowElements = createArrowElements(head[0] + pointsOffsetX, head[1] + pointsOffsetY, angle, edgeArrowType, arrowFill, edgeWidth, arrowSize);
|
|
472
337
|
decorElements.push(...arrowElements);
|
|
473
338
|
}
|
|
474
339
|
if (direction === 'both') {
|
|
@@ -476,7 +341,7 @@ export const RelationDagreFlow = (props) => {
|
|
|
476
341
|
const tail = points[1];
|
|
477
342
|
const angle = Math.atan2(head[1] - tail[1], head[0] - tail[0]);
|
|
478
343
|
const arrowFill = edgeColorMode === 'gradient' ? sourceColor : defaultStroke;
|
|
479
|
-
const arrowElements = createArrowElements(head[0] + pointsOffsetX, head[1] + pointsOffsetY, angle, edgeArrowType, arrowFill);
|
|
344
|
+
const arrowElements = createArrowElements(head[0] + pointsOffsetX, head[1] + pointsOffsetY, angle, edgeArrowType, arrowFill, edgeWidth, arrowSize);
|
|
480
345
|
decorElements.push(...arrowElements);
|
|
481
346
|
}
|
|
482
347
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ComponentType } from '../../jsx';
|
|
2
|
+
import type { RelationEdgeDatum } from '../../types';
|
|
3
|
+
import type { BaseStructureProps } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* 泳道内的节点数据
|
|
6
|
+
*/
|
|
7
|
+
export interface InteractionChildDatum {
|
|
8
|
+
id: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
desc?: string;
|
|
11
|
+
icon?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 手动指定节点的垂直顺序(层级),默认为数组索引
|
|
14
|
+
* 相同 step 的节点会处于同一高度
|
|
15
|
+
*/
|
|
16
|
+
step?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 泳道数据(顶层item)
|
|
20
|
+
* label 作为泳道标题
|
|
21
|
+
* children 作为泳道内的节点列表
|
|
22
|
+
*/
|
|
23
|
+
export interface InteractionLaneDatum {
|
|
24
|
+
label: string;
|
|
25
|
+
desc?: string;
|
|
26
|
+
icon?: string;
|
|
27
|
+
children?: InteractionChildDatum[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 交互流程的数据结构
|
|
31
|
+
* items: 泳道列表,每个泳道有 label 和 children
|
|
32
|
+
* relations: 节点间的关系
|
|
33
|
+
*/
|
|
34
|
+
export interface InteractionFlowData {
|
|
35
|
+
title?: string;
|
|
36
|
+
desc?: string;
|
|
37
|
+
items?: InteractionLaneDatum[];
|
|
38
|
+
relations?: RelationEdgeDatum[];
|
|
39
|
+
}
|
|
40
|
+
export interface SequenceInteractionProps extends BaseStructureProps {
|
|
41
|
+
laneGap?: number;
|
|
42
|
+
nodeGap?: number;
|
|
43
|
+
lifelineWidth?: number;
|
|
44
|
+
arrowWidth?: number;
|
|
45
|
+
showLifeline?: boolean;
|
|
46
|
+
padding?: number;
|
|
47
|
+
arrowType?: 'arrow' | 'triangle';
|
|
48
|
+
showLaneHeader?: boolean;
|
|
49
|
+
laneHeaderHeight?: number;
|
|
50
|
+
edgeStyle?: 'solid' | 'dashed';
|
|
51
|
+
animated?: boolean;
|
|
52
|
+
edgeColorMode?: 'solid' | 'gradient';
|
|
53
|
+
}
|
|
54
|
+
export declare const SequenceInteractionFlow: ComponentType<SequenceInteractionProps>;
|