@easyv/charts 1.8.15 → 1.8.17

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