@antv/infographic 0.2.2 → 0.2.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.
Files changed (75) hide show
  1. package/README.md +43 -7
  2. package/README.zh-CN.md +43 -7
  3. package/dist/infographic.min.js +111 -111
  4. package/dist/infographic.min.js.map +1 -1
  5. package/esm/designs/layouts/Align.js +6 -6
  6. package/esm/designs/layouts/Flex.js +8 -6
  7. package/esm/designs/structures/chart-wordcloud.js +1 -1
  8. package/esm/designs/structures/hierarchy-structure.d.ts +45 -0
  9. package/esm/designs/structures/hierarchy-structure.js +266 -0
  10. package/esm/designs/structures/index.d.ts +2 -0
  11. package/esm/designs/structures/index.js +2 -0
  12. package/esm/designs/structures/list-zigzag.d.ts +11 -0
  13. package/esm/designs/structures/list-zigzag.js +240 -0
  14. package/esm/index.d.ts +1 -1
  15. package/esm/index.js +1 -1
  16. package/esm/renderer/composites/icon.d.ts +2 -5
  17. package/esm/renderer/composites/icon.js +5 -10
  18. package/esm/renderer/composites/illus.d.ts +3 -2
  19. package/esm/renderer/composites/illus.js +6 -2
  20. package/esm/renderer/composites/index.d.ts +2 -2
  21. package/esm/renderer/composites/index.js +2 -2
  22. package/esm/renderer/palettes/registry.d.ts +1 -1
  23. package/esm/renderer/palettes/registry.js +1 -1
  24. package/esm/renderer/renderer.js +6 -3
  25. package/esm/resource/loader.d.ts +2 -1
  26. package/esm/resource/loader.js +55 -23
  27. package/esm/templates/built-in.js +4 -0
  28. package/esm/templates/hierarchy-structure.d.ts +2 -0
  29. package/esm/templates/hierarchy-structure.js +21 -0
  30. package/esm/templates/list-zigzag.d.ts +2 -0
  31. package/esm/templates/list-zigzag.js +68 -0
  32. package/lib/designs/layouts/Align.js +6 -6
  33. package/lib/designs/layouts/Flex.js +8 -6
  34. package/lib/designs/structures/chart-wordcloud.js +1 -1
  35. package/lib/designs/structures/hierarchy-structure.d.ts +45 -0
  36. package/lib/designs/structures/hierarchy-structure.js +270 -0
  37. package/lib/designs/structures/index.d.ts +2 -0
  38. package/lib/designs/structures/index.js +2 -0
  39. package/lib/designs/structures/list-zigzag.d.ts +11 -0
  40. package/lib/designs/structures/list-zigzag.js +246 -0
  41. package/lib/index.d.ts +1 -1
  42. package/lib/index.js +3 -2
  43. package/lib/renderer/composites/icon.d.ts +2 -5
  44. package/lib/renderer/composites/icon.js +5 -11
  45. package/lib/renderer/composites/illus.d.ts +3 -2
  46. package/lib/renderer/composites/illus.js +7 -2
  47. package/lib/renderer/composites/index.d.ts +2 -2
  48. package/lib/renderer/composites/index.js +2 -2
  49. package/lib/renderer/palettes/registry.d.ts +1 -1
  50. package/lib/renderer/palettes/registry.js +1 -1
  51. package/lib/renderer/renderer.js +5 -2
  52. package/lib/resource/loader.d.ts +2 -1
  53. package/lib/resource/loader.js +55 -23
  54. package/lib/templates/built-in.js +4 -0
  55. package/lib/templates/hierarchy-structure.d.ts +2 -0
  56. package/lib/templates/hierarchy-structure.js +24 -0
  57. package/lib/templates/list-zigzag.d.ts +2 -0
  58. package/lib/templates/list-zigzag.js +71 -0
  59. package/package.json +1 -1
  60. package/src/designs/layouts/Align.tsx +6 -6
  61. package/src/designs/layouts/Flex.tsx +8 -6
  62. package/src/designs/structures/chart-wordcloud.tsx +1 -1
  63. package/src/designs/structures/hierarchy-structure.tsx +658 -0
  64. package/src/designs/structures/index.ts +2 -0
  65. package/src/designs/structures/list-zigzag.tsx +492 -0
  66. package/src/index.ts +2 -0
  67. package/src/renderer/composites/icon.ts +6 -16
  68. package/src/renderer/composites/illus.ts +12 -2
  69. package/src/renderer/composites/index.ts +2 -2
  70. package/src/renderer/palettes/registry.ts +2 -2
  71. package/src/renderer/renderer.ts +5 -11
  72. package/src/resource/loader.ts +54 -20
  73. package/src/templates/built-in.ts +4 -0
  74. package/src/templates/hierarchy-structure.ts +23 -0
  75. package/src/templates/list-zigzag.ts +70 -0
