@antv/infographic 0.1.3 → 0.1.4
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/infographic.min.js +110 -105
- package/dist/infographic.min.js.map +1 -1
- package/esm/constants/element.d.ts +1 -1
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +1 -0
- package/esm/constants/service.d.ts +1 -0
- package/esm/constants/service.js +1 -0
- package/esm/designs/components/Illus.js +1 -1
- package/esm/designs/structures/chart-wordcloud.d.ts +11 -0
- package/esm/designs/structures/chart-wordcloud.js +156 -0
- package/esm/designs/structures/hierarchy-tree.d.ts +2 -0
- package/esm/designs/structures/hierarchy-tree.js +179 -50
- package/esm/designs/structures/index.d.ts +2 -0
- package/esm/designs/structures/index.js +2 -0
- package/esm/designs/structures/sequence-stairs-front.d.ts +8 -0
- package/esm/designs/structures/sequence-stairs-front.js +116 -0
- package/esm/designs/types.d.ts +8 -0
- package/esm/editor/managers/state.js +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.js +1 -0
- package/esm/options/parser.d.ts +1 -1
- package/esm/options/parser.js +33 -15
- package/esm/renderer/composites/icon.js +1 -1
- package/esm/renderer/composites/illus.js +1 -1
- package/esm/resource/loader.d.ts +2 -2
- package/esm/resource/loader.js +22 -11
- package/esm/resource/loaders/index.d.ts +1 -0
- package/esm/resource/loaders/index.js +1 -0
- package/esm/resource/loaders/remote.d.ts +1 -1
- package/esm/resource/loaders/remote.js +10 -2
- package/esm/resource/loaders/search.d.ts +1 -0
- package/esm/resource/loaders/search.js +51 -0
- package/esm/resource/types/index.d.ts +1 -0
- package/esm/resource/types/resource.d.ts +8 -1
- package/esm/resource/types/scene.d.ts +1 -0
- package/esm/resource/utils/data-uri.js +20 -11
- package/esm/resource/utils/parser.js +92 -1
- package/esm/resource/utils/ref.js +2 -2
- package/esm/runtime/Infographic.d.ts +7 -6
- package/esm/runtime/Infographic.js +48 -17
- package/esm/runtime/utils.d.ts +4 -2
- package/esm/runtime/utils.js +33 -13
- package/esm/syntax/index.d.ts +3 -0
- package/esm/syntax/index.js +101 -0
- package/esm/syntax/mapper.d.ts +3 -0
- package/esm/syntax/mapper.js +238 -0
- package/esm/syntax/parser.d.ts +14 -0
- package/esm/syntax/parser.js +142 -0
- package/esm/syntax/schema.d.ts +6 -0
- package/esm/syntax/schema.js +74 -0
- package/esm/syntax/types.d.ts +61 -0
- package/esm/syntax/types.js +1 -0
- package/esm/templates/built-in.js +4 -0
- package/esm/templates/hierarchy-tree.js +25 -11
- package/esm/templates/sequence-stairs.d.ts +2 -0
- package/esm/templates/sequence-stairs.js +42 -0
- package/esm/templates/word-cloud.d.ts +2 -0
- package/esm/templates/word-cloud.js +19 -0
- package/esm/themes/types.d.ts +1 -1
- package/esm/utils/design.d.ts +2 -0
- package/esm/utils/design.js +10 -0
- package/esm/utils/font.js +11 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/lib/constants/element.d.ts +1 -1
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/constants/service.d.ts +1 -0
- package/lib/constants/service.js +4 -0
- package/lib/designs/components/Illus.js +1 -1
- package/lib/designs/structures/chart-wordcloud.d.ts +11 -0
- package/lib/designs/structures/chart-wordcloud.js +160 -0
- package/lib/designs/structures/hierarchy-tree.d.ts +2 -0
- package/lib/designs/structures/hierarchy-tree.js +179 -50
- package/lib/designs/structures/index.d.ts +2 -0
- package/lib/designs/structures/index.js +2 -0
- package/lib/designs/structures/sequence-stairs-front.d.ts +8 -0
- package/lib/designs/structures/sequence-stairs-front.js +120 -0
- package/lib/designs/types.d.ts +8 -0
- package/lib/editor/managers/state.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -1
- package/lib/options/parser.d.ts +1 -1
- package/lib/options/parser.js +32 -14
- package/lib/renderer/composites/icon.js +1 -1
- package/lib/renderer/composites/illus.js +1 -1
- package/lib/resource/loader.d.ts +2 -2
- package/lib/resource/loader.js +21 -10
- package/lib/resource/loaders/index.d.ts +1 -0
- package/lib/resource/loaders/index.js +1 -0
- package/lib/resource/loaders/remote.d.ts +1 -1
- package/lib/resource/loaders/remote.js +10 -2
- package/lib/resource/loaders/search.d.ts +1 -0
- package/lib/resource/loaders/search.js +54 -0
- package/lib/resource/types/index.d.ts +1 -0
- package/lib/resource/types/resource.d.ts +8 -1
- package/lib/resource/types/scene.d.ts +1 -0
- package/lib/resource/utils/data-uri.js +20 -11
- package/lib/resource/utils/parser.js +92 -1
- package/lib/resource/utils/ref.js +2 -2
- package/lib/runtime/Infographic.d.ts +7 -6
- package/lib/runtime/Infographic.js +47 -16
- package/lib/runtime/utils.d.ts +4 -2
- package/lib/runtime/utils.js +35 -13
- package/lib/syntax/index.d.ts +3 -0
- package/lib/syntax/index.js +104 -0
- package/lib/syntax/mapper.d.ts +3 -0
- package/lib/syntax/mapper.js +242 -0
- package/lib/syntax/parser.d.ts +14 -0
- package/lib/syntax/parser.js +146 -0
- package/lib/syntax/schema.d.ts +6 -0
- package/lib/syntax/schema.js +77 -0
- package/lib/syntax/types.d.ts +61 -0
- package/lib/syntax/types.js +2 -0
- package/lib/templates/built-in.js +4 -0
- package/lib/templates/hierarchy-tree.js +25 -11
- package/lib/templates/sequence-stairs.d.ts +2 -0
- package/lib/templates/sequence-stairs.js +45 -0
- package/lib/templates/word-cloud.d.ts +2 -0
- package/lib/templates/word-cloud.js +22 -0
- package/lib/themes/types.d.ts +1 -1
- package/lib/utils/design.d.ts +2 -0
- package/lib/utils/design.js +13 -0
- package/lib/utils/font.js +11 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/package.json +1 -1
- package/src/constants/element.ts +1 -1
- package/src/constants/index.ts +1 -0
- package/src/constants/service.ts +1 -0
- package/src/designs/components/Illus.tsx +1 -1
- package/src/designs/structures/chart-wordcloud.tsx +278 -0
- package/src/designs/structures/hierarchy-tree.tsx +212 -59
- package/src/designs/structures/index.ts +2 -0
- package/src/designs/structures/sequence-stairs-front.tsx +291 -0
- package/src/designs/types.ts +9 -0
- package/src/editor/managers/state.ts +1 -1
- package/src/index.ts +2 -0
- package/src/options/parser.ts +57 -28
- package/src/renderer/composites/icon.ts +1 -1
- package/src/renderer/composites/illus.ts +1 -1
- package/src/resource/loader.ts +22 -8
- package/src/resource/loaders/index.ts +1 -0
- package/src/resource/loaders/remote.ts +9 -2
- package/src/resource/loaders/search.ts +52 -0
- package/src/resource/types/index.ts +2 -1
- package/src/resource/types/resource.ts +12 -1
- package/src/resource/types/scene.ts +1 -0
- package/src/resource/utils/data-uri.ts +20 -11
- package/src/resource/utils/parser.ts +103 -2
- package/src/resource/utils/ref.ts +2 -2
- package/src/runtime/Infographic.tsx +74 -22
- package/src/runtime/utils.ts +38 -16
- package/src/syntax/index.ts +124 -0
- package/src/syntax/mapper.ts +362 -0
- package/src/syntax/parser.ts +171 -0
- package/src/syntax/schema.ts +98 -0
- package/src/syntax/types.ts +89 -0
- package/src/templates/built-in.ts +4 -0
- package/src/templates/hierarchy-tree.ts +34 -11
- package/src/templates/sequence-stairs.ts +44 -0
- package/src/templates/word-cloud.ts +21 -0
- package/src/themes/types.ts +1 -1
- package/src/utils/design.ts +14 -0
- package/src/utils/font.ts +11 -1
- package/src/utils/index.ts +1 -0
- package/esm/resource/types/font.d.ts +0 -12
- package/lib/resource/types/font.d.ts +0 -12
- package/src/resource/types/font.ts +0 -23
- /package/esm/resource/types/{font.js → scene.js} +0 -0
- /package/lib/resource/types/{font.js → scene.js} +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const string = () => ({ kind: 'string' });
|
|
2
|
+
const number = () => ({ kind: 'number' });
|
|
3
|
+
// const boolean = (): SchemaNode => ({ kind: 'boolean' });
|
|
4
|
+
const enumOf = (values) => ({ kind: 'enum', values });
|
|
5
|
+
const array = (item, split = 'any') => ({
|
|
6
|
+
kind: 'array',
|
|
7
|
+
item,
|
|
8
|
+
split,
|
|
9
|
+
});
|
|
10
|
+
const object = (fields, options = {}) => ({
|
|
11
|
+
kind: 'object',
|
|
12
|
+
fields,
|
|
13
|
+
allowUnknown: options.allowUnknown,
|
|
14
|
+
shorthandKey: options.shorthandKey,
|
|
15
|
+
});
|
|
16
|
+
const union = (...variants) => ({
|
|
17
|
+
kind: 'union',
|
|
18
|
+
variants,
|
|
19
|
+
});
|
|
20
|
+
const itemDatumSchema = object({});
|
|
21
|
+
itemDatumSchema.fields = {
|
|
22
|
+
label: string(),
|
|
23
|
+
value: union(number(), string()),
|
|
24
|
+
desc: string(),
|
|
25
|
+
icon: string(),
|
|
26
|
+
children: array(itemDatumSchema),
|
|
27
|
+
};
|
|
28
|
+
export const ThemeSchema = object({
|
|
29
|
+
type: string(),
|
|
30
|
+
colorBg: string(),
|
|
31
|
+
colorPrimary: string(),
|
|
32
|
+
palette: array(string(), 'any'),
|
|
33
|
+
title: object({}, { allowUnknown: true }),
|
|
34
|
+
desc: object({}, { allowUnknown: true }),
|
|
35
|
+
base: object({
|
|
36
|
+
global: object({}, { allowUnknown: true }),
|
|
37
|
+
shape: object({}, { allowUnknown: true }),
|
|
38
|
+
text: object({}, { allowUnknown: true }),
|
|
39
|
+
}),
|
|
40
|
+
stylize: object({
|
|
41
|
+
type: enumOf(['rough', 'pattern']),
|
|
42
|
+
roughness: number(),
|
|
43
|
+
bowing: number(),
|
|
44
|
+
fillWeight: number(),
|
|
45
|
+
hachureGap: number(),
|
|
46
|
+
pattern: string(),
|
|
47
|
+
backgroundColor: string(),
|
|
48
|
+
foregroundColor: string(),
|
|
49
|
+
scale: number(),
|
|
50
|
+
}, { shorthandKey: 'type' }),
|
|
51
|
+
}, { shorthandKey: 'type' });
|
|
52
|
+
const designNodeSchema = object({}, { allowUnknown: true, shorthandKey: 'type' });
|
|
53
|
+
export const DesignSchema = object({
|
|
54
|
+
structure: designNodeSchema,
|
|
55
|
+
item: designNodeSchema,
|
|
56
|
+
items: array(designNodeSchema),
|
|
57
|
+
title: designNodeSchema,
|
|
58
|
+
});
|
|
59
|
+
export const DataSchema = object({
|
|
60
|
+
title: string(),
|
|
61
|
+
desc: string(),
|
|
62
|
+
items: array(itemDatumSchema),
|
|
63
|
+
});
|
|
64
|
+
export const TemplateSchema = object({
|
|
65
|
+
type: string(),
|
|
66
|
+
}, { shorthandKey: 'type' });
|
|
67
|
+
export const RootSchema = object({
|
|
68
|
+
template: TemplateSchema,
|
|
69
|
+
design: DesignSchema,
|
|
70
|
+
data: DataSchema,
|
|
71
|
+
theme: ThemeSchema,
|
|
72
|
+
width: union(number(), string()),
|
|
73
|
+
height: union(number(), string()),
|
|
74
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { InfographicOptions } from '../options';
|
|
2
|
+
export type SyntaxNode = ValueNode | ObjectNode | ArrayNode;
|
|
3
|
+
export interface ValueNode {
|
|
4
|
+
kind: 'value';
|
|
5
|
+
line: number;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ObjectNode {
|
|
9
|
+
kind: 'object';
|
|
10
|
+
line: number;
|
|
11
|
+
value?: string;
|
|
12
|
+
entries: Record<string, SyntaxNode>;
|
|
13
|
+
}
|
|
14
|
+
export interface ArrayNode {
|
|
15
|
+
kind: 'array';
|
|
16
|
+
line: number;
|
|
17
|
+
items: SyntaxNode[];
|
|
18
|
+
}
|
|
19
|
+
export type SyntaxErrorCode = 'unknown_key' | 'schema_mismatch' | 'invalid_value' | 'bad_indent' | 'bad_list' | 'bad_syntax';
|
|
20
|
+
export interface SyntaxError {
|
|
21
|
+
path: string;
|
|
22
|
+
line: number;
|
|
23
|
+
code: SyntaxErrorCode;
|
|
24
|
+
message: string;
|
|
25
|
+
raw?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface SyntaxParseResult {
|
|
28
|
+
options: Partial<InfographicOptions>;
|
|
29
|
+
errors: SyntaxError[];
|
|
30
|
+
warnings: SyntaxError[];
|
|
31
|
+
ast?: ObjectNode;
|
|
32
|
+
}
|
|
33
|
+
export type SchemaNode = StringSchema | NumberSchema | BooleanSchema | EnumSchema | ArraySchema | ObjectSchema | UnionSchema;
|
|
34
|
+
export interface StringSchema {
|
|
35
|
+
kind: 'string';
|
|
36
|
+
}
|
|
37
|
+
export interface NumberSchema {
|
|
38
|
+
kind: 'number';
|
|
39
|
+
}
|
|
40
|
+
export interface BooleanSchema {
|
|
41
|
+
kind: 'boolean';
|
|
42
|
+
}
|
|
43
|
+
export interface EnumSchema {
|
|
44
|
+
kind: 'enum';
|
|
45
|
+
values: string[];
|
|
46
|
+
}
|
|
47
|
+
export interface ArraySchema {
|
|
48
|
+
kind: 'array';
|
|
49
|
+
item: SchemaNode;
|
|
50
|
+
split?: 'space' | 'comma' | 'any';
|
|
51
|
+
}
|
|
52
|
+
export interface ObjectSchema {
|
|
53
|
+
kind: 'object';
|
|
54
|
+
fields: Record<string, SchemaNode>;
|
|
55
|
+
allowUnknown?: boolean;
|
|
56
|
+
shorthandKey?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface UnionSchema {
|
|
59
|
+
kind: 'union';
|
|
60
|
+
variants: SchemaNode[];
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { hierarchyMindmapTemplates } from './hierarchy-mindmap';
|
|
2
2
|
import { hierarchyTreeTemplates } from './hierarchy-tree';
|
|
3
3
|
import { registerTemplate } from './registry';
|
|
4
|
+
import { sequenceStairsTemplates } from './sequence-stairs';
|
|
5
|
+
import { wordCloudTemplate } from './word-cloud';
|
|
4
6
|
const BUILT_IN_TEMPLATES = {
|
|
5
7
|
'compare-hierarchy-left-right-circle-node-pill-badge': {
|
|
6
8
|
design: {
|
|
@@ -801,6 +803,8 @@ const BUILT_IN_TEMPLATES = {
|
|
|
801
803
|
},
|
|
802
804
|
...hierarchyTreeTemplates,
|
|
803
805
|
...hierarchyMindmapTemplates,
|
|
806
|
+
...sequenceStairsTemplates,
|
|
807
|
+
...wordCloudTemplate,
|
|
804
808
|
};
|
|
805
809
|
Object.entries(BUILT_IN_TEMPLATES).forEach(([name, options]) => {
|
|
806
810
|
registerTemplate(name, options);
|
|
@@ -47,19 +47,33 @@ const items = [
|
|
|
47
47
|
];
|
|
48
48
|
export const hierarchyTreeTemplates = {};
|
|
49
49
|
const structureName = 'hierarchy-tree';
|
|
50
|
+
const orientationConfigs = [
|
|
51
|
+
{ key: '' },
|
|
52
|
+
{ key: 'bt', orientation: 'bottom-top' },
|
|
53
|
+
{ key: 'lr', orientation: 'left-right' },
|
|
54
|
+
{ key: 'rl', orientation: 'right-left' },
|
|
55
|
+
];
|
|
56
|
+
const createTemplateName = (oriKey, name, item) => {
|
|
57
|
+
return oriKey
|
|
58
|
+
? `${structureName}-${oriKey}-${name}-${item}`
|
|
59
|
+
: `${structureName}-${name}-${item}`;
|
|
60
|
+
};
|
|
50
61
|
for (const item of items) {
|
|
51
62
|
for (const [name, structureProps] of Object.entries(structures)) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
for (const { key, orientation } of orientationConfigs) {
|
|
64
|
+
const templateName = createTemplateName(key, name, item);
|
|
65
|
+
hierarchyTreeTemplates[templateName] = {
|
|
66
|
+
design: {
|
|
67
|
+
structure: {
|
|
68
|
+
type: 'hierarchy-tree',
|
|
69
|
+
...(orientation ? { orientation } : {}),
|
|
70
|
+
...structureProps,
|
|
71
|
+
},
|
|
72
|
+
item: {
|
|
73
|
+
type: item,
|
|
74
|
+
},
|
|
61
75
|
},
|
|
62
|
-
}
|
|
63
|
-
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
64
78
|
}
|
|
65
79
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const sequenceStairsTemplates = {
|
|
2
|
+
'sequence-stairs-front-pill-badge': {
|
|
3
|
+
design: {
|
|
4
|
+
title: 'default',
|
|
5
|
+
structure: {
|
|
6
|
+
type: 'sequence-stairs-front',
|
|
7
|
+
},
|
|
8
|
+
items: [
|
|
9
|
+
{
|
|
10
|
+
type: 'pill-badge',
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
'sequence-stairs-front-compact-card': {
|
|
16
|
+
design: {
|
|
17
|
+
title: 'default',
|
|
18
|
+
structure: {
|
|
19
|
+
type: 'sequence-stairs-front',
|
|
20
|
+
},
|
|
21
|
+
items: [
|
|
22
|
+
{
|
|
23
|
+
type: 'compact-card',
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
'sequence-stairs-front-simple': {
|
|
29
|
+
design: {
|
|
30
|
+
title: 'default',
|
|
31
|
+
structure: {
|
|
32
|
+
type: 'sequence-stairs-front',
|
|
33
|
+
},
|
|
34
|
+
items: [
|
|
35
|
+
{
|
|
36
|
+
type: 'simple',
|
|
37
|
+
usePaletteColor: true,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const wordCloudTemplate = {
|
|
2
|
+
'chart-wordcloud-rotate': {
|
|
3
|
+
design: {
|
|
4
|
+
structure: {
|
|
5
|
+
type: 'chart-wordcloud',
|
|
6
|
+
},
|
|
7
|
+
item: 'simple',
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
'chart-wordcloud': {
|
|
11
|
+
design: {
|
|
12
|
+
structure: {
|
|
13
|
+
type: 'chart-wordcloud',
|
|
14
|
+
enableRotate: false,
|
|
15
|
+
},
|
|
16
|
+
item: 'simple',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
package/esm/themes/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface ThemeConfig {
|
|
|
20
20
|
palette?: Palette;
|
|
21
21
|
title?: TextAttributes;
|
|
22
22
|
desc?: TextAttributes;
|
|
23
|
-
shape?:
|
|
23
|
+
shape?: ShapeAttributes;
|
|
24
24
|
item?: {
|
|
25
25
|
icon?: DynamicAttributes<IconAttributes>;
|
|
26
26
|
label?: DynamicAttributes<TextAttributes>;
|
package/esm/utils/font.js
CHANGED
|
@@ -13,21 +13,31 @@ export function encodeFontFamily(font) {
|
|
|
13
13
|
const FontWeightNameMap = {
|
|
14
14
|
'100': 'thin',
|
|
15
15
|
hairline: 'thin',
|
|
16
|
+
thin: 'thin',
|
|
16
17
|
'200': 'extralight',
|
|
17
18
|
ultralight: 'extralight',
|
|
19
|
+
extralight: 'extralight',
|
|
18
20
|
'300': 'light',
|
|
21
|
+
light: 'light',
|
|
19
22
|
'400': 'regular',
|
|
20
23
|
normal: 'regular',
|
|
24
|
+
regular: 'regular',
|
|
21
25
|
'500': 'medium',
|
|
26
|
+
medium: 'medium',
|
|
22
27
|
'600': 'semibold',
|
|
23
28
|
demibold: 'semibold',
|
|
29
|
+
semibold: 'semibold',
|
|
24
30
|
'700': 'bold',
|
|
31
|
+
bold: 'bold',
|
|
25
32
|
'800': 'extrabold',
|
|
26
|
-
ultrabold: '
|
|
33
|
+
ultrabold: 'extrabold',
|
|
34
|
+
extrabold: 'extrabold',
|
|
27
35
|
'900': 'black',
|
|
28
36
|
heavy: 'black',
|
|
37
|
+
black: 'black',
|
|
29
38
|
'950': 'extrablack',
|
|
30
39
|
ultrablack: 'extrablack',
|
|
40
|
+
extrablack: 'extrablack',
|
|
31
41
|
};
|
|
32
42
|
export function normalizeFontWeightName(fontWeight) {
|
|
33
43
|
const key = String(fontWeight).toLowerCase();
|
package/esm/utils/index.d.ts
CHANGED
package/esm/utils/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export declare const enum ElementTypeEnum {
|
|
|
11
11
|
ItemLabel = "item-label",
|
|
12
12
|
ItemDesc = "item-desc",
|
|
13
13
|
ItemValue = "item-value",
|
|
14
|
-
|
|
14
|
+
ItemIllus = "item-illus",
|
|
15
15
|
BtnAdd = "btn-add",
|
|
16
16
|
BtnRemove = "btn-remove",
|
|
17
17
|
IllusGroup = "illus-group",
|
package/lib/constants/index.d.ts
CHANGED
package/lib/constants/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./components"), exports);
|
|
18
18
|
__exportStar(require("./element"), exports);
|
|
19
|
+
__exportStar(require("./service"), exports);
|
|
19
20
|
__exportStar(require("./shape"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ICON_SERVICE_URL = "https://www.weavefox.cn/api/open/v1/icon";
|
|
@@ -10,7 +10,7 @@ const Illus = ({ indexes, ...props }) => {
|
|
|
10
10
|
const finalProps = { ...defaultProps, ...props };
|
|
11
11
|
if (indexes) {
|
|
12
12
|
finalProps['data-indexes'] = indexes;
|
|
13
|
-
finalProps['data-element-type'] = "
|
|
13
|
+
finalProps['data-element-type'] = "item-illus" /* ElementTypeEnum.ItemIllus */;
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
16
|
finalProps['data-element-type'] = "illus" /* ElementTypeEnum.Illus */;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComponentType } from '../../jsx';
|
|
2
|
+
import type { BaseStructureProps } from './types';
|
|
3
|
+
export interface ChartWordCloudProps extends BaseStructureProps {
|
|
4
|
+
minFontSize?: number;
|
|
5
|
+
maxFontSize?: number;
|
|
6
|
+
enableRotate?: boolean;
|
|
7
|
+
padding?: number;
|
|
8
|
+
spiralStep?: number;
|
|
9
|
+
radiusStep?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const ChartWordCloud: ComponentType<ChartWordCloudProps>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChartWordCloud = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@antv/infographic/jsx-runtime");
|
|
5
|
+
const jsx_1 = require("../../jsx");
|
|
6
|
+
const components_1 = require("../components");
|
|
7
|
+
const layouts_1 = require("../layouts");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const registry_1 = require("./registry");
|
|
10
|
+
const DEFAULT_ROTATE_ANGLES = [0, 30, -30, 60, -60];
|
|
11
|
+
const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
|
|
12
|
+
function getRotatedSize(width, height, angle) {
|
|
13
|
+
const rad = (Math.PI / 180) * angle;
|
|
14
|
+
const cos = Math.cos(rad);
|
|
15
|
+
const sin = Math.sin(rad);
|
|
16
|
+
return {
|
|
17
|
+
width: Math.abs(width * cos) + Math.abs(height * sin),
|
|
18
|
+
height: Math.abs(width * sin) + Math.abs(height * cos),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function hasCollision(x, y, width, height, placed, padding) {
|
|
22
|
+
const left = x - padding;
|
|
23
|
+
const right = x + width + padding;
|
|
24
|
+
const top = y - padding;
|
|
25
|
+
const bottom = y + height + padding;
|
|
26
|
+
return placed.some((word) => {
|
|
27
|
+
const wLeft = word.box.x - padding;
|
|
28
|
+
const wRight = word.box.x + word.box.width + padding;
|
|
29
|
+
const wTop = word.box.y - padding;
|
|
30
|
+
const wBottom = word.box.y + word.box.height + padding;
|
|
31
|
+
return !(right <= wLeft ||
|
|
32
|
+
left >= wRight ||
|
|
33
|
+
bottom <= wTop ||
|
|
34
|
+
top >= wBottom);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function placeWords(words, enableRotate, padding, spiralStep, radiusStep) {
|
|
38
|
+
const placed = [];
|
|
39
|
+
const rotationAngles = enableRotate ? DEFAULT_ROTATE_ANGLES : [0];
|
|
40
|
+
const maxAttempts = Math.max(1600, words.length * 28);
|
|
41
|
+
words.forEach((word, wordIndex) => {
|
|
42
|
+
const sizeBias = Math.max(word.width, word.height);
|
|
43
|
+
const angleOffset = wordIndex * GOLDEN_ANGLE;
|
|
44
|
+
let extraRadius = 0;
|
|
45
|
+
let placedWord = null;
|
|
46
|
+
for (let attempt = 0; attempt < maxAttempts && !placedWord; attempt++) {
|
|
47
|
+
if (attempt === Math.floor(maxAttempts * 0.6)) {
|
|
48
|
+
// Gradually expand the search radius for dense layouts
|
|
49
|
+
extraRadius = sizeBias;
|
|
50
|
+
}
|
|
51
|
+
const theta = angleOffset + attempt * spiralStep;
|
|
52
|
+
const radius = radiusStep * Math.sqrt(attempt + 1) + extraRadius + sizeBias * 0.25;
|
|
53
|
+
const centerX = radius * Math.cos(theta);
|
|
54
|
+
const centerY = radius * Math.sin(theta);
|
|
55
|
+
for (const angle of rotationAngles) {
|
|
56
|
+
const rotated = getRotatedSize(word.width, word.height, angle);
|
|
57
|
+
const x = centerX - rotated.width / 2;
|
|
58
|
+
const y = centerY - rotated.height / 2;
|
|
59
|
+
if (!hasCollision(x, y, rotated.width, rotated.height, placed, padding)) {
|
|
60
|
+
placedWord = {
|
|
61
|
+
...word,
|
|
62
|
+
angle,
|
|
63
|
+
centerX,
|
|
64
|
+
centerY,
|
|
65
|
+
box: { x, y, width: rotated.width, height: rotated.height },
|
|
66
|
+
};
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!placedWord) {
|
|
72
|
+
const fallbackAngle = rotationAngles[wordIndex % rotationAngles.length];
|
|
73
|
+
const farRadius = radiusStep * Math.sqrt(maxAttempts + 1) + sizeBias;
|
|
74
|
+
const theta = angleOffset;
|
|
75
|
+
const centerX = farRadius * Math.cos(theta);
|
|
76
|
+
const centerY = farRadius * Math.sin(theta);
|
|
77
|
+
const rotated = getRotatedSize(word.width, word.height, fallbackAngle);
|
|
78
|
+
placedWord = {
|
|
79
|
+
...word,
|
|
80
|
+
angle: fallbackAngle,
|
|
81
|
+
centerX,
|
|
82
|
+
centerY,
|
|
83
|
+
box: {
|
|
84
|
+
x: centerX - rotated.width / 2,
|
|
85
|
+
y: centerY - rotated.height / 2,
|
|
86
|
+
width: rotated.width,
|
|
87
|
+
height: rotated.height,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
placed.push(placedWord);
|
|
92
|
+
});
|
|
93
|
+
return placed;
|
|
94
|
+
}
|
|
95
|
+
const ChartWordCloud = (props) => {
|
|
96
|
+
const { data, options, minFontSize = 16, maxFontSize = 48, enableRotate = true, padding = 6, spiralStep = 0.45, radiusStep = 10, } = props;
|
|
97
|
+
const { items = [] } = data;
|
|
98
|
+
const validItems = items
|
|
99
|
+
.map((datum, index) => ({ datum, index }))
|
|
100
|
+
.filter(({ datum }) => datum.label);
|
|
101
|
+
if (validItems.length === 0) {
|
|
102
|
+
return ((0, jsx_runtime_1.jsx)(layouts_1.FlexLayout, { id: "infographic-container", flexDirection: "column", justifyContent: "center", alignItems: "center", children: (0, jsx_runtime_1.jsx)(jsx_1.Group, { children: (0, jsx_runtime_1.jsx)(components_1.ItemsGroup, {}) }) }));
|
|
103
|
+
}
|
|
104
|
+
const values = validItems
|
|
105
|
+
.map(({ datum }) => datum.value)
|
|
106
|
+
.filter((v) => typeof v === 'number');
|
|
107
|
+
const hasValues = values.length > 0;
|
|
108
|
+
const minValue = hasValues ? Math.min(...values) : 0;
|
|
109
|
+
const maxValue = hasValues ? Math.max(...values) : 0;
|
|
110
|
+
const sameValue = hasValues && minValue === maxValue;
|
|
111
|
+
const uniformSize = (minFontSize + maxFontSize) / 2;
|
|
112
|
+
const mapFontSize = (value) => {
|
|
113
|
+
if (!hasValues || sameValue)
|
|
114
|
+
return uniformSize;
|
|
115
|
+
if (value == null)
|
|
116
|
+
return minFontSize;
|
|
117
|
+
const ratio = (value - minValue) / (maxValue - minValue || 1);
|
|
118
|
+
return minFontSize + ratio * (maxFontSize - minFontSize);
|
|
119
|
+
};
|
|
120
|
+
const words = validItems
|
|
121
|
+
.map(({ datum, index }) => {
|
|
122
|
+
const fontSize = mapFontSize(datum.value);
|
|
123
|
+
const measured = (0, jsx_1.getElementBounds)((0, jsx_runtime_1.jsx)(jsx_1.Text, { fontSize: fontSize, fontWeight: "bold", children: datum.label }));
|
|
124
|
+
const color = (0, utils_1.getPaletteColor)(options, [index]) ||
|
|
125
|
+
(0, utils_1.getColorPrimary)(options) ||
|
|
126
|
+
'#333333';
|
|
127
|
+
return {
|
|
128
|
+
label: datum.label,
|
|
129
|
+
value: datum.value,
|
|
130
|
+
color,
|
|
131
|
+
fontSize,
|
|
132
|
+
width: measured.width * 1.05,
|
|
133
|
+
height: measured.height,
|
|
134
|
+
};
|
|
135
|
+
})
|
|
136
|
+
.sort((a, b) => b.fontSize - a.fontSize);
|
|
137
|
+
const placedWords = placeWords(words, enableRotate, padding, spiralStep, radiusStep);
|
|
138
|
+
const minX = Math.min(...placedWords.map((w) => w.box.x));
|
|
139
|
+
const minY = Math.min(...placedWords.map((w) => w.box.y));
|
|
140
|
+
const maxX = Math.max(...placedWords.map((w) => w.box.x + w.box.width));
|
|
141
|
+
const maxY = Math.max(...placedWords.map((w) => w.box.y + w.box.height));
|
|
142
|
+
const offsetX = -minX + padding;
|
|
143
|
+
const offsetY = -minY + padding;
|
|
144
|
+
const containerWidth = maxX - minX + padding * 2;
|
|
145
|
+
const containerHeight = maxY - minY + padding * 2;
|
|
146
|
+
const wordElements = placedWords.map((word, index) => {
|
|
147
|
+
const translateX = word.centerX - word.width / 2 + offsetX;
|
|
148
|
+
const translateY = word.centerY - word.height / 2 + offsetY;
|
|
149
|
+
const rotationOriginX = word.width / 2;
|
|
150
|
+
const rotationOriginY = word.height / 2;
|
|
151
|
+
const transform = `translate(${translateX}, ${translateY}) rotate(${word.angle}, ${rotationOriginX}, ${rotationOriginY})`;
|
|
152
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Group, { transform: transform, children: (0, jsx_runtime_1.jsx)(jsx_1.Text, { width: word.width, height: word.height, fontSize: word.fontSize, fontWeight: "bold", alignHorizontal: "center", alignVertical: "middle", fill: word.color, "data-indexes": index, "data-element-type": "item-label" /* ElementTypeEnum.ItemLabel */, children: word.label }) }));
|
|
153
|
+
});
|
|
154
|
+
return ((0, jsx_runtime_1.jsx)(components_1.ItemsGroup, { id: "infographic-container", width: containerWidth, height: containerHeight, children: wordElements }));
|
|
155
|
+
};
|
|
156
|
+
exports.ChartWordCloud = ChartWordCloud;
|
|
157
|
+
(0, registry_1.registerStructure)('chart-wordcloud', {
|
|
158
|
+
component: exports.ChartWordCloud,
|
|
159
|
+
composites: ['item'],
|
|
160
|
+
});
|
|
@@ -6,6 +6,8 @@ export interface HierarchyTreeProps extends BaseStructureProps {
|
|
|
6
6
|
levelGap?: number;
|
|
7
7
|
/** 节点间距:同级节点之间的水平距离,默认 60 */
|
|
8
8
|
nodeGap?: number;
|
|
9
|
+
/** 布局方向:'top-bottom' 自上而下 | 'bottom-top' 自下而上 | 'left-right' 自左向右 | 'right-left' 自右向左,默认 'top-bottom' */
|
|
10
|
+
orientation?: 'top-bottom' | 'bottom-top' | 'left-right' | 'right-left';
|
|
9
11
|
/** 连接线类型:'straight' 直线 | 'curved' 曲线,默认 'curved' */
|
|
10
12
|
edgeType?: 'straight' | 'curved';
|
|
11
13
|
/** 连接线颜色模式:'solid' 单色 | 'gradient' 渐变色,默认 'gradient' */
|