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