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