@@ -1,3 +1,4 @@
1
+ import type { ItemDatum } from '../types';
1
2
  import { getOrCreateDefs } from '../utils';
2
3
  import {
3
4
  loadImageBase64Resource,
@@ -12,34 +13,41 @@ import { getResourceId, parseResourceConfig } from './utils';
12
13
  async function getResource(
13
14
  scene: ResourceScene,
14
15
  config: string | ResourceConfig,
16
+ datum?: ItemDatum,
15
17
  ): Promise<Resource | null> {
16
18
  const cfg = parseResourceConfig(config);
17
19
  if (!cfg) return null;
18
20
  cfg.scene ||= scene;
19
21
  const { source, data, format, encoding } = cfg;
20
22
 
21
- if (source === 'inline') {
22
- const isDataURI = data.startsWith('data:');
23
- if (format === 'svg' && encoding === 'raw') {
24
- return loadSVGResource(data);
23
+ let resource: Resource | null = null;
24
+ try {
25
+ if (source === 'inline') {
26
+ const isDataURI = data.startsWith('data:');
27
+ if (format === 'svg' && encoding === 'raw') {
28
+ resource = loadSVGResource(data);
29
+ } else if (format === 'svg' && isDataURI) {
30
+ resource = await loadImageBase64Resource(data);
31
+ } else if (isDataURI || format === 'image') {
32
+ resource = await loadImageBase64Resource(data);
33
+ } else {
34
+ resource = loadSVGResource(data);
35
+ }
36
+ } else if (source === 'remote') {
37
+ resource = await loadRemoteResource(data, format);
38
+ } else if (source === 'search') {
39
+ resource = await loadSearchResource(data, format);
40
+ } else {
41
+ const customLoader = getCustomResourceLoader();
42
+ if (customLoader) resource = await customLoader(cfg);
25
43
  }
26
- if (format === 'svg' && isDataURI) {
27
- return await loadImageBase64Resource(data);
28
- }
29
- if (isDataURI || format === 'image') {
30
- return await loadImageBase64Resource(data);
31
- }
32
- return loadSVGResource(data);
33
- } else if (source === 'remote') {
34
- return await loadRemoteResource(data, format);
35
- } else if (source === 'search') {
36
- return await loadSearchResource(data, format);
37
- } else {
38
- const customLoader = getCustomResourceLoader();
39
- if (customLoader) return await customLoader(cfg);
44
+ } catch {
45
+ resource = null;
40
46
  }
41
47
 
42
- return null;
48
+ if (resource) return resource;
49
+
50
+ return await loadSearchResource(getFallbackQuery(cfg, scene, datum), format);
43
51
  }
44
52
 
45
53
  const RESOURCE_MAP = new Map<string, Resource>();
@@ -53,6 +61,7 @@ export async function loadResource(
53
61
  svg: SVGSVGElement | null,
54
62
  scene: ResourceScene,
55
63
  config: string | ResourceConfig,
64
+ datum?: ItemDatum,
56
65
  ): Promise<string | null> {
57
66
  if (!svg) return null;
58
67
  const cfg = parseResourceConfig(config);
@@ -61,7 +70,7 @@ export async function loadResource(
61
70
 
62
71
  const resource = RESOURCE_MAP.has(id)
63
72
  ? RESOURCE_MAP.get(id) || null
64
- : await getResource(scene, cfg);
73
+ : await getResource(scene, cfg, datum);
65
74
 
66
75
  if (!resource) return null;
67
76
 
@@ -76,3 +85,28 @@ export async function loadResource(
76
85
 
77
86
  return id;
78
87
  }
88
+
89
+ function getFallbackQuery(
90
+ cfg: ResourceConfig,
91
+ scene: ResourceScene,
92
+ datum?: ItemDatum,
93
+ ): string {
94
+ const defaultQuery = scene === 'illus' ? 'illustration' : 'icon';
95
+ const datumQuery =
96
+ normalizeQuery(datum?.label) || normalizeQuery(datum?.desc);
97
+ if (datumQuery) return datumQuery;
98
+
99
+ const data = normalizeQuery(cfg.data);
100
+ if (!data) return defaultQuery;
101
+ if (cfg.source === 'inline') return defaultQuery;
102
+ if (data.startsWith('data:')) return defaultQuery;
103
+ if (data.startsWith('<svg') || data.startsWith('<symbol'))
104
+ return defaultQuery;
105
+ return data;
106
+ }
107
+
108
+ function normalizeQuery(value?: string): string | null {
109
+ if (typeof value !== 'string') return null;
110
+ const trimmed = value.trim();
111
+ return trimmed ? trimmed : null;
112
+ }
@@ -1,5 +1,7 @@
1
1
  import { hierarchyMindmapTemplates } from './hierarchy-mindmap';
2
+ import { hierarchyStructureTemplates } from './hierarchy-structure';
2
3
  import { hierarchyTreeTemplates } from './hierarchy-tree';
4
+ import { listZigzagTemplates } from './list-zigzag';
3
5
  import { registerTemplate } from './registry';
4
6
  import { sequenceStairsTemplates } from './sequence-stairs';
5
7
  import type { TemplateOptions } from './types';
@@ -807,6 +809,8 @@ const BUILT_IN_TEMPLATES: Record<string, TemplateOptions> = {
807
809
  ...hierarchyMindmapTemplates,
808
810
  ...sequenceStairsTemplates,
809
811
  ...wordCloudTemplate,
812
+ ...listZigzagTemplates,
813
+ ...hierarchyStructureTemplates,
810
814
  };
811
815
 
812
816
  Object.entries(BUILT_IN_TEMPLATES).forEach(([name, options]) => {
@@ -0,0 +1,23 @@
1
+ import type { TemplateOptions } from './types';
2
+
3
+ export const hierarchyStructureTemplates: Record<string, TemplateOptions> = {
4
+ 'hierarchy-structure': {
5
+ design: {
6
+ title: 'default',
7
+ structure: {
8
+ type: 'hierarchy-structure',
9
+ },
10
+ item: 'simple',
11
+ },
12
+ },
13
+ 'hierarchy-structure-mirror': {
14
+ design: {
15
+ title: 'default',
16
+ structure: {
17
+ type: 'hierarchy-structure',
18
+ layerLabelPosition: 'right',
19
+ },
20
+ item: 'simple',
21
+ },
22
+ },
23
+ };
@@ -0,0 +1,70 @@
1
+ import type { TemplateOptions } from './types';
2
+
3
+ export const listZigzagTemplates: Record<string, TemplateOptions> = {
4
+ 'list-zigzag-up-compact-card': {
5
+ design: {
6
+ title: 'default',
7
+ structure: {
8
+ type: 'list-zigzag-up',
9
+ },
10
+ items: [
11
+ {
12
+ type: 'compact-card',
13
+ },
14
+ ],
15
+ },
16
+ themeConfig: {
17
+ colorPrimary: '#17CA2C',
18
+ },
19
+ },
20
+ 'list-zigzag-up-simple': {
21
+ design: {
22
+ title: 'default',
23
+ structure: {
24
+ type: 'list-zigzag-up',
25
+ },
26
+ items: [
27
+ {
28
+ type: 'simple',
29
+ usePaletteColor: true,
30
+ },
31
+ ],
32
+ },
33
+ themeConfig: {
34
+ colorPrimary: '#17CA2C',
35
+ },
36
+ },
37
+ 'list-zigzag-down-compact-card': {
38
+ design: {
39
+ title: 'default',
40
+ structure: {
41
+ type: 'list-zigzag-down',
42
+ },
43
+ items: [
44
+ {
45
+ type: 'compact-card',
46
+ },
47
+ ],
48
+ },
49
+ themeConfig: {
50
+ colorPrimary: '#17CA2C',
51
+ },
52
+ },
53
+ 'list-zigzag-down-simple': {
54
+ design: {
55
+ title: 'default',
56
+ structure: {
57
+ type: 'list-zigzag-down',
58
+ },
59
+ items: [
60
+ {
61
+ type: 'simple',
62
+ usePaletteColor: true,
63
+ },
64
+ ],
65
+ },
66
+ themeConfig: {
67
+ colorPrimary: '#17CA2C',
68
+ },
69
+ },
70
+ };