@easyv/charts 1.3.0 → 1.3.3

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 (71) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/lib/components/Axis.js +10 -10
  5. package/lib/components/Background.js +2 -2
  6. package/lib/components/Carousel.js +2 -2
  7. package/lib/components/Chart.js +1 -1
  8. package/lib/components/ConicalGradient.js +21 -21
  9. package/lib/components/Indicator.js +2 -2
  10. package/lib/components/Lighter.js +179 -179
  11. package/lib/components/LinearGradient.js +2 -2
  12. package/lib/components/Marquee.js +3 -3
  13. package/lib/components/TextOverflow.js +3 -3
  14. package/lib/css/index.module.css +41 -41
  15. package/lib/css/piechart.module.css +26 -26
  16. package/lib/element/ConicGradient.js +72 -72
  17. package/lib/hooks/useAnimateData.js +5 -5
  18. package/lib/hooks/useAxes.js +5 -5
  19. package/lib/hooks/useCarouselAxisX.js +5 -5
  20. package/lib/hooks/useExtentData.js +6 -6
  21. package/lib/hooks/useFilterData.js +5 -5
  22. package/lib/hooks/useStackData.js +5 -5
  23. package/lib/hooks/useTooltip.js +10 -10
  24. package/lib/utils/index.js +6 -0
  25. package/package.json +54 -54
  26. package/src/components/AnimateData.tsx +24 -24
  27. package/src/components/Axis.tsx +354 -354
  28. package/src/components/Background.tsx +62 -62
  29. package/src/components/Band.tsx +169 -169
  30. package/src/components/BaseLine.js +82 -82
  31. package/src/components/Brush.js +159 -159
  32. package/src/components/Carousel.tsx +144 -144
  33. package/src/components/Chart.js +99 -99
  34. package/src/components/ChartContainer.tsx +63 -63
  35. package/src/components/ConicalGradient.js +258 -258
  36. package/src/components/ExtentData.js +17 -17
  37. package/src/components/FilterData.js +23 -23
  38. package/src/components/Indicator.js +13 -13
  39. package/src/components/Label.js +225 -225
  40. package/src/components/Legend.js +158 -158
  41. package/src/components/Lighter.jsx +173 -173
  42. package/src/components/Line.js +145 -145
  43. package/src/components/LinearGradient.js +29 -29
  44. package/src/components/Mapping.js +71 -71
  45. package/src/components/Marquee.js +88 -88
  46. package/src/components/PieChart.js +1278 -1278
  47. package/src/components/StackData.js +16 -16
  48. package/src/components/StereoBar.tsx +307 -307
  49. package/src/components/TextOverflow.js +51 -51
  50. package/src/components/Tooltip.js +169 -169
  51. package/src/components/index.js +55 -55
  52. package/src/context/index.js +2 -2
  53. package/src/css/index.module.css +41 -41
  54. package/src/css/piechart.module.css +26 -26
  55. package/src/element/ConicGradient.jsx +55 -55
  56. package/src/element/Line.tsx +33 -33
  57. package/src/element/index.ts +3 -3
  58. package/src/formatter/index.js +1 -1
  59. package/src/formatter/legend.js +90 -90
  60. package/src/hooks/index.js +17 -17
  61. package/src/hooks/useAnimateData.ts +67 -67
  62. package/src/hooks/useAxes.js +144 -144
  63. package/src/hooks/useCarouselAxisX.js +163 -163
  64. package/src/hooks/useExtentData.js +89 -89
  65. package/src/hooks/useFilterData.js +72 -72
  66. package/src/hooks/useStackData.js +101 -101
  67. package/src/hooks/useTooltip.ts +96 -96
  68. package/src/index.js +6 -6
  69. package/src/types/index.d.ts +67 -67
  70. package/src/utils/index.js +738 -731
  71. package/tsconfig.json +23 -23
