@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
package/src/syntax/relations.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { mapWithSchema } from './mapper';
|
|
|
3
3
|
import { RelationSchema } from './schema';
|
|
4
4
|
import type { SyntaxError, SyntaxNode } from './types';
|
|
5
5
|
|
|
6
|
-
const RELATION_TOKEN = /[
|
|
7
|
-
const ARROW_TOKEN = /[
|
|
6
|
+
const RELATION_TOKEN = /(?:[<>o.x-]{2,}|[<>=]{2,})/;
|
|
7
|
+
const ARROW_TOKEN = /(?:[<>o.x-]{2,}|[<>=]{2,})/g;
|
|
8
8
|
|
|
9
9
|
interface ParsedNode {
|
|
10
10
|
id: string;
|
|
@@ -125,6 +125,33 @@ function readEdge(text: string, startIndex: number): ParsedEdge | null {
|
|
|
125
125
|
let directionToken = arrowToken;
|
|
126
126
|
let index = arrowEnd;
|
|
127
127
|
|
|
128
|
+
// Detect split bidirectional arrow pattern: <- label ->
|
|
129
|
+
{
|
|
130
|
+
const leftHasLeft = directionToken.includes('<');
|
|
131
|
+
const leftHasRight = directionToken.includes('>');
|
|
132
|
+
if (leftHasLeft && !leftHasRight) {
|
|
133
|
+
const lookahead = new RegExp(ARROW_TOKEN.source, 'g');
|
|
134
|
+
lookahead.lastIndex = arrowEnd;
|
|
135
|
+
const rightMatch = lookahead.exec(text);
|
|
136
|
+
if (
|
|
137
|
+
rightMatch &&
|
|
138
|
+
rightMatch[0].includes('>') &&
|
|
139
|
+
!rightMatch[0].includes('<')
|
|
140
|
+
) {
|
|
141
|
+
const middleText = text.slice(arrowEnd, rightMatch.index).trim();
|
|
142
|
+
if (middleText) {
|
|
143
|
+
const splitLabel = normalizeLabel(middleText);
|
|
144
|
+
return {
|
|
145
|
+
label: splitLabel || label,
|
|
146
|
+
direction: 'both',
|
|
147
|
+
reverse: false,
|
|
148
|
+
nextIndex: rightMatch.index + rightMatch[0].length,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
128
155
|
index = skipSpaces(text, index);
|
|
129
156
|
if (text[index] === '|') {
|
|
130
157
|
const pipeEnd = text.indexOf('|', index + 1);
|
package/src/syntax/schema.ts
CHANGED
|
@@ -60,6 +60,7 @@ export const RelationSchema: ObjectSchema = object(
|
|
|
60
60
|
direction: enumOf(['forward', 'both', 'none']),
|
|
61
61
|
showArrow: enumOf(['true', 'false']),
|
|
62
62
|
arrowType: enumOf(['arrow', 'triangle', 'diamond']),
|
|
63
|
+
lineStyle: enumOf(['solid', 'dashed']),
|
|
63
64
|
},
|
|
64
65
|
{ allowUnknown: true },
|
|
65
66
|
);
|
|
@@ -6,6 +6,7 @@ import { hierarchyTreeTemplates } from './hierarchy-tree';
|
|
|
6
6
|
import { listZigzagTemplates } from './list-zigzag';
|
|
7
7
|
import { registerTemplate } from './registry';
|
|
8
8
|
import { relationDagreFlowTemplates } from './relation-dagre-flow';
|
|
9
|
+
import { sequenceInteractionTemplates } from './sequence-interaction';
|
|
9
10
|
import { sequenceStairsTemplates } from './sequence-stairs';
|
|
10
11
|
import type { TemplateOptions } from './types';
|
|
11
12
|
import { wordCloudTemplate } from './word-cloud';
|
|
@@ -752,6 +753,7 @@ const BUILT_IN_TEMPLATES: Record<string, TemplateOptions> = {
|
|
|
752
753
|
...wordCloudTemplate,
|
|
753
754
|
...listZigzagTemplates,
|
|
754
755
|
...relationDagreFlowTemplates,
|
|
756
|
+
...sequenceInteractionTemplates,
|
|
755
757
|
...hierarchyStructureTemplates,
|
|
756
758
|
};
|
|
757
759
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { TemplateOptions } from './types';
|
|
2
|
+
|
|
3
|
+
// 多样化的节点样式
|
|
4
|
+
const items = {
|
|
5
|
+
'badge-card': {
|
|
6
|
+
type: 'badge-card',
|
|
7
|
+
width: 160,
|
|
8
|
+
height: 60,
|
|
9
|
+
},
|
|
10
|
+
'compact-card': {
|
|
11
|
+
type: 'compact-card',
|
|
12
|
+
width: 180,
|
|
13
|
+
height: 60,
|
|
14
|
+
},
|
|
15
|
+
'capsule-item': {
|
|
16
|
+
type: 'capsule-item',
|
|
17
|
+
width: 150,
|
|
18
|
+
height: 60,
|
|
19
|
+
},
|
|
20
|
+
'rounded-rect-node': {
|
|
21
|
+
type: 'rounded-rect-node',
|
|
22
|
+
width: 140,
|
|
23
|
+
height: 60,
|
|
24
|
+
},
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
// 基础结构属性
|
|
28
|
+
const baseStructureAttrs = {
|
|
29
|
+
type: 'sequence-interaction',
|
|
30
|
+
showLaneHeader: true,
|
|
31
|
+
arrowType: 'triangle',
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
// 箭头样式配置
|
|
35
|
+
const arrowStyles = {
|
|
36
|
+
default: {},
|
|
37
|
+
dashed: {
|
|
38
|
+
edgeStyle: 'dashed',
|
|
39
|
+
},
|
|
40
|
+
animated: {
|
|
41
|
+
edgeStyle: 'dashed',
|
|
42
|
+
animated: true,
|
|
43
|
+
},
|
|
44
|
+
} as const;
|
|
45
|
+
|
|
46
|
+
// 结构布局配置
|
|
47
|
+
const structures = {
|
|
48
|
+
// 默认:带生命线
|
|
49
|
+
default: {
|
|
50
|
+
...baseStructureAttrs,
|
|
51
|
+
showLifeline: true,
|
|
52
|
+
nodeGap: 40,
|
|
53
|
+
},
|
|
54
|
+
// 紧凑:更小间距
|
|
55
|
+
compact: {
|
|
56
|
+
...baseStructureAttrs,
|
|
57
|
+
showLifeline: true,
|
|
58
|
+
nodeGap: 20,
|
|
59
|
+
},
|
|
60
|
+
// 宽松:更大间距
|
|
61
|
+
wide: {
|
|
62
|
+
...baseStructureAttrs,
|
|
63
|
+
showLifeline: true,
|
|
64
|
+
nodeGap: 60,
|
|
65
|
+
},
|
|
66
|
+
} as const;
|
|
67
|
+
|
|
68
|
+
export const sequenceInteractionTemplates: Record<string, TemplateOptions> = {};
|
|
69
|
+
|
|
70
|
+
// 排除某些不合适的组合
|
|
71
|
+
const omit: string[] = [
|
|
72
|
+
// 后续如果有不合适的可以排除掉
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
Object.entries(structures).forEach(([strKey, strAttrs]) => {
|
|
76
|
+
Object.entries(arrowStyles).forEach(([arrowKey, arrowAttrs]) => {
|
|
77
|
+
Object.entries(items).forEach(([itemKey, itemAttrs]) => {
|
|
78
|
+
const parts = [strKey];
|
|
79
|
+
if (arrowKey !== 'default') {
|
|
80
|
+
parts.push(arrowKey);
|
|
81
|
+
}
|
|
82
|
+
parts.push(itemKey);
|
|
83
|
+
|
|
84
|
+
const appendix = parts.join('-');
|
|
85
|
+
if (omit.includes(appendix)) return;
|
|
86
|
+
|
|
87
|
+
const templateKey = `sequence-interaction-${appendix}`;
|
|
88
|
+
|
|
89
|
+
sequenceInteractionTemplates[templateKey] = {
|
|
90
|
+
design: {
|
|
91
|
+
title: 'default',
|
|
92
|
+
structure: {
|
|
93
|
+
...strAttrs,
|
|
94
|
+
...arrowAttrs,
|
|
95
|
+
},
|
|
96
|
+
item: itemAttrs,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
package/src/types/data.ts
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { measureText as measure, registerFont } from 'measury';
|
|
2
|
+
import Tegakizatsu from 'measury/fonts/851tegakizatsu-Regular';
|
|
2
3
|
import AlibabaPuHuiTi from 'measury/fonts/AlibabaPuHuiTi-Regular';
|
|
4
|
+
import Arial from 'measury/fonts/Arial-Regular';
|
|
5
|
+
import LXGWWenKai from 'measury/fonts/LXGWWenKai-Regular';
|
|
6
|
+
import SourceHanSans from 'measury/fonts/SourceHanSans-Regular';
|
|
7
|
+
import SourceHanSerif from 'measury/fonts/SourceHanSerif-Regular';
|
|
3
8
|
import { JSXNode, TextProps } from '../jsx';
|
|
4
9
|
import { DEFAULT_FONT } from '../renderer';
|
|
5
|
-
import { encodeFontFamily } from './font';
|
|
10
|
+
import { decodeFontFamily, encodeFontFamily } from './font';
|
|
6
11
|
|
|
7
|
-
let FONT_EXTEND_FACTOR = 1.
|
|
12
|
+
let FONT_EXTEND_FACTOR = 1.015;
|
|
8
13
|
|
|
9
14
|
export const setFontExtendFactor = (factor: number) => {
|
|
10
15
|
FONT_EXTEND_FACTOR = factor;
|
|
@@ -12,6 +17,28 @@ export const setFontExtendFactor = (factor: number) => {
|
|
|
12
17
|
|
|
13
18
|
registerFont(AlibabaPuHuiTi);
|
|
14
19
|
|
|
20
|
+
// Lazy-register extra measury fonts on first use (SSR only needs glyph data).
|
|
21
|
+
const EXTRA_MEASURY_FONTS: Record<string, Parameters<typeof registerFont>[0]> =
|
|
22
|
+
{
|
|
23
|
+
'851tegakizatsu': Tegakizatsu,
|
|
24
|
+
Arial: Arial,
|
|
25
|
+
'LXGW WenKai': LXGWWenKai,
|
|
26
|
+
'Source Han Sans': SourceHanSans,
|
|
27
|
+
'Source Han Serif': SourceHanSerif,
|
|
28
|
+
};
|
|
29
|
+
const registeredMeasuryFonts = new Set<string>();
|
|
30
|
+
|
|
31
|
+
function ensureMeasuryFont(fontFamily: string) {
|
|
32
|
+
// decodeFontFamily: '"851tegakizatsu", sans-serif' → '851tegakizatsu, sans-serif'
|
|
33
|
+
// split by comma and take the first family name
|
|
34
|
+
const primary = decodeFontFamily(fontFamily)?.split(',')[0]?.trim();
|
|
35
|
+
if (!primary || registeredMeasuryFonts.has(primary)) return;
|
|
36
|
+
const data = EXTRA_MEASURY_FONTS[primary];
|
|
37
|
+
if (!data) return;
|
|
38
|
+
registerFont(data);
|
|
39
|
+
registeredMeasuryFonts.add(primary);
|
|
40
|
+
}
|
|
41
|
+
|
|
15
42
|
let canvasContext: CanvasRenderingContext2D | null | undefined = undefined;
|
|
16
43
|
let measureSpan: HTMLSpanElement | null = null;
|
|
17
44
|
|
|
@@ -121,13 +148,18 @@ export function measureText(
|
|
|
121
148
|
} = attrs;
|
|
122
149
|
|
|
123
150
|
const content = text.toString();
|
|
151
|
+
ensureMeasuryFont(fontFamily);
|
|
124
152
|
const options = {
|
|
125
153
|
fontFamily,
|
|
126
154
|
fontSize: parseFloat(fontSize.toString()),
|
|
127
155
|
fontWeight,
|
|
128
156
|
lineHeight,
|
|
129
157
|
};
|
|
130
|
-
const fallback = () =>
|
|
158
|
+
const fallback = () =>
|
|
159
|
+
measure(content, {
|
|
160
|
+
...options,
|
|
161
|
+
fontFamily: decodeFontFamily(fontFamily),
|
|
162
|
+
});
|
|
131
163
|
const metrics = measureTextInBrowser(content, options) ?? fallback();
|
|
132
164
|
|
|
133
165
|
// 额外添加 1% 宽高
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Path Helper Types (路径生成工具类型)
|
|
3
|
+
//
|
|
4
|
+
// 作用:递归提取对象的所有可选路径(点语法),用于 SyncRegistry 等场景的类型安全与补全。
|
|
5
|
+
//
|
|
6
|
+
// [Input]:
|
|
7
|
+
// type Obj = { a: { b: { c: string } }, d: number };
|
|
8
|
+
//
|
|
9
|
+
// [Output]:
|
|
10
|
+
// "a" | "a.b" | "a.b.c" | "d"
|
|
11
|
+
// =============================================================================
|
|
12
|
+
|
|
13
|
+
// 1. 递归深度控制:定义一个元组,用于递减深度 (D -> D-1)
|
|
14
|
+
// Prev[3] => 2, Prev[2] => 1, ... Prev[0] => never
|
|
15
|
+
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
16
|
+
|
|
17
|
+
// 2. 终止节点类型:遇到这些类型停止递归
|
|
18
|
+
// 包括基本类型、数组、函数等,只深入遍历普通对象
|
|
19
|
+
type StopType =
|
|
20
|
+
| string
|
|
21
|
+
| number
|
|
22
|
+
| boolean
|
|
23
|
+
| symbol
|
|
24
|
+
| undefined
|
|
25
|
+
| null
|
|
26
|
+
| ((...args: any[]) => any)
|
|
27
|
+
| Array<any>;
|
|
28
|
+
|
|
29
|
+
// 3. 辅助:拼接两个路径片段 (K.P)
|
|
30
|
+
type Join<K, P> = K extends string | number
|
|
31
|
+
? P extends string | number
|
|
32
|
+
? `${K}${'' extends P ? '' : '.'}${P}`
|
|
33
|
+
: never
|
|
34
|
+
: never;
|
|
35
|
+
|
|
36
|
+
// 4. 辅助:提取对象中明确定义的 Key (过滤掉索引签名 [key: string]: any)
|
|
37
|
+
// 使用 Key Remapping (TS 4.1+) 技术
|
|
38
|
+
type ValidKey<T> = keyof {
|
|
39
|
+
[K in keyof T as string extends K
|
|
40
|
+
? never
|
|
41
|
+
: number extends K
|
|
42
|
+
? never
|
|
43
|
+
: K]: any;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 递归生成 T 的所有点语法路径 (例如 "design.structure" 或 "data.items")
|
|
48
|
+
* @template T 目标对象类型
|
|
49
|
+
* @template D 递归深度限制,默认 3 层 (足以覆盖大多数配置嵌套)
|
|
50
|
+
*/
|
|
51
|
+
export type Path<T, D extends number = 3> = [D] extends [never]
|
|
52
|
+
? never // A. 达到最大深度,终止
|
|
53
|
+
: T extends StopType
|
|
54
|
+
? never // B. 遇到终止类型,终止
|
|
55
|
+
: {
|
|
56
|
+
// C. 遍历所有有效的 Key,并移除可选修饰符 (-?) 以处理 undefined
|
|
57
|
+
[K in ValidKey<T>]-?: K extends string | number
|
|
58
|
+
? // 生成: 当前路径 K 或 "K + 子路径"
|
|
59
|
+
K | Join<K, Path<NonNullable<T[K]>, Prev[D]>>
|
|
60
|
+
: never;
|
|
61
|
+
}[ValidKey<T>]; // D. 提取所有生成路径的联合类型
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.2.
|
|
1
|
+
export const VERSION = '0.2.15';
|