@easyv/charts 1.6.8 → 1.6.10

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