@@ -1,731 +1,738 @@
1
- import { getColor } from '@easyv/utils';
2
- import { toFixed } from '@easyv/utils/lib/common/utils';
3
- import {
4
- scaleOrdinal as ordinal,
5
- range as sequence,
6
- ascending,
7
- descending,
8
- sum,
9
- } from 'd3v7';
10
- import { renderToStaticMarkup } from 'react-dom/server';
11
- import { toPath } from 'svg-points';
12
-
13
- const defaultSize = 10;
14
- const defaultBackground = '#000000';
15
- const defaultIcon = {
16
- width: defaultSize,
17
- height: defaultSize,
18
- background: defaultBackground,
19
- };
20
- const defaultLineIcon = {
21
- width: defaultSize,
22
- height: 2,
23
- background: defaultBackground,
24
- };
25
- const SvgBackground = ({
26
- fill: {
27
- type,
28
- pure,
29
- linear: { angle, opacity, stops },
30
- },
31
- pattern: {
32
- path = '',
33
- width = '100%',
34
- height = '100%',
35
- boderColor: stroke = 'transparent',
36
- boderWidth = 0,
37
- },
38
- }) => {
39
- return (
40
- <svg
41
- preserveAspectRatio='none'
42
- xmlns='http://www.w3.org/2000/svg'
43
- width={width}
44
- height={height}
45
- >
46
- <defs>
47
- <linearGradient
48
- id='linearGradient'
49
- x1='0%'
50
- y1='0%'
51
- x2='0%'
52
- y2='100%'
53
- gradientTransform={'rotate(' + (angle + 180) + ', 0.5, 0.5)'}
54
- >
55
- {stops.map(({ offset, color }, index) => (
56
- <stop
57
- key={index}
58
- offset={offset + '%'}
59
- stopColor={color}
60
- stopOpacity={opacity}
61
- />
62
- ))}
63
- </linearGradient>
64
- </defs>
65
- <path
66
- d={path}
67
- fill={type === 'pure' ? pure : 'url(#linearGradient)'}
68
- stroke={stroke}
69
- strokeWidth={boderWidth}
70
- />
71
- </svg>
72
- );
73
- };
74
- const getColorList = ({ type, pure, linear: { stops, angle, opacity } }) => {
75
- if (type == 'pure') {
76
- return [
77
- { color: pure, offset: 1 },
78
- { color: pure, offset: 0 },
79
- ];
80
- }
81
- return stops.map(({ color, offset }) => ({ color, offset: offset / 100 }));
82
- };
83
- const getIcon = (type, icon) => {
84
- switch (type) {
85
- case 'area':
86
- case 'line':
87
- return icon
88
- ? {
89
- ...defaultLineIcon,
90
- ...icon,
91
- }
92
- : defaultLineIcon;
93
- default:
94
- return icon
95
- ? {
96
- ...defaultIcon,
97
- ...icon,
98
- }
99
- : defaultIcon;
100
- }
101
- };
102
-
103
- const dateFormat = (date, fmt) => {
104
- date = new Date(date);
105
- const o = {
106
- 'M+': date.getMonth() + 1, //月份
107
- 'D+': date.getDate(), //日
108
- 'H+': date.getHours(), //小时
109
- 'h+': date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, //小时
110
- 'm+': date.getMinutes(), //分
111
- 's+': date.getSeconds(), //秒
112
- S: date.getMilliseconds(), //毫秒
113
- X: '星期' + '日一二三四五六'.charAt(date.getDay()),
114
- W: new Array(
115
- 'Sunday',
116
- 'Monday',
117
- 'Tuesday',
118
- 'Wednesday',
119
- 'Thursday',
120
- 'Friday',
121
- 'Saturday'
122
- )[date.getDay()],
123
- w: new Array('Sun.', 'Mon.', ' Tues.', 'Wed.', ' Thur.', 'Fri.', 'Sat.')[
124
- date.getDay()
125
- ],
126
- };
127
- if (/(Y+)/.test(fmt))
128
- fmt = fmt.replace(
129
- RegExp.$1,
130
- (date.getFullYear() + '').substr(4 - RegExp.$1.length)
131
- );
132
- for (var k in o)
133
- if (new RegExp('(' + k + ')').test(fmt))
134
- fmt = fmt.replace(
135
- RegExp.$1,
136
- RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
137
- );
138
- return fmt;
139
- };
140
- const getBreakWord = (str, breakNumber) => {
141
- const re = new RegExp('([^]){1,' + breakNumber + '}', 'g');
142
- return str.match(re);
143
- };
144
-
145
- //x轴标签逻辑
146
-
147
- const getTicksOfAxis = (domain, ticksCount, showLast) => {
148
- let len = domain.length;
149
- if (ticksCount < 2 || ticksCount > len) return domain;
150
- let step = Math.floor((len - ticksCount) / (ticksCount - 1));
151
- const ticksArr = domain.filter(function (d, i) {
152
- return i % (step + 1) === 0;
153
- });
154
- let Tlen = ticksArr.length;
155
- let lastIndex = domain.findIndex((d) => d == ticksArr[Tlen - 1]);
156
- if (showLast) {
157
- len % ticksCount == 0 || len - 1 - lastIndex >= Math.round(len / Tlen / 2)
158
- ? null
159
- : ticksArr.pop();
160
- ticksArr.push(domain[len - 1]);
161
- }
162
- return ticksArr;
163
- };
164
-
165
- const getTickCoord = ({
166
- orientation,
167
- coordinate,
168
- tickSize = 6,
169
- x = 0,
170
- y = 0,
171
- }) => {
172
- let x1, x2, y1, y2;
173
- switch (orientation) {
174
- case 'top':
175
- x1 = x2 = coordinate;
176
- y2 = y;
177
- y1 = y2 - tickSize;
178
- break;
179
- case 'left':
180
- y1 = y2 = coordinate;
181
- x2 = x;
182
- x1 = x2 - tickSize;
183
- break;
184
- case 'right':
185
- y1 = y2 = coordinate;
186
- x2 = x;
187
- x1 = x2 + tickSize;
188
- break;
189
- default:
190
- x1 = x2 = coordinate;
191
- y2 = y;
192
- y1 = y2 + tickSize;
193
- break;
194
- }
195
- return { x1, x2, y1, y2 };
196
- };
197
- const getGridCoord = ({ orientation, coordinate, end }) => {
198
- let x1, x2, y1, y2;
199
- switch (orientation) {
200
- case 'top':
201
- x1 = x2 = coordinate;
202
- y1 = 0;
203
- y2 = end;
204
- break;
205
- case 'bottom':
206
- x1 = x2 = coordinate;
207
- y1 = 0;
208
- y2 = end * -1;
209
- break;
210
- case 'left':
211
- y1 = y2 = coordinate;
212
- x1 = 0;
213
- x2 = end;
214
- break;
215
- case 'right':
216
- y1 = y2 = coordinate;
217
- x1 = 0;
218
- x2 = end * -1;
219
- break;
220
- }
221
- return { x1, x2, y1, y2 };
222
- };
223
-
224
- const identity = (d) => d;
225
-
226
- //获取鼠标指针坐标
227
- const getMousePos = (evt, dom) => {
228
- var rect = dom.getBoundingClientRect();
229
- return {
230
- x: evt.clientX - rect.left,
231
- y: evt.clientY - rect.top,
232
- w: rect.width,
233
- h: rect.height,
234
- };
235
- };
236
-
237
- const getFontStyle = (
238
- { color, bold, italic, fontSize, fontFamily, letterSpacing },
239
- type
240
- ) => {
241
- if (type == 'svg') {
242
- return {
243
- fontSize,
244
- fontFamily,
245
- letterSpacing,
246
- fill: color,
247
- fontWeight: bold ? 'bold' : 'normal',
248
- fontStyle: italic ? 'italic' : 'normal',
249
- };
250
- }
251
- return {
252
- fontSize,
253
- fontFamily,
254
- letterSpacing,
255
- color,
256
- fontWeight: bold ? 'bold' : 'normal',
257
- fontStyle: italic ? 'italic' : 'normal',
258
- };
259
- };
260
-
261
- const getMargin = ({ marginTop, marginRight, marginBottom, marginLeft }) =>
262
- marginTop +
263
- 'px ' +
264
- marginRight +
265
- 'px ' +
266
- marginBottom +
267
- 'px ' +
268
- marginLeft +
269
- 'px';
270
- const getTranslate3d = ({ x = 0, y = 0, z = 0 }) =>
271
- 'translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)';
272
- const getTranslate2d = ({ x = 0, y = 0 }) => 'translate(' + x + ', ' + y + ')';
273
- function band() {
274
- var scale = ordinal().unknown(undefined),
275
- domain = scale.domain,
276
- ordinalRange = scale.range,
277
- r0 = 0,
278
- r1 = 1,
279
- step,
280
- bandwidth,
281
- round = false,
282
- paddingInner = 0,
283
- paddingOuter = 0,
284
- // seriesPaddingInner = 0,
285
- // seriesPaddingOuter = 0,
286
- // seriesLength = 0,
287
- align = 0.5;
288
-
289
- delete scale.unknown;
290
-
291
- function rescale() {
292
- var n = domain().length,
293
- reverse = r1 < r0,
294
- start = reverse ? r1 : r0,
295
- stop = reverse ? r0 : r1;
296
- step = (stop - start) / Math.max(1, n - paddingOuter * 2);
297
- if (round) step = Math.floor(step);
298
- start += (stop - start - step * n) * align;
299
- bandwidth = step;
300
- if (round) (start = Math.round(start)), (bandwidth = Math.round(bandwidth));
301
- var values = sequence(n).map(function (i) {
302
- return start + step * i + step / 2;
303
- });
304
- return ordinalRange(reverse ? values.reverse() : values);
305
- }
306
-
307
- scale.domain = function (_) {
308
- return arguments.length ? (domain(_), rescale()) : domain();
309
- };
310
-
311
- scale.range = function (_) {
312
- return arguments.length
313
- ? (([r0, r1] = _), (r0 = +r0), (r1 = +r1), rescale())
314
- : [r0, r1];
315
- };
316
-
317
- scale.rangeRound = function (_) {
318
- return ([r0, r1] = _), (r0 = +r0), (r1 = +r1), (round = true), rescale();
319
- };
320
-
321
- scale.bandwidth = function () {
322
- return bandwidth;
323
- };
324
-
325
- scale.step = function () {
326
- return step;
327
- };
328
-
329
- scale.seriesBandwidth = function () {
330
- return seriesBandwidth;
331
- };
332
-
333
- scale.seriesStep = function () {
334
- return seriesStep;
335
- };
336
-
337
- scale.round = function (_) {
338
- return arguments.length ? ((round = !!_), rescale()) : round;
339
- };
340
-
341
- scale.padding = function (_) {
342
- return arguments.length
343
- ? ((paddingInner = Math.min(1, (paddingOuter = +_))), rescale())
344
- : paddingInner;
345
- };
346
-
347
- scale.paddingInner = function (_) {
348
- return arguments.length
349
- ? ((paddingInner = Math.min(1, _)), rescale())
350
- : paddingInner;
351
- };
352
-
353
- scale.paddingOuter = function (_) {
354
- return arguments.length ? ((paddingOuter = +_), rescale()) : paddingOuter;
355
- };
356
-
357
- scale.align = function (_) {
358
- return arguments.length
359
- ? ((align = Math.max(0, Math.min(1, _))), rescale())
360
- : align;
361
- };
362
-
363
- scale.copy = function () {
364
- return band(domain(), [r0, r1])
365
- .round(round)
366
- .paddingInner(paddingInner)
367
- .paddingOuter(paddingOuter)
368
- .align(align);
369
- };
370
-
371
- return initRange.apply(rescale(), arguments);
372
- }
373
-
374
- function initRange(domain, range) {
375
- switch (arguments.length) {
376
- case 0:
377
- break;
378
- case 1:
379
- this.range(domain);
380
- break;
381
- default:
382
- this.range(range).domain(domain);
383
- break;
384
- }
385
- return this;
386
- }
387
-
388
- const getStacks = (series) => {
389
- const tmp = [];
390
- series.forEach(({ type, stack, yOrZ }, name) => {
391
- const current = tmp.find(
392
- ({ type: _type, stack: _stack, yOrZ: _yOrZ }) =>
393
- _type == type && stack && _stack == stack && yOrZ == _yOrZ
394
- );
395
- if (!current) {
396
- const common = {
397
- type,
398
- stack,
399
- positive: 0,
400
- negative: 0,
401
- yOrZ,
402
- s: [name],
403
- };
404
- if (type === 'band') {
405
- const index = tmp.filter((item) => item.type === 'band').length;
406
- tmp.push({
407
- ...common,
408
- index,
409
- });
410
- } else {
411
- tmp.push({
412
- ...common,
413
- index: 0,
414
- });
415
- }
416
- } else {
417
- current.s.push(name);
418
- }
419
- });
420
- return tmp;
421
- };
422
-
423
- const dataYOrZ = (data, { y: seriesY, z: seriesZ }) => {
424
- const tmp = {
425
- y: [],
426
- z: [],
427
- };
428
- for (let i = 0, j = data.length; i < j; i++) {
429
- const d = data[i];
430
- if (seriesY.get(d.s)) {
431
- tmp.y.push(d);
432
- continue;
433
- }
434
- if (seriesZ.get(d.s)) {
435
- tmp.z.push(d);
436
- }
437
- }
438
- return tmp;
439
- };
440
-
441
- const seriesYOrZ = (series) => {
442
- const y = new Map();
443
- const z = new Map();
444
- series.forEach((value, key) => {
445
- if (value.yOrZ === 'y') {
446
- y.set(key, value);
447
- } else {
448
- z.set(key, value);
449
- }
450
- });
451
- return { y, z };
452
- };
453
-
454
- const resetStacks = (stacks) => {
455
- stacks.forEach((stack) => {
456
- stack.positive = 0;
457
- stack.negative = 0;
458
- });
459
- };
460
-
461
- const getCurrentStack = (stack, stackMap) =>
462
- stackMap.find(
463
- ({ stack: _stack, type: _type, yOrZ: _yOrZ, s: _s }) =>
464
- _type == stack.type &&
465
- _stack == stack.stack &&
466
- _yOrZ == stack.yOrZ &&
467
- _s.includes(stack.name)
468
- );
469
-
470
- const getBandBackground = (pattern, fill) => {
471
- if (!(pattern && pattern.path)) return getColor(fill);
472
- const { backgroundSize = '100% 100%', ..._pattern } = pattern;
473
- return (
474
- 'center top / ' +
475
- backgroundSize +
476
- ' url("data:image/svg+xml,' +
477
- encodeURIComponent(
478
- renderToStaticMarkup(<SvgBackground fill={fill} pattern={_pattern} />)
479
- ) +
480
- '")'
481
- );
482
- };
483
- const getBandwidth = (step, paddingOuter) => step * (1 - paddingOuter);
484
-
485
- const getBandSeriesStepAndWidth = ({ width, paddingInner, bandLength }) => {
486
- const seriesStep = width / (bandLength == 0 ? 1 : bandLength);
487
- const seriesWidth = seriesStep * (1 - paddingInner);
488
- return {
489
- seriesStep,
490
- seriesWidth,
491
- };
492
- };
493
-
494
- const getSeriesInfo = ({
495
- step,
496
- bandLength = 1,
497
- paddingInner = 0,
498
- paddingOuter = 0,
499
- }) => {
500
- const _step =
501
- step / (bandLength + paddingOuter * 2 + paddingInner * (bandLength - 1));
502
- return {
503
- seriesWidth: _step,
504
- seriesStep: (1 + paddingInner) * _step,
505
- seriesStart: paddingOuter * _step,
506
- width: step - paddingOuter * 2 * _step,
507
- };
508
- };
509
-
510
- const isValidHttpUrl = (string) => {
511
- let url;
512
-
513
- try {
514
- url = new URL(string);
515
- } catch (_) {
516
- return false;
517
- }
518
-
519
- return url.protocol === 'http:' || url.protocol === 'https:';
520
- };
521
-
522
- const getChildren = (svgStr) => {
523
- const wrapper = document.createElement('div');
524
- wrapper.innerHTML = svgStr;
525
- const { childNodes } = wrapper;
526
- const svgDom = [...childNodes].find((item) => item.tagName === 'svg');
527
-
528
- if (!!svgDom) {
529
- return [...svgDom.childNodes];
530
- }
531
-
532
- return null;
533
- };
534
-
535
- const filterChildren = (children, tagNames) => {
536
- return children.reduce((prev, node) => {
537
- let { nodeName } = node;
538
-
539
- if (tagNames.indexOf(nodeName) > -1) {
540
- if (nodeName === 'g') {
541
- return filterChildren([...node.childNodes], tagNames);
542
- } else {
543
- prev.push(node);
544
- }
545
- }
546
-
547
- return prev;
548
- }, []);
549
- };
550
-
551
- const getDomPath = (node) => {
552
- switch (node.nodeName) {
553
- case 'circle':
554
- return toPath({
555
- type: 'circle',
556
- cx: +node.getAttribute('cx') || 0,
557
- cy: +node.getAttribute('cy') || 0,
558
- r: +node.getAttribute('r') || 0,
559
- });
560
-
561
- case 'ellipse':
562
- return toPath({
563
- type: 'ellipse',
564
- cx: +node.getAttribute('cx') || 0,
565
- cy: +node.getAttribute('cy') || 0,
566
- rx: +node.getAttribute('rx') || 0,
567
- ry: +node.getAttribute('ry') || 0,
568
- });
569
-
570
- case 'line':
571
- return toPath({
572
- type: 'line',
573
- x1: +node.getAttribute('x1') || 0,
574
- x2: +node.getAttribute('x2') || 0,
575
- y1: +node.getAttribute('y1') || 0,
576
- y2: +node.getAttribute('y2') || 0,
577
- });
578
-
579
- case 'path':
580
- return toPath({
581
- type: 'path',
582
- d: node.getAttribute('d') || '',
583
- });
584
-
585
- case 'polygon':
586
- return toPath({
587
- type: 'polyline',
588
- points: node.getAttribute('points') || '',
589
- });
590
-
591
- case 'polyline':
592
- return toPath({
593
- type: 'polyline',
594
- points: node.getAttribute('points') || '',
595
- });
596
-
597
- case 'rect':
598
- return toPath({
599
- type: 'rect',
600
- height: +node.getAttribute('height') || 0,
601
- width: +node.getAttribute('width') || 0,
602
- x: +node.getAttribute('x') || 0,
603
- y: +node.getAttribute('y') || 0,
604
- rx: +node.getAttribute('rx') || 0,
605
- ry: +node.getAttribute('ry') || 0,
606
- });
607
- }
608
- };
609
-
610
- const sortPie = (data, order) => {
611
- const _data = data.map((item) => ({ ...item }));
612
- switch (order) {
613
- case '':
614
- _data.sort(({ index: a }, { index: b }) => ascending(a, b));
615
- break;
616
- case 'desc':
617
- _data.sort(({ value: a }, { value: b }) => descending(a, b));
618
- break;
619
- case 'asc':
620
- _data.sort(({ value: a }, { value: b }) => ascending(a, b));
621
- break;
622
- }
623
- return _data;
624
- };
625
-
626
- // const getDataWithPercent = (data = [], precision = 0, type) => {
627
- // const digits = Math.pow(10, precision);
628
- // const targetSeats = digits * 100;
629
-
630
- // const total = sum(data, (d) => d.value);
631
-
632
- // const votesPerQuota = data.map((d, index) => ({
633
- // ...d,
634
- // vote: Math.round((d.value / total) * digits * 100),
635
- // index,
636
- // }));
637
- // const currentSum = sum(votesPerQuota, (d) => d.vote);
638
- // const remainder = targetSeats - currentSum;
639
- // console.log(type+":",votesPerQuota, toFixed);
640
- // votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
641
-
642
- // const tmp = votesPerQuota.map(({ vote, ...data }, index) => ({
643
- // ...data,
644
- // percent: toFixed((vote + (index < remainder ? 1 : 0)) / digits, precision),
645
- // }));
646
-
647
- // return tmp;
648
- // };
649
-
650
- const getDataWithPercent = (data = [], precision = 0) => {
651
- const digits = Math.pow(10, precision);
652
- const targetSeats = digits * 100;
653
-
654
- const total = sum(data, (d) => d.value) || 1;
655
-
656
- const votesPerQuota = data.map((d, index) => ({
657
- ...d,
658
- vote: Math.round((d.value / total) * digits * 100),
659
- index,
660
- }));
661
- const currentSum = sum(votesPerQuota, (d) => d.vote);
662
-
663
- let remainder = targetSeats - currentSum;
664
- votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
665
-
666
- const tmp = votesPerQuota.map(({ vote, value, ...data }, index) => {
667
- let obj = {
668
- ...data,
669
- value,
670
- percent: toFixed(
671
- (vote + (value && value != 0 ? remainder : 0)) / digits,
672
- precision
673
- ),
674
- };
675
- if (value && value != 0) {
676
- remainder = 0;
677
- }
678
- return obj;
679
- });
680
- return tmp;
681
- };
682
-
683
- const excludeTypes = ['array', 'object', 'group', 'modal', 'colors'];
684
- const reduceConfig = (config = []) => {
685
- if (!Array.isArray(config)) {
686
- return config;
687
- }
688
- let output = {};
689
- for (let i = 0, len = config.length; i < len; i++) {
690
- let type = config[i]._type;
691
-
692
- output[config[i]._name] =
693
- type && !excludeTypes.includes(type)
694
- ? config[i]._value
695
- : reduceConfig(config[i]._value);
696
- }
697
- return output;
698
- };
699
-
700
- export {
701
- dateFormat,
702
- getBreakWord,
703
- getTicksOfAxis,
704
- getTickCoord,
705
- getGridCoord,
706
- identity,
707
- getMousePos,
708
- getFontStyle,
709
- getMargin,
710
- getTranslate3d,
711
- getTranslate2d,
712
- band,
713
- getIcon,
714
- getColorList,
715
- getStacks,
716
- dataYOrZ,
717
- seriesYOrZ,
718
- resetStacks,
719
- getCurrentStack,
720
- getBandBackground,
721
- getBandwidth,
722
- getBandSeriesStepAndWidth,
723
- isValidHttpUrl,
724
- getChildren,
725
- filterChildren,
726
- getDomPath,
727
- sortPie,
728
- getDataWithPercent,
729
- reduceConfig,
730
- getSeriesInfo,
731
- };
1
+ import { getColor } from '@easyv/utils';
2
+ import { toFixed } from '@easyv/utils/lib/common/utils';
3
+ import {
4
+ scaleOrdinal as ordinal,
5
+ range as sequence,
6
+ ascending,
7
+ descending,
8
+ sum,
9
+ } from 'd3v7';
10
+ import { renderToStaticMarkup } from 'react-dom/server';
11
+ import { toPath } from 'svg-points';
12
+
13
+ const defaultSize = 10;
14
+ const defaultBackground = '#000000';
15
+ const defaultIcon = {
16
+ width: defaultSize,
17
+ height: defaultSize,
18
+ background: defaultBackground,
19
+ };
20
+ const defaultLineIcon = {
21
+ width: defaultSize,
22
+ height: 2,
23
+ background: defaultBackground,
24
+ };
25
+ const SvgBackground = ({
26
+ fill: {
27
+ type,
28
+ pure,
29
+ linear: { angle, opacity, stops },
30
+ },
31
+ pattern: {
32
+ path = '',
33
+ width = '100%',
34
+ height = '100%',
35
+ boderColor: stroke = 'transparent',
36
+ boderWidth = 0,
37
+ },
38
+ }) => {
39
+ return (
40
+ <svg
41
+ preserveAspectRatio='none'
42
+ xmlns='http://www.w3.org/2000/svg'
43
+ width={width}
44
+ height={height}
45
+ >
46
+ <defs>
47
+ <linearGradient
48
+ id='linearGradient'
49
+ x1='0%'
50
+ y1='0%'
51
+ x2='0%'
52
+ y2='100%'
53
+ gradientTransform={'rotate(' + (angle + 180) + ', 0.5, 0.5)'}
54
+ >
55
+ {stops.map(({ offset, color }, index) => (
56
+ <stop
57
+ key={index}
58
+ offset={offset + '%'}
59
+ stopColor={color}
60
+ stopOpacity={opacity}
61
+ />
62
+ ))}
63
+ </linearGradient>
64
+ </defs>
65
+ <path
66
+ d={path}
67
+ fill={type === 'pure' ? pure : 'url(#linearGradient)'}
68
+ stroke={stroke}
69
+ strokeWidth={boderWidth}
70
+ />
71
+ </svg>
72
+ );
73
+ };
74
+ const getColorList = ({ type, pure, linear: { stops, angle, opacity } }) => {
75
+ if (type == 'pure') {
76
+ return [
77
+ { color: pure, offset: 1 },
78
+ { color: pure, offset: 0 },
79
+ ];
80
+ }
81
+ return stops.map(({ color, offset }) => ({ color, offset: offset / 100 }));
82
+ };
83
+ const getIcon = (type, icon) => {
84
+ switch (type) {
85
+ case 'area':
86
+ case 'line':
87
+ return icon
88
+ ? {
89
+ ...defaultLineIcon,
90
+ ...icon,
91
+ }
92
+ : defaultLineIcon;
93
+ default:
94
+ return icon
95
+ ? {
96
+ ...defaultIcon,
97
+ ...icon,
98
+ }
99
+ : defaultIcon;
100
+ }
101
+ };
102
+
103
+ const dateFormat = (date, fmt) => {
104
+ date = new Date(date);
105
+ const o = {
106
+ 'M+': date.getMonth() + 1, //月份
107
+ 'D+': date.getDate(), //日
108
+ 'H+': date.getHours(), //小时
109
+ 'h+': date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, //小时
110
+ 'm+': date.getMinutes(), //分
111
+ 's+': date.getSeconds(), //秒
112
+ S: date.getMilliseconds(), //毫秒
113
+ X: '星期' + '日一二三四五六'.charAt(date.getDay()),
114
+ W: new Array(
115
+ 'Sunday',
116
+ 'Monday',
117
+ 'Tuesday',
118
+ 'Wednesday',
119
+ 'Thursday',
120
+ 'Friday',
121
+ 'Saturday'
122
+ )[date.getDay()],
123
+ w: new Array('Sun.', 'Mon.', ' Tues.', 'Wed.', ' Thur.', 'Fri.', 'Sat.')[
124
+ date.getDay()
125
+ ],
126
+ };
127
+ if (/(Y+)/.test(fmt))
128
+ fmt = fmt.replace(
129
+ RegExp.$1,
130
+ (date.getFullYear() + '').substr(4 - RegExp.$1.length)
131
+ );
132
+ for (var k in o)
133
+ if (new RegExp('(' + k + ')').test(fmt))
134
+ fmt = fmt.replace(
135
+ RegExp.$1,
136
+ RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
137
+ );
138
+ return fmt;
139
+ };
140
+ const getBreakWord = (str, breakNumber) => {
141
+ const re = new RegExp('([^]){1,' + breakNumber + '}', 'g');
142
+ return str.match(re);
143
+ };
144
+
145
+ //x轴标签逻辑
146
+
147
+ const getTicksOfAxis = (domain, ticksCount, showLast) => {
148
+ let len = domain.length;
149
+ if (ticksCount < 2 || ticksCount > len) return domain;
150
+ let step = Math.floor((len - ticksCount) / (ticksCount - 1));
151
+ const ticksArr = domain.filter(function (d, i) {
152
+ return i % (step + 1) === 0;
153
+ });
154
+ let Tlen = ticksArr.length;
155
+ let lastIndex = domain.findIndex((d) => d == ticksArr[Tlen - 1]);
156
+ if (showLast) {
157
+ len % ticksCount == 0 || len - 1 - lastIndex >= Math.round(len / Tlen / 2)
158
+ ? null
159
+ : ticksArr.pop();
160
+ ticksArr.push(domain[len - 1]);
161
+ }
162
+ return ticksArr;
163
+ };
164
+
165
+ const getTickCoord = ({
166
+ orientation,
167
+ coordinate,
168
+ tickSize = 6,
169
+ x = 0,
170
+ y = 0,
171
+ }) => {
172
+ let x1, x2, y1, y2;
173
+ switch (orientation) {
174
+ case 'top':
175
+ x1 = x2 = coordinate;
176
+ y2 = y;
177
+ y1 = y2 - tickSize;
178
+ break;
179
+ case 'left':
180
+ y1 = y2 = coordinate;
181
+ x2 = x;
182
+ x1 = x2 - tickSize;
183
+ break;
184
+ case 'right':
185
+ y1 = y2 = coordinate;
186
+ x2 = x;
187
+ x1 = x2 + tickSize;
188
+ break;
189
+ default:
190
+ x1 = x2 = coordinate;
191
+ y2 = y;
192
+ y1 = y2 + tickSize;
193
+ break;
194
+ }
195
+ return { x1, x2, y1, y2 };
196
+ };
197
+ const getGridCoord = ({ orientation, coordinate, end }) => {
198
+ let x1, x2, y1, y2;
199
+ switch (orientation) {
200
+ case 'top':
201
+ x1 = x2 = coordinate;
202
+ y1 = 0;
203
+ y2 = end;
204
+ break;
205
+ case 'bottom':
206
+ x1 = x2 = coordinate;
207
+ y1 = 0;
208
+ y2 = end * -1;
209
+ break;
210
+ case 'left':
211
+ y1 = y2 = coordinate;
212
+ x1 = 0;
213
+ x2 = end;
214
+ break;
215
+ case 'right':
216
+ y1 = y2 = coordinate;
217
+ x1 = 0;
218
+ x2 = end * -1;
219
+ break;
220
+ }
221
+ return { x1, x2, y1, y2 };
222
+ };
223
+
224
+ const identity = (d) => d;
225
+
226
+ //获取鼠标指针坐标
227
+ const getMousePos = (evt, dom) => {
228
+ var rect = dom.getBoundingClientRect();
229
+ return {
230
+ x: evt.clientX - rect.left,
231
+ y: evt.clientY - rect.top,
232
+ w: rect.width,
233
+ h: rect.height,
234
+ };
235
+ };
236
+
237
+ const getFontStyle = (
238
+ { color, bold, italic, fontSize, fontFamily, letterSpacing },
239
+ type
240
+ ) => {
241
+ if (type == 'svg') {
242
+ return {
243
+ fontSize,
244
+ fontFamily,
245
+ letterSpacing,
246
+ fill: color,
247
+ fontWeight: bold ? 'bold' : 'normal',
248
+ fontStyle: italic ? 'italic' : 'normal',
249
+ };
250
+ }
251
+ return {
252
+ fontSize,
253
+ fontFamily,
254
+ letterSpacing,
255
+ color,
256
+ fontWeight: bold ? 'bold' : 'normal',
257
+ fontStyle: italic ? 'italic' : 'normal',
258
+ };
259
+ };
260
+
261
+ const getMargin = ({ marginTop, marginRight, marginBottom, marginLeft }) =>
262
+ marginTop +
263
+ 'px ' +
264
+ marginRight +
265
+ 'px ' +
266
+ marginBottom +
267
+ 'px ' +
268
+ marginLeft +
269
+ 'px';
270
+ const getTranslate3d = ({ x = 0, y = 0, z = 0 }) =>
271
+ 'translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)';
272
+ const getTranslate2d = ({ x = 0, y = 0 }) => 'translate(' + x + ', ' + y + ')';
273
+ function band() {
274
+ var scale = ordinal().unknown(undefined),
275
+ domain = scale.domain,
276
+ ordinalRange = scale.range,
277
+ r0 = 0,
278
+ r1 = 1,
279
+ step,
280
+ bandwidth,
281
+ round = false,
282
+ paddingInner = 0,
283
+ paddingOuter = 0,
284
+ // seriesPaddingInner = 0,
285
+ // seriesPaddingOuter = 0,
286
+ // seriesLength = 0,
287
+ align = 0.5;
288
+
289
+ delete scale.unknown;
290
+
291
+ function rescale() {
292
+ var n = domain().length,
293
+ reverse = r1 < r0,
294
+ start = reverse ? r1 : r0,
295
+ stop = reverse ? r0 : r1;
296
+ step = (stop - start) / Math.max(1, n - paddingOuter * 2);
297
+ if (round) step = Math.floor(step);
298
+ start += (stop - start - step * n) * align;
299
+ bandwidth = step;
300
+ if (round) (start = Math.round(start)), (bandwidth = Math.round(bandwidth));
301
+ var values = sequence(n).map(function (i) {
302
+ return start + step * i + step / 2;
303
+ });
304
+ return ordinalRange(reverse ? values.reverse() : values);
305
+ }
306
+
307
+ scale.domain = function (_) {
308
+ return arguments.length ? (domain(_), rescale()) : domain();
309
+ };
310
+
311
+ scale.range = function (_) {
312
+ return arguments.length
313
+ ? (([r0, r1] = _), (r0 = +r0), (r1 = +r1), rescale())
314
+ : [r0, r1];
315
+ };
316
+
317
+ scale.rangeRound = function (_) {
318
+ return ([r0, r1] = _), (r0 = +r0), (r1 = +r1), (round = true), rescale();
319
+ };
320
+
321
+ scale.bandwidth = function () {
322
+ return bandwidth;
323
+ };
324
+
325
+ scale.step = function () {
326
+ return step;
327
+ };
328
+
329
+ scale.seriesBandwidth = function () {
330
+ return seriesBandwidth;
331
+ };
332
+
333
+ scale.seriesStep = function () {
334
+ return seriesStep;
335
+ };
336
+
337
+ scale.round = function (_) {
338
+ return arguments.length ? ((round = !!_), rescale()) : round;
339
+ };
340
+
341
+ scale.padding = function (_) {
342
+ return arguments.length
343
+ ? ((paddingInner = Math.min(1, (paddingOuter = +_))), rescale())
344
+ : paddingInner;
345
+ };
346
+
347
+ scale.paddingInner = function (_) {
348
+ return arguments.length
349
+ ? ((paddingInner = Math.min(1, _)), rescale())
350
+ : paddingInner;
351
+ };
352
+
353
+ scale.paddingOuter = function (_) {
354
+ return arguments.length ? ((paddingOuter = +_), rescale()) : paddingOuter;
355
+ };
356
+
357
+ scale.align = function (_) {
358
+ return arguments.length
359
+ ? ((align = Math.max(0, Math.min(1, _))), rescale())
360
+ : align;
361
+ };
362
+
363
+ scale.copy = function () {
364
+ return band(domain(), [r0, r1])
365
+ .round(round)
366
+ .paddingInner(paddingInner)
367
+ .paddingOuter(paddingOuter)
368
+ .align(align);
369
+ };
370
+
371
+ return initRange.apply(rescale(), arguments);
372
+ }
373
+
374
+ function initRange(domain, range) {
375
+ switch (arguments.length) {
376
+ case 0:
377
+ break;
378
+ case 1:
379
+ this.range(domain);
380
+ break;
381
+ default:
382
+ this.range(range).domain(domain);
383
+ break;
384
+ }
385
+ return this;
386
+ }
387
+
388
+ const getStacks = (series) => {
389
+ const tmp = [];
390
+ series.forEach(({ type, stack, yOrZ }, name) => {
391
+ const current = tmp.find(
392
+ ({ type: _type, stack: _stack, yOrZ: _yOrZ }) =>
393
+ _type == type && stack && _stack == stack && yOrZ == _yOrZ
394
+ );
395
+ if (!current) {
396
+ const common = {
397
+ type,
398
+ stack,
399
+ positive: 0,
400
+ negative: 0,
401
+ yOrZ,
402
+ s: [name],
403
+ };
404
+ if (type === 'band') {
405
+ const index = tmp.filter((item) => item.type === 'band').length;
406
+ tmp.push({
407
+ ...common,
408
+ index,
409
+ });
410
+ } else {
411
+ tmp.push({
412
+ ...common,
413
+ index: 0,
414
+ });
415
+ }
416
+ } else {
417
+ current.s.push(name);
418
+ }
419
+ });
420
+ return tmp;
421
+ };
422
+
423
+ const dataYOrZ = (data, { y: seriesY, z: seriesZ }) => {
424
+ const tmp = {
425
+ y: [],
426
+ z: [],
427
+ };
428
+ for (let i = 0, j = data.length; i < j; i++) {
429
+ const d = data[i];
430
+ if (seriesY.get(d.s)) {
431
+ tmp.y.push(d);
432
+ continue;
433
+ }
434
+ if (seriesZ.get(d.s)) {
435
+ tmp.z.push(d);
436
+ }
437
+ }
438
+ return tmp;
439
+ };
440
+
441
+ const seriesYOrZ = (series) => {
442
+ const y = new Map();
443
+ const z = new Map();
444
+ series.forEach((value, key) => {
445
+ if (value.yOrZ === 'y') {
446
+ y.set(key, value);
447
+ } else {
448
+ z.set(key, value);
449
+ }
450
+ });
451
+ return { y, z };
452
+ };
453
+
454
+ const resetStacks = (stacks) => {
455
+ stacks.forEach((stack) => {
456
+ stack.positive = 0;
457
+ stack.negative = 0;
458
+ });
459
+ };
460
+
461
+ const getCurrentStack = (stack, stackMap) =>
462
+ stackMap.find(
463
+ ({ stack: _stack, type: _type, yOrZ: _yOrZ, s: _s }) =>
464
+ _type == stack.type &&
465
+ _stack == stack.stack &&
466
+ _yOrZ == stack.yOrZ &&
467
+ _s.includes(stack.name)
468
+ );
469
+
470
+ const getBandBackground = (pattern, fill) => {
471
+ if (!(pattern && pattern.path)) return getColor(fill);
472
+ const { backgroundSize = '100% 100%', ..._pattern } = pattern;
473
+ return (
474
+ 'center top / ' +
475
+ backgroundSize +
476
+ ' url("data:image/svg+xml,' +
477
+ encodeURIComponent(
478
+ renderToStaticMarkup(<SvgBackground fill={fill} pattern={_pattern} />)
479
+ ) +
480
+ '")'
481
+ );
482
+ };
483
+ const getBandwidth = (step, paddingOuter) => step * (1 - paddingOuter);
484
+
485
+ const getBandSeriesStepAndWidth = ({ width, paddingInner, bandLength }) => {
486
+ const seriesStep = width / (bandLength == 0 ? 1 : bandLength);
487
+ const seriesWidth = seriesStep * (1 - paddingInner);
488
+ return {
489
+ seriesStep,
490
+ seriesWidth,
491
+ };
492
+ };
493
+
494
+ const getSeriesInfo = ({
495
+ step,
496
+ bandLength = 1,
497
+ paddingInner = 0,
498
+ paddingOuter = 0,
499
+ }) => {
500
+ if (bandLength == 0)
501
+ return {
502
+ seriesWidth: step,
503
+ seriesStep: step,
504
+ seriesStart: 0,
505
+ width: step,
506
+ };
507
+ const _step =
508
+ step / (bandLength + paddingOuter * 2 + paddingInner * (bandLength - 1));
509
+ return {
510
+ seriesWidth: _step,
511
+ seriesStep: (1 + paddingInner) * _step,
512
+ seriesStart: paddingOuter * _step,
513
+ width: step - paddingOuter * 2 * _step,
514
+ };
515
+ };
516
+
517
+ const isValidHttpUrl = (string) => {
518
+ let url;
519
+
520
+ try {
521
+ url = new URL(string);
522
+ } catch (_) {
523
+ return false;
524
+ }
525
+
526
+ return url.protocol === 'http:' || url.protocol === 'https:';
527
+ };
528
+
529
+ const getChildren = (svgStr) => {
530
+ const wrapper = document.createElement('div');
531
+ wrapper.innerHTML = svgStr;
532
+ const { childNodes } = wrapper;
533
+ const svgDom = [...childNodes].find((item) => item.tagName === 'svg');
534
+
535
+ if (!!svgDom) {
536
+ return [...svgDom.childNodes];
537
+ }
538
+
539
+ return null;
540
+ };
541
+
542
+ const filterChildren = (children, tagNames) => {
543
+ return children.reduce((prev, node) => {
544
+ let { nodeName } = node;
545
+
546
+ if (tagNames.indexOf(nodeName) > -1) {
547
+ if (nodeName === 'g') {
548
+ return filterChildren([...node.childNodes], tagNames);
549
+ } else {
550
+ prev.push(node);
551
+ }
552
+ }
553
+
554
+ return prev;
555
+ }, []);
556
+ };
557
+
558
+ const getDomPath = (node) => {
559
+ switch (node.nodeName) {
560
+ case 'circle':
561
+ return toPath({
562
+ type: 'circle',
563
+ cx: +node.getAttribute('cx') || 0,
564
+ cy: +node.getAttribute('cy') || 0,
565
+ r: +node.getAttribute('r') || 0,
566
+ });
567
+
568
+ case 'ellipse':
569
+ return toPath({
570
+ type: 'ellipse',
571
+ cx: +node.getAttribute('cx') || 0,
572
+ cy: +node.getAttribute('cy') || 0,
573
+ rx: +node.getAttribute('rx') || 0,
574
+ ry: +node.getAttribute('ry') || 0,
575
+ });
576
+
577
+ case 'line':
578
+ return toPath({
579
+ type: 'line',
580
+ x1: +node.getAttribute('x1') || 0,
581
+ x2: +node.getAttribute('x2') || 0,
582
+ y1: +node.getAttribute('y1') || 0,
583
+ y2: +node.getAttribute('y2') || 0,
584
+ });
585
+
586
+ case 'path':
587
+ return toPath({
588
+ type: 'path',
589
+ d: node.getAttribute('d') || '',
590
+ });
591
+
592
+ case 'polygon':
593
+ return toPath({
594
+ type: 'polyline',
595
+ points: node.getAttribute('points') || '',
596
+ });
597
+
598
+ case 'polyline':
599
+ return toPath({
600
+ type: 'polyline',
601
+ points: node.getAttribute('points') || '',
602
+ });
603
+
604
+ case 'rect':
605
+ return toPath({
606
+ type: 'rect',
607
+ height: +node.getAttribute('height') || 0,
608
+ width: +node.getAttribute('width') || 0,
609
+ x: +node.getAttribute('x') || 0,
610
+ y: +node.getAttribute('y') || 0,
611
+ rx: +node.getAttribute('rx') || 0,
612
+ ry: +node.getAttribute('ry') || 0,
613
+ });
614
+ }
615
+ };
616
+
617
+ const sortPie = (data, order) => {
618
+ const _data = data.map((item) => ({ ...item }));
619
+ switch (order) {
620
+ case '':
621
+ _data.sort(({ index: a }, { index: b }) => ascending(a, b));
622
+ break;
623
+ case 'desc':
624
+ _data.sort(({ value: a }, { value: b }) => descending(a, b));
625
+ break;
626
+ case 'asc':
627
+ _data.sort(({ value: a }, { value: b }) => ascending(a, b));
628
+ break;
629
+ }
630
+ return _data;
631
+ };
632
+
633
+ // const getDataWithPercent = (data = [], precision = 0, type) => {
634
+ // const digits = Math.pow(10, precision);
635
+ // const targetSeats = digits * 100;
636
+
637
+ // const total = sum(data, (d) => d.value);
638
+
639
+ // const votesPerQuota = data.map((d, index) => ({
640
+ // ...d,
641
+ // vote: Math.round((d.value / total) * digits * 100),
642
+ // index,
643
+ // }));
644
+ // const currentSum = sum(votesPerQuota, (d) => d.vote);
645
+ // const remainder = targetSeats - currentSum;
646
+ // console.log(type+":",votesPerQuota, toFixed);
647
+ // votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
648
+
649
+ // const tmp = votesPerQuota.map(({ vote, ...data }, index) => ({
650
+ // ...data,
651
+ // percent: toFixed((vote + (index < remainder ? 1 : 0)) / digits, precision),
652
+ // }));
653
+
654
+ // return tmp;
655
+ // };
656
+
657
+ const getDataWithPercent = (data = [], precision = 0) => {
658
+ const digits = Math.pow(10, precision);
659
+ const targetSeats = digits * 100;
660
+
661
+ const total = sum(data, (d) => d.value) || 1;
662
+
663
+ const votesPerQuota = data.map((d, index) => ({
664
+ ...d,
665
+ vote: Math.round((d.value / total) * digits * 100),
666
+ index,
667
+ }));
668
+ const currentSum = sum(votesPerQuota, (d) => d.vote);
669
+
670
+ let remainder = targetSeats - currentSum;
671
+ votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
672
+
673
+ const tmp = votesPerQuota.map(({ vote, value, ...data }, index) => {
674
+ let obj = {
675
+ ...data,
676
+ value,
677
+ percent: toFixed(
678
+ (vote + (value && value != 0 ? remainder : 0)) / digits,
679
+ precision
680
+ ),
681
+ };
682
+ if (value && value != 0) {
683
+ remainder = 0;
684
+ }
685
+ return obj;
686
+ });
687
+ return tmp;
688
+ };
689
+
690
+ const excludeTypes = ['array', 'object', 'group', 'modal', 'colors'];
691
+ const reduceConfig = (config = []) => {
692
+ if (!Array.isArray(config)) {
693
+ return config;
694
+ }
695
+ let output = {};
696
+ for (let i = 0, len = config.length; i < len; i++) {
697
+ let type = config[i]._type;
698
+
699
+ output[config[i]._name] =
700
+ type && !excludeTypes.includes(type)
701
+ ? config[i]._value
702
+ : reduceConfig(config[i]._value);
703
+ }
704
+ return output;
705
+ };
706
+
707
+ export {
708
+ dateFormat,
709
+ getBreakWord,
710
+ getTicksOfAxis,
711
+ getTickCoord,
712
+ getGridCoord,
713
+ identity,
714
+ getMousePos,
715
+ getFontStyle,
716
+ getMargin,
717
+ getTranslate3d,
718
+ getTranslate2d,
719
+ band,
720
+ getIcon,
721
+ getColorList,
722
+ getStacks,
723
+ dataYOrZ,
724
+ seriesYOrZ,
725
+ resetStacks,
726
+ getCurrentStack,
727
+ getBandBackground,
728
+ getBandwidth,
729
+ getBandSeriesStepAndWidth,
730
+ isValidHttpUrl,
731
+ getChildren,
732
+ filterChildren,
733
+ getDomPath,
734
+ sortPie,
735
+ getDataWithPercent,
736
+ reduceConfig,
737
+ getSeriesInfo,
738
+ };