@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
@@ -0,0 +1,492 @@
1
+ import tinycolor from 'tinycolor2';
2
+ import type { ComponentType, JSXElement } from '../../jsx';
3
+ import { getElementBounds, Group } from '../../jsx';
4
+ import { BtnAdd, BtnRemove, BtnsGroup, ItemsGroup } from '../components';
5
+ import { FlexLayout } from '../layouts';
6
+ import { getColorPrimary, getThemeColors } from '../utils';
7
+ import { registerStructure } from './registry';
8
+ import type { BaseStructureProps } from './types';
9
+
10
+ export interface ListZigzagProps extends BaseStructureProps {
11
+ itemGap?: number;
12
+ }
13
+
14
+ export interface ListZigzagDownProps extends ListZigzagProps {}
15
+
16
+ export interface ListZigzagUpProps extends ListZigzagProps {}
17
+
18
+ const MAX_ITEMS = 6;
19
+ const ARROW_WIDTH = 700;
20
+ const ARROW_HEIGHT_DOWN = 330;
21
+ const ARROW_HEIGHT_UP = 333;
22
+
23
+ type AnchorPosition =
24
+ | 'center'
25
+ | 'top'
26
+ | 'bottom'
27
+ | 'top-left'
28
+ | 'top-right'
29
+ | 'bottom-left'
30
+ | 'bottom-right';
31
+
32
+ type AnchorPoint = {
33
+ x: number;
34
+ y: number;
35
+ anchor?: AnchorPosition;
36
+ };
37
+
38
+ type ZigzagArrowProps = {
39
+ colorPrimary?: string;
40
+ colorShadow?: string;
41
+ };
42
+
43
+ type ZigzagConfig = {
44
+ arrowHeight: number;
45
+ presetRatios: Record<number, AnchorPoint[]>;
46
+ Arrow: ComponentType<ZigzagArrowProps>;
47
+ };
48
+
49
+ const PRESET_RATIOS_DOWN: Record<number, AnchorPoint[]> = {
50
+ 1: [{ x: 0.5, y: 0.6, anchor: 'top-right' }],
51
+ 2: [
52
+ { x: 0.42, y: 0.5, anchor: 'top-right' },
53
+ { x: 0.72, y: 0.4, anchor: 'bottom' },
54
+ ],
55
+ 3: [
56
+ { x: 0.3, y: 0.5, anchor: 'top-right' },
57
+ { x: 0.48, y: 0.3, anchor: 'bottom-left' },
58
+ { x: 0.8, y: 0.75, anchor: 'top-right' },
59
+ ],
60
+ 4: [
61
+ { x: 0.3, y: 0.5, anchor: 'top-right' },
62
+ { x: 0.35, y: 0.2, anchor: 'bottom-left' },
63
+ { x: 0.65, y: 0.73, anchor: 'top-right' },
64
+ { x: 0.8, y: 0.52, anchor: 'bottom-left' },
65
+ ],
66
+ 5: [
67
+ { x: 0.19, y: 0.4, anchor: 'top-right' },
68
+ { x: 0.38, y: 0.2, anchor: 'bottom' },
69
+ { x: 0.52, y: 0.62, anchor: 'top-right' },
70
+ { x: 0.7, y: 0.43, anchor: 'bottom' },
71
+ { x: 0.82, y: 0.8, anchor: 'top-right' },
72
+ ],
73
+ 6: [
74
+ { x: 0.16, y: 0.35, anchor: 'top-right' },
75
+ { x: 0.38, y: 0.2, anchor: 'bottom' },
76
+ { x: 0.48, y: 0.54, anchor: 'top-right' },
77
+ { x: 0.55, y: 0.43, anchor: 'bottom-left' },
78
+ { x: 0.8, y: 0.75, anchor: 'top-right' },
79
+ { x: 0.86, y: 0.65, anchor: 'bottom-left' },
80
+ ],
81
+ };
82
+
83
+ const PRESET_RATIOS_UP: Record<number, AnchorPoint[]> = {
84
+ 1: [{ x: 0.5, y: 0.4, anchor: 'bottom-right' }],
85
+ 2: [
86
+ { x: 0.42, y: 0.5, anchor: 'bottom-right' },
87
+ { x: 0.72, y: 0.6, anchor: 'top' },
88
+ ],
89
+ 3: [
90
+ { x: 0.3, y: 0.5, anchor: 'bottom-right' },
91
+ { x: 0.48, y: 0.7, anchor: 'top-left' },
92
+ { x: 0.8, y: 0.25, anchor: 'bottom-right' },
93
+ ],
94
+ 4: [
95
+ { x: 0.3, y: 0.5, anchor: 'bottom-right' },
96
+ { x: 0.35, y: 0.8, anchor: 'top-left' },
97
+ { x: 0.65, y: 0.27, anchor: 'bottom-right' },
98
+ { x: 0.8, y: 0.48, anchor: 'top-left' },
99
+ ],
100
+ 5: [
101
+ { x: 0.19, y: 0.6, anchor: 'bottom-right' },
102
+ { x: 0.38, y: 0.8, anchor: 'top' },
103
+ { x: 0.52, y: 0.38, anchor: 'bottom-right' },
104
+ { x: 0.7, y: 0.57, anchor: 'top' },
105
+ { x: 0.82, y: 0.2, anchor: 'bottom-right' },
106
+ ],
107
+ 6: [
108
+ { x: 0.16, y: 0.65, anchor: 'bottom-right' },
109
+ { x: 0.38, y: 0.8, anchor: 'top' },
110
+ { x: 0.48, y: 0.46, anchor: 'bottom-right' },
111
+ { x: 0.55, y: 0.57, anchor: 'top-left' },
112
+ { x: 0.8, y: 0.25, anchor: 'bottom-right' },
113
+ { x: 0.86, y: 0.35, anchor: 'top-left' },
114
+ ],
115
+ };
116
+
117
+ const getPresetPoints = (
118
+ count: number,
119
+ presetRatios: Record<number, AnchorPoint[]>,
120
+ arrowHeight: number,
121
+ ) => {
122
+ const ratios = presetRatios[count];
123
+ if (!ratios) return null;
124
+ return ratios.map((point) => ({
125
+ x: point.x * ARROW_WIDTH,
126
+ y: point.y * arrowHeight,
127
+ anchor: point.anchor,
128
+ }));
129
+ };
130
+
131
+ const getAnchoredPosition = (
132
+ point: AnchorPoint,
133
+ size: { width: number; height: number },
134
+ ) => {
135
+ const anchor = point.anchor || 'center';
136
+ let x = point.x - size.width / 2;
137
+ let y = point.y - size.height / 2;
138
+ let centerY = point.y;
139
+
140
+ switch (anchor) {
141
+ case 'top':
142
+ x = point.x - size.width / 2;
143
+ y = point.y;
144
+ centerY = point.y + size.height / 2;
145
+ break;
146
+ case 'bottom':
147
+ x = point.x - size.width / 2;
148
+ y = point.y - size.height;
149
+ centerY = point.y - size.height / 2;
150
+ break;
151
+ case 'top-left':
152
+ x = point.x;
153
+ y = point.y;
154
+ centerY = point.y + size.height / 2;
155
+ break;
156
+ case 'top-right':
157
+ x = point.x - size.width;
158
+ y = point.y;
159
+ centerY = point.y + size.height / 2;
160
+ break;
161
+ case 'bottom-left':
162
+ x = point.x;
163
+ y = point.y - size.height;
164
+ centerY = point.y - size.height / 2;
165
+ break;
166
+ case 'bottom-right':
167
+ x = point.x - size.width;
168
+ y = point.y - size.height;
169
+ centerY = point.y - size.height / 2;
170
+ break;
171
+ default:
172
+ break;
173
+ }
174
+
175
+ return { x, y, centerY };
176
+ };
177
+
178
+ const getUnitVector = (
179
+ from: { x: number; y: number },
180
+ to: {
181
+ x: number;
182
+ y: number;
183
+ },
184
+ ) => {
185
+ const dx = to.x - from.x;
186
+ const dy = to.y - from.y;
187
+ const length = Math.hypot(dx, dy) || 1;
188
+ return { x: dx / length, y: dy / length };
189
+ };
190
+
191
+ const createListZigzag = (config: ZigzagConfig) => {
192
+ const { presetRatios, arrowHeight, Arrow } = config;
193
+ const ListZigzag: ComponentType<ListZigzagProps> = (props) => {
194
+ const { Title, Item, data, options, itemGap = 24 } = props;
195
+ const { title, desc, items = [] } = data;
196
+ const layoutCount = Math.min(items.length, MAX_ITEMS);
197
+ const displayItems = items.slice(0, layoutCount);
198
+
199
+ const titleContent = Title ? <Title title={title} desc={desc} /> : null;
200
+ const colorPrimary = getColorPrimary(options);
201
+ const themeColors = getThemeColors({ colorPrimary }, options);
202
+ const colorShadow = themeColors.colorTextSecondary || '#737373';
203
+
204
+ const btnBounds = getElementBounds(<BtnAdd indexes={[0]} />);
205
+
206
+ if (items.length === 0) {
207
+ const anchor = getPresetPoints(1, presetRatios, arrowHeight)?.[0];
208
+ if (!anchor) {
209
+ return (
210
+ <FlexLayout
211
+ id="infographic-container"
212
+ flexDirection="column"
213
+ justifyContent="center"
214
+ alignItems="center"
215
+ >
216
+ {titleContent}
217
+ <Group>
218
+ <Arrow colorPrimary={colorPrimary} colorShadow={colorShadow} />
219
+ </Group>
220
+ </FlexLayout>
221
+ );
222
+ }
223
+ const btnX = anchor.x - btnBounds.width / 2;
224
+ const btnY = anchor.y - btnBounds.height / 2;
225
+ return (
226
+ <FlexLayout
227
+ id="infographic-container"
228
+ flexDirection="column"
229
+ justifyContent="center"
230
+ alignItems="center"
231
+ >
232
+ {titleContent}
233
+ <Group>
234
+ <Arrow colorPrimary={colorPrimary} colorShadow={colorShadow} />
235
+ <ItemsGroup />
236
+ <BtnsGroup>
237
+ <BtnAdd indexes={[0]} x={btnX} y={btnY} />
238
+ </BtnsGroup>
239
+ </Group>
240
+ </FlexLayout>
241
+ );
242
+ }
243
+
244
+ const itemBounds = getElementBounds(
245
+ <Item indexes={[0]} data={data} datum={items[0]} positionH="center" />,
246
+ );
247
+
248
+ const btnElements: JSXElement[] = [];
249
+ const itemElements: JSXElement[] = [];
250
+ const presetPoints = getPresetPoints(
251
+ layoutCount,
252
+ presetRatios,
253
+ arrowHeight,
254
+ );
255
+ if (!presetPoints) {
256
+ return (
257
+ <FlexLayout
258
+ id="infographic-container"
259
+ flexDirection="column"
260
+ justifyContent="center"
261
+ alignItems="center"
262
+ >
263
+ {titleContent}
264
+ <Group>
265
+ <Arrow colorPrimary={colorPrimary} colorShadow={colorShadow} />
266
+ <ItemsGroup />
267
+ </Group>
268
+ </FlexLayout>
269
+ );
270
+ }
271
+ const anchorPoints = presetPoints;
272
+ const baseDirection =
273
+ anchorPoints.length > 1
274
+ ? getUnitVector(anchorPoints[0], anchorPoints[anchorPoints.length - 1])
275
+ : { x: 1, y: 0 };
276
+ const startDirection =
277
+ anchorPoints.length > 1
278
+ ? getUnitVector(anchorPoints[0], anchorPoints[1])
279
+ : baseDirection;
280
+ const endDirection =
281
+ anchorPoints.length > 1
282
+ ? getUnitVector(
283
+ anchorPoints[anchorPoints.length - 2],
284
+ anchorPoints[anchorPoints.length - 1],
285
+ )
286
+ : baseDirection;
287
+ const addOffset =
288
+ Math.max(itemBounds.width, itemBounds.height) * 0.45 + itemGap;
289
+
290
+ const toItemPosition = (point: AnchorPoint) => {
291
+ const { x, y, centerY } = getAnchoredPosition(point, itemBounds);
292
+ return { x, y, centerY };
293
+ };
294
+
295
+ anchorPoints.forEach((anchor, index) => {
296
+ const itemPosition = toItemPosition(anchor);
297
+ const isTop = itemPosition.centerY < arrowHeight / 2;
298
+ const indexes = [index];
299
+ const item = displayItems[index];
300
+ if (!item) return;
301
+
302
+ itemElements.push(
303
+ <Item
304
+ indexes={indexes}
305
+ datum={item}
306
+ data={data}
307
+ x={itemPosition.x}
308
+ y={itemPosition.y}
309
+ positionH="center"
310
+ />,
311
+ );
312
+
313
+ const btnRemoveX =
314
+ itemPosition.x + itemBounds.width - btnBounds.width / 2;
315
+ const btnRemoveY = isTop
316
+ ? itemPosition.y - btnBounds.height / 2
317
+ : itemPosition.y + itemBounds.height - btnBounds.height / 2;
318
+ btnElements.push(
319
+ <BtnRemove indexes={indexes} x={btnRemoveX} y={btnRemoveY} />,
320
+ );
321
+ });
322
+
323
+ if (anchorPoints.length > 0) {
324
+ const firstAnchor = anchorPoints[0];
325
+ const firstAddX =
326
+ firstAnchor.x - startDirection.x * addOffset - btnBounds.width / 2;
327
+ const firstAddY =
328
+ firstAnchor.y - startDirection.y * addOffset - btnBounds.height / 2;
329
+ btnElements.push(<BtnAdd indexes={[0]} x={firstAddX} y={firstAddY} />);
330
+
331
+ for (let index = 0; index < anchorPoints.length - 1; index++) {
332
+ const current = anchorPoints[index];
333
+ const next = anchorPoints[index + 1];
334
+ const midX = (current.x + next.x) / 2;
335
+ const midY = (current.y + next.y) / 2;
336
+ const midAddX = midX - btnBounds.width / 2;
337
+ const midAddY = midY - btnBounds.height / 2;
338
+ btnElements.push(
339
+ <BtnAdd indexes={[index + 1]} x={midAddX} y={midAddY} />,
340
+ );
341
+ }
342
+
343
+ const lastAnchor = anchorPoints[anchorPoints.length - 1];
344
+ const lastAddX =
345
+ lastAnchor.x + endDirection.x * addOffset - btnBounds.width / 2;
346
+ const lastAddY =
347
+ lastAnchor.y + endDirection.y * addOffset - btnBounds.height / 2;
348
+ btnElements.push(
349
+ <BtnAdd indexes={[layoutCount]} x={lastAddX} y={lastAddY} />,
350
+ );
351
+ }
352
+
353
+ return (
354
+ <FlexLayout
355
+ id="infographic-container"
356
+ flexDirection="column"
357
+ justifyContent="center"
358
+ alignItems="center"
359
+ >
360
+ {titleContent}
361
+ <Group>
362
+ <Arrow colorPrimary={colorPrimary} colorShadow={colorShadow} />
363
+ <ItemsGroup>{itemElements}</ItemsGroup>
364
+ <BtnsGroup>{btnElements}</BtnsGroup>
365
+ </Group>
366
+ </FlexLayout>
367
+ );
368
+ };
369
+
370
+ return ListZigzag;
371
+ };
372
+
373
+ const ArrowDown: ComponentType<ZigzagArrowProps> = ({
374
+ colorPrimary = '#17CA2C',
375
+ colorShadow = '#737373',
376
+ }) => {
377
+ const colorPrimaryDark = tinycolor(colorPrimary).darken(20).toHexString();
378
+ return (
379
+ <Group width={ARROW_WIDTH} height={ARROW_HEIGHT_DOWN}>
380
+ <path
381
+ d="M228.864 159.446C230.266 159.446 231.623 158.768 232.689 157.535L274.263 110.162L265.717 102.923L227.311 148.082C225.977 149.623 224.281 150.47 222.529 150.47H175.404L182.03 158.367C182.795 159.445 182.795 159.446 183.734 159.446H228.864Z"
382
+ fill={colorShadow}
383
+ />
384
+ <path
385
+ d="M462.869 234.92C464.271 234.92 465.628 234.242 466.695 233.01L508.268 185.636L499.722 178.397L461.316 223.557C459.983 225.098 458.287 225.945 456.534 225.945H409.409L416.035 233.841C416.8 234.92 416.8 234.92 417.74 234.92H462.869Z"
386
+ fill={colorShadow}
387
+ />
388
+ <path
389
+ d="M697.005 330C698.783 330 700 328.82 700 327.001V256.638C700 254.857 697.848 253.965 696.591 255.225L693.409 258.411V320.402C693.409 322.058 692.069 323.401 690.414 323.401H630.718L627.536 326.587C626.278 327.847 627.169 330 628.947 330H697.005Z"
390
+ fill={colorShadow}
391
+ />
392
+ <path
393
+ d="M689.642 321.89C690.744 321.89 691.638 320.995 691.638 319.891V250.743C691.638 248.962 689.488 248.07 688.23 249.329L662.647 274.947L520.987 153.863C519.541 152.627 517.703 151.948 515.802 151.948H469.518C470.236 151.949 470.956 152.206 471.53 152.729L498.163 176.978L498.13 177.018L639.84 297.784L619.174 318.477C617.916 319.737 618.807 321.89 620.586 321.89H689.642Z"
394
+ fill={colorPrimary}
395
+ />
396
+ <path
397
+ d="M429.279 198.995L467.208 153.03C468.3 151.716 470.268 151.579 471.531 152.729L498.163 176.978L460.69 221.107C459.173 222.894 456.946 223.924 454.6 223.924H408.473C409.366 223.924 410.252 223.527 410.845 222.764L429.279 198.995Z"
398
+ fill={colorPrimaryDark}
399
+ />
400
+ <path
401
+ d="M408.473 223.924H408.314L408.318 223.92C408.369 223.922 408.421 223.924 408.473 223.924Z"
402
+ fill={colorPrimaryDark}
403
+ />
404
+ <path
405
+ d="M406.524 223.203C407.826 224.318 409.796 224.116 410.845 222.761L429.279 198.932L287.411 77.8866C285.964 76.6523 284.125 75.9742 282.223 75.9742H234.606L234.625 75.9907C235.429 75.9118 236.263 76.1557 236.915 76.7378L263.662 100.621L263.546 100.758L406.524 223.203Z"
406
+ fill={colorPrimary}
407
+ />
408
+ <path
409
+ d="M236.914 76.7386C235.651 75.6097 233.707 75.7513 232.621 77.0513L194.557 123.104L175.644 146.821C175.076 147.535 174.25 147.917 173.409 147.947L173.407 147.95H219.923C222.271 147.95 224.499 146.915 226.017 145.122L263.645 100.649L236.914 76.7386Z"
410
+ fill={colorPrimaryDark}
411
+ />
412
+ <path
413
+ d="M175.648 146.816C174.589 148.145 172.637 148.329 171.348 147.221L4.09334 3.51697C2.68586 2.30767 3.54106 0 5.39671 0H47.5805C49.4864 0 51.3297 0.680433 52.7785 1.91877L194.557 123.104L175.648 146.816Z"
414
+ fill={colorPrimary}
415
+ />
416
+ </Group>
417
+ );
418
+ };
419
+
420
+ const ArrowUp: ComponentType<ZigzagArrowProps> = ({
421
+ colorPrimary = '#17CA2C',
422
+ colorShadow = '#737373',
423
+ }) => {
424
+ const colorPrimaryDark = tinycolor(colorPrimary).darken(20).toHexString();
425
+ return (
426
+ <Group width={ARROW_WIDTH} height={ARROW_HEIGHT_UP}>
427
+ <path
428
+ d="M19.0526 324L12.6762 329.482C11.2703 330.691 12.1234 333 13.976 333H56.1578C58.058 333 59.896 332.321 61.3413 331.085L201.854 210.901L194.249 201.693L54.0527 321.606C52.246 323.151 49.9486 324 47.5732 324H19.0526Z"
429
+ fill={colorShadow}
430
+ />
431
+ <path
432
+ d="M234.587 248L241.131 255.922C241.656 256.552 242.382 256.909 243.134 256.983L243.115 257H290.716C292.618 257 294.457 256.322 295.903 255.087L437.091 134.536L429.305 125.5L288.613 245.609C286.805 247.153 284.507 248 282.132 248H234.587Z"
433
+ fill={colorShadow}
434
+ />
435
+ <path
436
+ d="M461.123 162.429L475.642 179.918C476.237 180.635 477.092 181.001 477.951 181H524.22C526.121 181 527.959 180.321 529.404 179.085L670.786 58.1578L662.326 49.6809L522.115 169.606C520.309 171.151 518.011 172 515.636 172H469.369L461.123 162.429Z"
437
+ fill={colorShadow}
438
+ />
439
+ <path
440
+ d="M687.912 74.8875C690.374 75.9052 693.412 74.1668 693.412 71.1716V11H698.004C699.106 11 700 11.8954 700 13V82.1716C700 83.9534 697.85 84.8457 696.593 83.5858L687.912 74.8875Z"
441
+ fill={colorShadow}
442
+ />
443
+ <path
444
+ d="M689.419 0C690.522 0 691.415 0.895432 691.415 2V71.1716C691.415 72.9534 689.265 73.8457 688.008 72.5858L662.433 46.9598L520.819 168.085C519.374 169.321 517.536 170 515.636 170H469.367C470.084 169.999 470.804 169.742 471.379 169.219L498.003 144.961L497.969 144.922L639.634 24.115L618.975 3.41421C617.717 2.15428 618.608 0 620.386 0H689.419Z"
445
+ fill={colorPrimary}
446
+ />
447
+ <path
448
+ d="M429.141 122.937L467.058 168.918C468.149 170.232 470.116 170.369 471.378 169.219L498.003 144.961L460.542 100.818C459.025 99.0305 456.798 98 454.453 98H408.341C409.234 98.0001 410.12 98.3968 410.712 99.1606L429.141 122.937Z"
449
+ fill={colorPrimaryDark}
450
+ />
451
+ <path
452
+ d="M408.341 98H408.183L408.186 98.004C408.237 98.0013 408.289 98 408.341 98Z"
453
+ fill={colorPrimaryDark}
454
+ />
455
+ <path
456
+ d="M406.393 98.721C407.695 97.606 409.664 97.8077 410.712 99.1633L429.141 123L287.318 244.087C285.872 245.322 284.033 246 282.132 246H234.53L234.55 245.983C235.353 246.062 236.187 245.818 236.839 245.236L263.577 221.345L263.461 221.208L406.393 98.721Z"
457
+ fill={colorPrimary}
458
+ />
459
+ <path
460
+ d="M236.837 245.235C235.575 246.365 233.631 246.223 232.546 244.922L194.494 198.854L175.588 175.129C175.019 174.415 174.194 174.032 173.353 174.002L173.351 174H219.852C222.199 174 224.427 175.035 225.944 176.829L263.56 221.317L236.837 245.235Z"
461
+ fill={colorPrimaryDark}
462
+ />
463
+ <path
464
+ d="M175.593 175.135C174.533 173.805 172.581 173.622 171.291 174.73L4.09013 318.484C2.68329 319.693 3.53868 322 5.394 322H47.5627C49.4695 322 51.3136 321.319 52.7627 320.08L194.494 198.854L175.593 175.135Z"
465
+ fill={colorPrimary}
466
+ />
467
+ </Group>
468
+ );
469
+ };
470
+
471
+ export const ListZigzagDown: ComponentType<ListZigzagDownProps> =
472
+ createListZigzag({
473
+ arrowHeight: ARROW_HEIGHT_DOWN,
474
+ presetRatios: PRESET_RATIOS_DOWN,
475
+ Arrow: ArrowDown,
476
+ });
477
+
478
+ export const ListZigzagUp: ComponentType<ListZigzagUpProps> = createListZigzag({
479
+ arrowHeight: ARROW_HEIGHT_UP,
480
+ presetRatios: PRESET_RATIOS_UP,
481
+ Arrow: ArrowUp,
482
+ });
483
+
484
+ registerStructure('list-zigzag-down', {
485
+ component: ListZigzagDown,
486
+ composites: ['title', 'item'],
487
+ });
488
+
489
+ registerStructure('list-zigzag-up', {
490
+ component: ListZigzagUp,
491
+ composites: ['title', 'item'],
492
+ });
package/src/index.ts CHANGED
@@ -38,7 +38,9 @@ export {
38
38
  getFont,
39
39
  getFonts,
40
40
  getPalette,
41
+ getPalettes,
41
42
  getPaletteColor,
43
+
42
44
  registerFont,
43
45
  registerPalette,
44
46
  registerPattern,
@@ -1,28 +1,17 @@
1
1
  import { ParsedInfographicOptions } from '../../options';
2
2
  import { loadResource, ResourceConfig } from '../../resource';
3
3
  import type { DynamicAttributes } from '../../themes';
4
- import type { IconAttributes, IconElement } from '../../types';
4
+ import type { IconAttributes, ItemDatum } from '../../types';
5
5
  import { createIconElement, getAttributes } from '../../utils';
6
6
  import { parseDynamicAttributes } from '../utils';
7
7
 
8
- export function renderIcon(
9
- svg: SVGSVGElement,
10
- node: SVGElement,
11
- value: string | ResourceConfig | undefined,
12
- attrs: DynamicAttributes<IconAttributes> = {},
13
- ): IconElement | null {
14
- if (!value) return null;
15
- const parsedAttrs = parseDynamicAttributes(node, attrs);
16
-
17
- return createIcon(svg, node, value, parsedAttrs);
18
- }
19
-
20
8
  export function renderItemIcon(
21
9
  svg: SVGSVGElement,
22
10
  node: SVGElement,
23
- value: string | ResourceConfig | undefined,
11
+ datum: ItemDatum,
24
12
  options: ParsedInfographicOptions,
25
13
  ) {
14
+ const value = datum.icon;
26
15
  if (!value) return null;
27
16
  const { themeConfig } = options;
28
17
  const attrs: DynamicAttributes<IconAttributes> = {
@@ -30,7 +19,7 @@ export function renderItemIcon(
30
19
  };
31
20
 
32
21
  const parsedAttrs = parseDynamicAttributes(node, attrs);
33
- return createIcon(svg, node, value, parsedAttrs);
22
+ return createIcon(svg, node, value, parsedAttrs, datum);
34
23
  }
35
24
 
36
25
  function createIcon(
@@ -38,9 +27,10 @@ function createIcon(
38
27
  node: SVGElement,
39
28
  value: string | ResourceConfig,
40
29
  attrs: IconAttributes,
30
+ datum?: ItemDatum,
41
31
  ) {
42
32
  // load async
43
- loadResource(svg, 'icon', value);
33
+ loadResource(svg, 'icon', value, datum);
44
34
 
45
35
  return createIconElement(value, {
46
36
  ...getAttributes(node, [
@@ -5,7 +5,7 @@ import {
5
5
  parseResourceConfig,
6
6
  type ResourceConfig,
7
7
  } from '../../resource';
8
- import type { IllusAttributes, IllusElement } from '../../types';
8
+ import type { IllusAttributes, IllusElement, ItemDatum } from '../../types';
9
9
  import {
10
10
  createElement,
11
11
  getAttributes,
@@ -19,6 +19,7 @@ export function renderIllus(
19
19
  svg: SVGSVGElement,
20
20
  node: SVGElement,
21
21
  value: string | ResourceConfig | undefined,
22
+ datum?: ItemDatum,
22
23
  ): IllusElement | null {
23
24
  if (!value) return null;
24
25
  const config = parseResourceConfig(value);
@@ -27,7 +28,7 @@ export function renderIllus(
27
28
  const id = getResourceId(config)!;
28
29
  const clipPathId = createClipPath(svg, node, id);
29
30
 
30
- loadResource(svg, 'illus', config);
31
+ loadResource(svg, 'illus', config, datum);
31
32
 
32
33
  const { data, color } = config;
33
34
  return createIllusElement(
@@ -41,6 +42,15 @@ export function renderIllus(
41
42
  );
42
43
  }
43
44
 
45
+ export function renderItemIllus(
46
+ svg: SVGSVGElement,
47
+ node: SVGElement,
48
+ datum: ItemDatum,
49
+ ) {
50
+ const value = datum.illus;
51
+ return renderIllus(svg, node, value, datum);
52
+ }
53
+
44
54
  function createClipPath(
45
55
  svg: SVGSVGElement,
46
56
  node: SVGElement,
@@ -1,8 +1,8 @@
1
1
  export { renderBackground } from './background';
2
2
  export { renderBaseElement } from './base';
3
3
  export { renderButtonsGroup } from './button';
4
- export { renderIcon, renderItemIcon } from './icon';
5
- export { renderIllus } from './illus';
4
+ export { renderItemIcon } from './icon';
5
+ export { renderIllus, renderItemIllus } from './illus';
6
6
  export { renderShape, renderStaticShape } from './shape';
7
7
  export { renderSVG } from './svg';
8
8
  export { renderItemText, renderStaticText, renderText } from './text';
@@ -10,6 +10,6 @@ export function getPalette(type: string): Palette | undefined {
10
10
  return PALETTE_REGISTRY.get(type);
11
11
  }
12
12
 
13
- export function getPalettes(): Palette[] {
14
- return Array.from(PALETTE_REGISTRY.values());
13
+ export function getPalettes(): Record<string, Palette> {
14
+ return Object.fromEntries(PALETTE_REGISTRY);
15
15
  }
@@ -25,6 +25,7 @@ import {
25
25
  renderButtonsGroup,
26
26
  renderIllus,
27
27
  renderItemIcon,
28
+ renderItemIllus,
28
29
  renderItemText,
29
30
  renderShape,
30
31
  renderStaticShape,
@@ -146,6 +147,7 @@ function fill(svg: SVGSVGElement, options: ParsedInfographicOptions) {
146
147
  if (element.dataset.elementType?.startsWith('item-')) {
147
148
  const indexes = getItemIndexes(element.dataset.indexes || '0');
148
149
  const itemType = element.dataset.elementType.replace('item-', '');
150
+ const datum = getDatumByIndexes(data, indexes);
149
151
 
150
152
  if (isItemLabel(element) || isItemDesc(element) || isItemValue(element)) {
151
153
  const modified = renderItemText(
@@ -155,22 +157,14 @@ function fill(svg: SVGSVGElement, options: ParsedInfographicOptions) {
155
157
  );
156
158
  return upsert(element, modified);
157
159
  }
160
+ if (!datum) return;
158
161
  if (isItemIllus(element)) {
159
- const modified = renderIllus(
160
- svg,
161
- element,
162
- getDatumByIndexes(data, indexes)?.illus,
163
- );
162
+ const modified = renderItemIllus(svg, element, datum);
164
163
  return upsert(element, modified);
165
164
  }
166
165
 
167
166
  if (isItemIcon(element)) {
168
- const modified = renderItemIcon(
169
- svg,
170
- element,
171
- getDatumByIndexes(data, indexes)?.icon,
172
- options,
173
- );
167
+ const modified = renderItemIcon(svg, element, datum, options);
174
168
  return upsert(element, modified);
175
169
  }
176
170
  }