@easyv/charts 1.9.3 → 1.9.5
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/lib/components/Chart.js +1 -0
- package/lib/formatter/legend.js +1 -0
- package/lib/utils/index.js +184 -132
- package/package.json +1 -1
- package/src/components/Chart.js +2 -0
- package/src/formatter/legend.js +2 -2
- package/src/utils/index.js +146 -96
package/lib/components/Chart.js
CHANGED
|
@@ -53,6 +53,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
53
53
|
emit = _ref2.emit,
|
|
54
54
|
emitEvent = _ref2.emitEvent,
|
|
55
55
|
props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
|
|
56
|
+
console.log("888");
|
|
56
57
|
var width = props.width,
|
|
57
58
|
height = props.height;
|
|
58
59
|
var isIOS = (0, _react.useRef)(/iPad|iPhone|iPod|iOS/i.test(navigator.userAgent) || /Mac OS X/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent));
|
package/lib/formatter/legend.js
CHANGED
|
@@ -65,6 +65,7 @@ var pieLegendFormatter = exports.pieLegendFormatter = function pieLegendFormatte
|
|
|
65
65
|
if (showName) columns.push("".concat(props.nameMaxWidth, "px"));
|
|
66
66
|
if (showValue) columns.push("".concat(props.valueMaxWidth + valueGap, "px"));
|
|
67
67
|
if (showPercent) columns.push("".concat(props.percentMaxWidth + percentGap, "px"));
|
|
68
|
+
columns[columns.length - 1] = "auto";
|
|
68
69
|
return /*#__PURE__*/React.createElement(React.Fragment, null, icon && /*#__PURE__*/React.createElement("span", {
|
|
69
70
|
style: _objectSpread(_objectSpread({}, icon), {}, {
|
|
70
71
|
marginRight: icon.marginRight,
|
package/lib/utils/index.js
CHANGED
|
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
exports.SvgBackground = void 0;
|
|
7
8
|
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
|
+
exports.sortPie = exports.seriesYOrZ = exports.resetStacks = exports.renderCanvasBackground = 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
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
@@ -27,7 +28,7 @@ var defaultLineIcon = {
|
|
|
27
28
|
height: 2,
|
|
28
29
|
background: defaultBackground
|
|
29
30
|
};
|
|
30
|
-
var
|
|
31
|
+
var renderCanvasBackground = exports.renderCanvasBackground = function renderCanvasBackground(_ref) {
|
|
31
32
|
var _ref$fill = _ref.fill,
|
|
32
33
|
type = _ref$fill.type,
|
|
33
34
|
pure = _ref$fill.pure,
|
|
@@ -46,6 +47,81 @@ var SvgBackground = function SvgBackground(_ref) {
|
|
|
46
47
|
stroke = _ref$pattern$boderCol === void 0 ? 'transparent' : _ref$pattern$boderCol,
|
|
47
48
|
_ref$pattern$boderWid = _ref$pattern.boderWidth,
|
|
48
49
|
boderWidth = _ref$pattern$boderWid === void 0 ? 0 : _ref$pattern$boderWid;
|
|
50
|
+
// 处理宽高(支持百分比/数字)
|
|
51
|
+
var canvasWidth = width === '100%' ? 200 : Number(width) || 200; // 百分比默认200,可根据实际场景调整
|
|
52
|
+
var canvasHeight = height === '100%' ? 200 : Number(height) || 200;
|
|
53
|
+
|
|
54
|
+
// 创建离屏 Canvas
|
|
55
|
+
var canvas = document.createElement('canvas');
|
|
56
|
+
var ctx = canvas.getContext('2d');
|
|
57
|
+
canvas.width = canvasWidth;
|
|
58
|
+
canvas.height = canvasHeight;
|
|
59
|
+
|
|
60
|
+
// 清空画布
|
|
61
|
+
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
62
|
+
|
|
63
|
+
// 1. 解析 SVG Path 为 Canvas Path2D
|
|
64
|
+
var path2D = new Path2D(path);
|
|
65
|
+
|
|
66
|
+
// 2. 处理填充(纯色/渐变)
|
|
67
|
+
if (type === 'pure') {
|
|
68
|
+
ctx.fillStyle = pure;
|
|
69
|
+
} else {
|
|
70
|
+
// 线性渐变(对应原 SVG linearGradient)
|
|
71
|
+
var centerX = canvasWidth / 2;
|
|
72
|
+
var centerY = canvasHeight / 2;
|
|
73
|
+
var rad = (angle + 180) * Math.PI / 180; // 旋转角度转弧度
|
|
74
|
+
var gradientLength = Math.hypot(canvasWidth, canvasHeight); // 渐变长度取对角线
|
|
75
|
+
|
|
76
|
+
// 计算渐变起点/终点(匹配 SVG rotate 效果)
|
|
77
|
+
var startX = centerX - Math.sin(rad) * gradientLength;
|
|
78
|
+
var startY = centerY - Math.cos(rad) * gradientLength;
|
|
79
|
+
var endX = centerX + Math.sin(rad) * gradientLength;
|
|
80
|
+
var endY = centerY + Math.cos(rad) * gradientLength;
|
|
81
|
+
|
|
82
|
+
// 创建渐变
|
|
83
|
+
var gradient = ctx.createLinearGradient(startX, startY, endX, endY);
|
|
84
|
+
stops.forEach(function (_ref2) {
|
|
85
|
+
var offset = _ref2.offset,
|
|
86
|
+
color = _ref2.color;
|
|
87
|
+
gradient.addColorStop(offset / 100, color);
|
|
88
|
+
gradient.opacity = opacity; // 透明度
|
|
89
|
+
});
|
|
90
|
+
ctx.fillStyle = gradient;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 3. 处理描边
|
|
94
|
+
ctx.strokeStyle = stroke;
|
|
95
|
+
ctx.lineWidth = boderWidth;
|
|
96
|
+
|
|
97
|
+
// 4. 绘制路径
|
|
98
|
+
ctx.fill(path2D);
|
|
99
|
+
if (boderWidth > 0) {
|
|
100
|
+
ctx.stroke(path2D);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 5. 转换为 DataURL(替代 SVG DataURL)
|
|
104
|
+
return canvas.toDataURL('image/png');
|
|
105
|
+
};
|
|
106
|
+
var SvgBackground = exports.SvgBackground = function SvgBackground(_ref3) {
|
|
107
|
+
var _ref3$fill = _ref3.fill,
|
|
108
|
+
type = _ref3$fill.type,
|
|
109
|
+
pure = _ref3$fill.pure,
|
|
110
|
+
_ref3$fill$linear = _ref3$fill.linear,
|
|
111
|
+
angle = _ref3$fill$linear.angle,
|
|
112
|
+
opacity = _ref3$fill$linear.opacity,
|
|
113
|
+
stops = _ref3$fill$linear.stops,
|
|
114
|
+
_ref3$pattern = _ref3.pattern,
|
|
115
|
+
_ref3$pattern$path = _ref3$pattern.path,
|
|
116
|
+
path = _ref3$pattern$path === void 0 ? '' : _ref3$pattern$path,
|
|
117
|
+
_ref3$pattern$width = _ref3$pattern.width,
|
|
118
|
+
width = _ref3$pattern$width === void 0 ? '100%' : _ref3$pattern$width,
|
|
119
|
+
_ref3$pattern$height = _ref3$pattern.height,
|
|
120
|
+
height = _ref3$pattern$height === void 0 ? '100%' : _ref3$pattern$height,
|
|
121
|
+
_ref3$pattern$boderCo = _ref3$pattern.boderColor,
|
|
122
|
+
stroke = _ref3$pattern$boderCo === void 0 ? 'transparent' : _ref3$pattern$boderCo,
|
|
123
|
+
_ref3$pattern$boderWi = _ref3$pattern.boderWidth,
|
|
124
|
+
boderWidth = _ref3$pattern$boderWi === void 0 ? 0 : _ref3$pattern$boderWi;
|
|
49
125
|
return /*#__PURE__*/React.createElement("svg", {
|
|
50
126
|
preserveAspectRatio: "none",
|
|
51
127
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -58,9 +134,9 @@ var SvgBackground = function SvgBackground(_ref) {
|
|
|
58
134
|
x2: "0%",
|
|
59
135
|
y2: "100%",
|
|
60
136
|
gradientTransform: 'rotate(' + (angle + 180) + ', 0.5, 0.5)'
|
|
61
|
-
}, stops.map(function (
|
|
62
|
-
var offset =
|
|
63
|
-
color =
|
|
137
|
+
}, stops.map(function (_ref4, index) {
|
|
138
|
+
var offset = _ref4.offset,
|
|
139
|
+
color = _ref4.color;
|
|
64
140
|
return /*#__PURE__*/React.createElement("stop", {
|
|
65
141
|
key: index,
|
|
66
142
|
offset: offset + '%',
|
|
@@ -74,13 +150,13 @@ var SvgBackground = function SvgBackground(_ref) {
|
|
|
74
150
|
strokeWidth: boderWidth
|
|
75
151
|
}));
|
|
76
152
|
};
|
|
77
|
-
var getColorList = exports.getColorList = function getColorList(
|
|
78
|
-
var type =
|
|
79
|
-
pure =
|
|
80
|
-
|
|
81
|
-
stops =
|
|
82
|
-
angle =
|
|
83
|
-
opacity =
|
|
153
|
+
var getColorList = exports.getColorList = function getColorList(_ref5) {
|
|
154
|
+
var type = _ref5.type,
|
|
155
|
+
pure = _ref5.pure,
|
|
156
|
+
_ref5$linear = _ref5.linear,
|
|
157
|
+
stops = _ref5$linear.stops,
|
|
158
|
+
angle = _ref5$linear.angle,
|
|
159
|
+
opacity = _ref5$linear.opacity;
|
|
84
160
|
if (type == 'pure') {
|
|
85
161
|
return [{
|
|
86
162
|
color: pure,
|
|
@@ -90,9 +166,9 @@ var getColorList = exports.getColorList = function getColorList(_ref3) {
|
|
|
90
166
|
offset: 0
|
|
91
167
|
}];
|
|
92
168
|
}
|
|
93
|
-
return stops.map(function (
|
|
94
|
-
var color =
|
|
95
|
-
offset =
|
|
169
|
+
return stops.map(function (_ref6) {
|
|
170
|
+
var color = _ref6.color,
|
|
171
|
+
offset = _ref6.offset;
|
|
96
172
|
return {
|
|
97
173
|
color: color,
|
|
98
174
|
offset: offset / 100
|
|
@@ -114,7 +190,7 @@ var getMultiColorStr = exports.getMultiColorStr = function getMultiColorStr(colo
|
|
|
114
190
|
offset = _stops_$i.offset;
|
|
115
191
|
result += "".concat(color, " ").concat(offset, "%,");
|
|
116
192
|
}
|
|
117
|
-
return result.slice(0, -1) +
|
|
193
|
+
return result.slice(0, -1) + ')';
|
|
118
194
|
}
|
|
119
195
|
};
|
|
120
196
|
var getIcon = exports.getIcon = function getIcon(type, icon) {
|
|
@@ -201,15 +277,15 @@ var getTicksOfAxis = exports.getTicksOfAxis = function getTicksOfAxis(domain, ti
|
|
|
201
277
|
}
|
|
202
278
|
return ticksArr;
|
|
203
279
|
};
|
|
204
|
-
var getTickCoord = exports.getTickCoord = function getTickCoord(
|
|
205
|
-
var orientation =
|
|
206
|
-
coordinate =
|
|
207
|
-
|
|
208
|
-
tickSize =
|
|
209
|
-
|
|
210
|
-
x =
|
|
211
|
-
|
|
212
|
-
y =
|
|
280
|
+
var getTickCoord = exports.getTickCoord = function getTickCoord(_ref7) {
|
|
281
|
+
var orientation = _ref7.orientation,
|
|
282
|
+
coordinate = _ref7.coordinate,
|
|
283
|
+
_ref7$tickSize = _ref7.tickSize,
|
|
284
|
+
tickSize = _ref7$tickSize === void 0 ? 6 : _ref7$tickSize,
|
|
285
|
+
_ref7$x = _ref7.x,
|
|
286
|
+
x = _ref7$x === void 0 ? 0 : _ref7$x,
|
|
287
|
+
_ref7$y = _ref7.y,
|
|
288
|
+
y = _ref7$y === void 0 ? 0 : _ref7$y;
|
|
213
289
|
var x1, x2, y1, y2;
|
|
214
290
|
switch (orientation) {
|
|
215
291
|
case 'top':
|
|
@@ -240,10 +316,10 @@ var getTickCoord = exports.getTickCoord = function getTickCoord(_ref5) {
|
|
|
240
316
|
y2: y2
|
|
241
317
|
};
|
|
242
318
|
};
|
|
243
|
-
var getGridCoord = exports.getGridCoord = function getGridCoord(
|
|
244
|
-
var orientation =
|
|
245
|
-
coordinate =
|
|
246
|
-
end =
|
|
319
|
+
var getGridCoord = exports.getGridCoord = function getGridCoord(_ref8) {
|
|
320
|
+
var orientation = _ref8.orientation,
|
|
321
|
+
coordinate = _ref8.coordinate,
|
|
322
|
+
end = _ref8.end;
|
|
247
323
|
var x1, x2, y1, y2;
|
|
248
324
|
switch (orientation) {
|
|
249
325
|
case 'top':
|
|
@@ -288,14 +364,14 @@ var getMousePos = exports.getMousePos = function getMousePos(evt, dom) {
|
|
|
288
364
|
h: rect.height
|
|
289
365
|
};
|
|
290
366
|
};
|
|
291
|
-
var getFontStyle = exports.getFontStyle = function getFontStyle(
|
|
292
|
-
var color =
|
|
293
|
-
bold =
|
|
294
|
-
italic =
|
|
295
|
-
fontSize =
|
|
296
|
-
fontFamily =
|
|
297
|
-
letterSpacing =
|
|
298
|
-
lineHeight =
|
|
367
|
+
var getFontStyle = exports.getFontStyle = function getFontStyle(_ref9, type) {
|
|
368
|
+
var color = _ref9.color,
|
|
369
|
+
bold = _ref9.bold,
|
|
370
|
+
italic = _ref9.italic,
|
|
371
|
+
fontSize = _ref9.fontSize,
|
|
372
|
+
fontFamily = _ref9.fontFamily,
|
|
373
|
+
letterSpacing = _ref9.letterSpacing,
|
|
374
|
+
lineHeight = _ref9.lineHeight;
|
|
299
375
|
if (type == 'svg') {
|
|
300
376
|
return {
|
|
301
377
|
fontSize: fontSize,
|
|
@@ -317,12 +393,12 @@ var getFontStyle = exports.getFontStyle = function getFontStyle(_ref7, type) {
|
|
|
317
393
|
lineHeight: lineHeight + "px" //不加px默认是倍数关系
|
|
318
394
|
};
|
|
319
395
|
};
|
|
320
|
-
var formatFont = exports.formatFont = function formatFont(
|
|
321
|
-
var color =
|
|
322
|
-
fill =
|
|
323
|
-
bold =
|
|
324
|
-
italic =
|
|
325
|
-
rest = (0, _objectWithoutProperties2["default"])(
|
|
396
|
+
var formatFont = exports.formatFont = function formatFont(_ref10, type) {
|
|
397
|
+
var color = _ref10.color,
|
|
398
|
+
fill = _ref10.fill,
|
|
399
|
+
bold = _ref10.bold,
|
|
400
|
+
italic = _ref10.italic,
|
|
401
|
+
rest = (0, _objectWithoutProperties2["default"])(_ref10, _excluded);
|
|
326
402
|
if (type == 'svg') {
|
|
327
403
|
return _objectSpread({
|
|
328
404
|
fill: fill || color,
|
|
@@ -336,27 +412,27 @@ var formatFont = exports.formatFont = function formatFont(_ref8, type) {
|
|
|
336
412
|
fontStyle: typeof italic == "string" ? italic : italic ? 'italic' : 'normal'
|
|
337
413
|
}, rest);
|
|
338
414
|
};
|
|
339
|
-
var getMargin = exports.getMargin = function getMargin(
|
|
340
|
-
var marginTop =
|
|
341
|
-
marginRight =
|
|
342
|
-
marginBottom =
|
|
343
|
-
marginLeft =
|
|
415
|
+
var getMargin = exports.getMargin = function getMargin(_ref11) {
|
|
416
|
+
var marginTop = _ref11.marginTop,
|
|
417
|
+
marginRight = _ref11.marginRight,
|
|
418
|
+
marginBottom = _ref11.marginBottom,
|
|
419
|
+
marginLeft = _ref11.marginLeft;
|
|
344
420
|
return marginTop + 'px ' + marginRight + 'px ' + marginBottom + 'px ' + marginLeft + 'px';
|
|
345
421
|
};
|
|
346
|
-
var getTranslate3d = exports.getTranslate3d = function getTranslate3d(
|
|
347
|
-
var
|
|
348
|
-
x =
|
|
349
|
-
|
|
350
|
-
y =
|
|
351
|
-
|
|
352
|
-
z =
|
|
422
|
+
var getTranslate3d = exports.getTranslate3d = function getTranslate3d(_ref12) {
|
|
423
|
+
var _ref12$x = _ref12.x,
|
|
424
|
+
x = _ref12$x === void 0 ? 0 : _ref12$x,
|
|
425
|
+
_ref12$y = _ref12.y,
|
|
426
|
+
y = _ref12$y === void 0 ? 0 : _ref12$y,
|
|
427
|
+
_ref12$z = _ref12.z,
|
|
428
|
+
z = _ref12$z === void 0 ? 0 : _ref12$z;
|
|
353
429
|
return 'translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)';
|
|
354
430
|
};
|
|
355
|
-
var getTranslate2d = exports.getTranslate2d = function getTranslate2d(
|
|
356
|
-
var
|
|
357
|
-
x =
|
|
358
|
-
|
|
359
|
-
y =
|
|
431
|
+
var getTranslate2d = exports.getTranslate2d = function getTranslate2d(_ref13) {
|
|
432
|
+
var _ref13$x = _ref13.x,
|
|
433
|
+
x = _ref13$x === void 0 ? 0 : _ref13$x,
|
|
434
|
+
_ref13$y = _ref13.y,
|
|
435
|
+
y = _ref13$y === void 0 ? 0 : _ref13$y;
|
|
360
436
|
return 'translate(' + x + ', ' + y + ')';
|
|
361
437
|
};
|
|
362
438
|
function band() {
|
|
@@ -370,9 +446,6 @@ function band() {
|
|
|
370
446
|
round = false,
|
|
371
447
|
paddingInner = 0,
|
|
372
448
|
paddingOuter = 0,
|
|
373
|
-
// seriesPaddingInner = 0,
|
|
374
|
-
// seriesPaddingOuter = 0,
|
|
375
|
-
// seriesLength = 0,
|
|
376
449
|
align = 0.5;
|
|
377
450
|
delete scale.unknown;
|
|
378
451
|
function rescale() {
|
|
@@ -394,12 +467,12 @@ function band() {
|
|
|
394
467
|
return arguments.length ? (domain(_), rescale()) : domain();
|
|
395
468
|
};
|
|
396
469
|
scale.range = function (_) {
|
|
397
|
-
var
|
|
398
|
-
return arguments.length ? (
|
|
470
|
+
var _ref14;
|
|
471
|
+
return arguments.length ? (_ref14 = (0, _slicedToArray2["default"])(_, 2), r0 = _ref14[0], r1 = _ref14[1], r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
|
|
399
472
|
};
|
|
400
473
|
scale.rangeRound = function (_) {
|
|
401
|
-
var
|
|
402
|
-
return
|
|
474
|
+
var _ref15;
|
|
475
|
+
return _ref15 = (0, _slicedToArray2["default"])(_, 2), r0 = _ref15[0], r1 = _ref15[1], r0 = +r0, r1 = +r1, round = true, rescale();
|
|
403
476
|
};
|
|
404
477
|
scale.bandwidth = function () {
|
|
405
478
|
return bandwidth;
|
|
@@ -448,14 +521,14 @@ function initRange(domain, range) {
|
|
|
448
521
|
}
|
|
449
522
|
var getStacks = exports.getStacks = function getStacks(series) {
|
|
450
523
|
var tmp = [];
|
|
451
|
-
series.forEach(function (
|
|
452
|
-
var type =
|
|
453
|
-
stack =
|
|
454
|
-
yOrZ =
|
|
455
|
-
var current = tmp.find(function (
|
|
456
|
-
var _type =
|
|
457
|
-
_stack =
|
|
458
|
-
_yOrZ =
|
|
524
|
+
series.forEach(function (_ref16, name) {
|
|
525
|
+
var type = _ref16.type,
|
|
526
|
+
stack = _ref16.stack,
|
|
527
|
+
yOrZ = _ref16.yOrZ;
|
|
528
|
+
var current = tmp.find(function (_ref17) {
|
|
529
|
+
var _type = _ref17.type,
|
|
530
|
+
_stack = _ref17.stack,
|
|
531
|
+
_yOrZ = _ref17.yOrZ;
|
|
459
532
|
return _type == type && stack && _stack == stack && yOrZ == _yOrZ;
|
|
460
533
|
});
|
|
461
534
|
if (!current) {
|
|
@@ -485,9 +558,9 @@ var getStacks = exports.getStacks = function getStacks(series) {
|
|
|
485
558
|
});
|
|
486
559
|
return tmp;
|
|
487
560
|
};
|
|
488
|
-
var dataYOrZ = exports.dataYOrZ = function dataYOrZ(data,
|
|
489
|
-
var seriesY =
|
|
490
|
-
seriesZ =
|
|
561
|
+
var dataYOrZ = exports.dataYOrZ = function dataYOrZ(data, _ref18) {
|
|
562
|
+
var seriesY = _ref18.y,
|
|
563
|
+
seriesZ = _ref18.z;
|
|
491
564
|
var tmp = {
|
|
492
565
|
y: [],
|
|
493
566
|
z: []
|
|
@@ -526,11 +599,11 @@ var resetStacks = exports.resetStacks = function resetStacks(stacks) {
|
|
|
526
599
|
});
|
|
527
600
|
};
|
|
528
601
|
var getCurrentStack = exports.getCurrentStack = function getCurrentStack(stack, stackMap) {
|
|
529
|
-
return stackMap.find(function (
|
|
530
|
-
var _stack =
|
|
531
|
-
_type =
|
|
532
|
-
_yOrZ =
|
|
533
|
-
_s =
|
|
602
|
+
return stackMap.find(function (_ref19) {
|
|
603
|
+
var _stack = _ref19.stack,
|
|
604
|
+
_type = _ref19.type,
|
|
605
|
+
_yOrZ = _ref19.yOrZ,
|
|
606
|
+
_s = _ref19.s;
|
|
534
607
|
return _type == stack.type && _stack == stack.stack && _yOrZ == stack.yOrZ && _s.includes(stack.name);
|
|
535
608
|
});
|
|
536
609
|
};
|
|
@@ -570,20 +643,24 @@ var getBandBackground = exports.getBandBackground = function getBandBackground(p
|
|
|
570
643
|
var _pattern$backgroundSi = pattern.backgroundSize,
|
|
571
644
|
backgroundSize = _pattern$backgroundSi === void 0 ? '100% 100%' : _pattern$backgroundSi,
|
|
572
645
|
_pattern = (0, _objectWithoutProperties2["default"])(pattern, _excluded2);
|
|
573
|
-
|
|
646
|
+
// 替换原 SVG DataURL 为 Canvas DataURL
|
|
647
|
+
var canvasDataUrl = renderCanvasBackground({
|
|
574
648
|
fill: fill,
|
|
575
649
|
pattern: _pattern
|
|
576
|
-
})
|
|
577
|
-
|
|
650
|
+
});
|
|
651
|
+
return 'center top / ' + backgroundSize + ' url("' + canvasDataUrl + '")';
|
|
652
|
+
} catch (e) {
|
|
653
|
+
console.error('Canvas 绘制背景失败:', e);
|
|
654
|
+
}
|
|
578
655
|
return "";
|
|
579
656
|
};
|
|
580
657
|
var getBandwidth = exports.getBandwidth = function getBandwidth(step, paddingOuter) {
|
|
581
658
|
return step * (1 - paddingOuter);
|
|
582
659
|
};
|
|
583
|
-
var getBandSeriesStepAndWidth = exports.getBandSeriesStepAndWidth = function getBandSeriesStepAndWidth(
|
|
584
|
-
var width =
|
|
585
|
-
paddingInner =
|
|
586
|
-
bandLength =
|
|
660
|
+
var getBandSeriesStepAndWidth = exports.getBandSeriesStepAndWidth = function getBandSeriesStepAndWidth(_ref20) {
|
|
661
|
+
var width = _ref20.width,
|
|
662
|
+
paddingInner = _ref20.paddingInner,
|
|
663
|
+
bandLength = _ref20.bandLength;
|
|
587
664
|
var seriesStep = width / (bandLength == 0 ? 1 : bandLength);
|
|
588
665
|
var seriesWidth = seriesStep * (1 - paddingInner);
|
|
589
666
|
return {
|
|
@@ -591,14 +668,14 @@ var getBandSeriesStepAndWidth = exports.getBandSeriesStepAndWidth = function get
|
|
|
591
668
|
seriesWidth: seriesWidth
|
|
592
669
|
};
|
|
593
670
|
};
|
|
594
|
-
var getSeriesInfo = exports.getSeriesInfo = function getSeriesInfo(
|
|
595
|
-
var step =
|
|
596
|
-
|
|
597
|
-
bandLength =
|
|
598
|
-
|
|
599
|
-
paddingInner =
|
|
600
|
-
|
|
601
|
-
paddingOuter =
|
|
671
|
+
var getSeriesInfo = exports.getSeriesInfo = function getSeriesInfo(_ref21) {
|
|
672
|
+
var step = _ref21.step,
|
|
673
|
+
_ref21$bandLength = _ref21.bandLength,
|
|
674
|
+
bandLength = _ref21$bandLength === void 0 ? 1 : _ref21$bandLength,
|
|
675
|
+
_ref21$paddingInner = _ref21.paddingInner,
|
|
676
|
+
paddingInner = _ref21$paddingInner === void 0 ? 0 : _ref21$paddingInner,
|
|
677
|
+
_ref21$paddingOuter = _ref21.paddingOuter,
|
|
678
|
+
paddingOuter = _ref21$paddingOuter === void 0 ? 0 : _ref21$paddingOuter;
|
|
602
679
|
if (bandLength == 0) return {
|
|
603
680
|
seriesWidth: step,
|
|
604
681
|
seriesStep: step,
|
|
@@ -705,54 +782,29 @@ var sortPie = exports.sortPie = function sortPie(data, order) {
|
|
|
705
782
|
});
|
|
706
783
|
switch (order) {
|
|
707
784
|
case '':
|
|
708
|
-
_data.sort(function (
|
|
709
|
-
var a =
|
|
710
|
-
var b =
|
|
785
|
+
_data.sort(function (_ref22, _ref23) {
|
|
786
|
+
var a = _ref22.index;
|
|
787
|
+
var b = _ref23.index;
|
|
711
788
|
return (0, _d3v.ascending)(a, b);
|
|
712
789
|
});
|
|
713
790
|
break;
|
|
714
791
|
case 'desc':
|
|
715
|
-
_data.sort(function (
|
|
716
|
-
var a =
|
|
717
|
-
var b =
|
|
792
|
+
_data.sort(function (_ref24, _ref25) {
|
|
793
|
+
var a = _ref24.value;
|
|
794
|
+
var b = _ref25.value;
|
|
718
795
|
return (0, _d3v.descending)(a, b);
|
|
719
796
|
});
|
|
720
797
|
break;
|
|
721
798
|
case 'asc':
|
|
722
|
-
_data.sort(function (
|
|
723
|
-
var a =
|
|
724
|
-
var b =
|
|
799
|
+
_data.sort(function (_ref26, _ref27) {
|
|
800
|
+
var a = _ref26.value;
|
|
801
|
+
var b = _ref27.value;
|
|
725
802
|
return (0, _d3v.ascending)(a, b);
|
|
726
803
|
});
|
|
727
804
|
break;
|
|
728
805
|
}
|
|
729
806
|
return _data;
|
|
730
807
|
};
|
|
731
|
-
|
|
732
|
-
// const getDataWithPercent = (data = [], precision = 0, type) => {
|
|
733
|
-
// const digits = Math.pow(10, precision);
|
|
734
|
-
// const targetSeats = digits * 100;
|
|
735
|
-
|
|
736
|
-
// const total = sum(data, (d) => d.value);
|
|
737
|
-
|
|
738
|
-
// const votesPerQuota = data.map((d, index) => ({
|
|
739
|
-
// ...d,
|
|
740
|
-
// vote: Math.round((d.value / total) * digits * 100),
|
|
741
|
-
// index,
|
|
742
|
-
// }));
|
|
743
|
-
// const currentSum = sum(votesPerQuota, (d) => d.vote);
|
|
744
|
-
// const remainder = targetSeats - currentSum;
|
|
745
|
-
// console.log(type+":",votesPerQuota, toFixed);
|
|
746
|
-
// votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
|
|
747
|
-
|
|
748
|
-
// const tmp = votesPerQuota.map(({ vote, ...data }, index) => ({
|
|
749
|
-
// ...data,
|
|
750
|
-
// percent: toFixed((vote + (index < remainder ? 1 : 0)) / digits, precision),
|
|
751
|
-
// }));
|
|
752
|
-
|
|
753
|
-
// return tmp;
|
|
754
|
-
// };
|
|
755
|
-
|
|
756
808
|
var getDataWithPercent = exports.getDataWithPercent = function getDataWithPercent() {
|
|
757
809
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
758
810
|
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
package/package.json
CHANGED
package/src/components/Chart.js
CHANGED
package/src/formatter/legend.js
CHANGED
|
@@ -49,11 +49,11 @@ export const pieLegendFormatter = (
|
|
|
49
49
|
const textMarginLeft = 5;
|
|
50
50
|
|
|
51
51
|
// 1. 计算每列宽度(加上间距)
|
|
52
|
-
|
|
52
|
+
let columns = [];
|
|
53
53
|
if (showName) columns.push(`${props.nameMaxWidth}px`);
|
|
54
54
|
if (showValue) columns.push(`${props.valueMaxWidth + valueGap}px`);
|
|
55
55
|
if (showPercent) columns.push(`${props.percentMaxWidth + percentGap}px`);
|
|
56
|
-
|
|
56
|
+
columns[columns.length-1]="auto"
|
|
57
57
|
return (
|
|
58
58
|
<>
|
|
59
59
|
{icon &&<span style={{ ...icon, marginRight: icon.marginRight, transform:`translate(${nameX}px, ${nameY}px)` }} />}
|
package/src/utils/index.js
CHANGED
|
@@ -18,6 +18,74 @@ const defaultLineIcon = {
|
|
|
18
18
|
height: 2,
|
|
19
19
|
background: defaultBackground,
|
|
20
20
|
};
|
|
21
|
+
const renderCanvasBackground = ({
|
|
22
|
+
fill: {
|
|
23
|
+
type,
|
|
24
|
+
pure,
|
|
25
|
+
linear: { angle, opacity, stops },
|
|
26
|
+
},
|
|
27
|
+
pattern: {
|
|
28
|
+
path = '',
|
|
29
|
+
width = '100%',
|
|
30
|
+
height = '100%',
|
|
31
|
+
boderColor: stroke = 'transparent',
|
|
32
|
+
boderWidth = 0,
|
|
33
|
+
},
|
|
34
|
+
}) => {
|
|
35
|
+
// 处理宽高(支持百分比/数字)
|
|
36
|
+
const canvasWidth = width === '100%' ? 200 : Number(width) || 200; // 百分比默认200,可根据实际场景调整
|
|
37
|
+
const canvasHeight = height === '100%' ? 200 : Number(height) || 200;
|
|
38
|
+
|
|
39
|
+
// 创建离屏 Canvas
|
|
40
|
+
const canvas = document.createElement('canvas');
|
|
41
|
+
const ctx = canvas.getContext('2d');
|
|
42
|
+
canvas.width = canvasWidth;
|
|
43
|
+
canvas.height = canvasHeight;
|
|
44
|
+
|
|
45
|
+
// 清空画布
|
|
46
|
+
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
47
|
+
|
|
48
|
+
// 1. 解析 SVG Path 为 Canvas Path2D
|
|
49
|
+
const path2D = new Path2D(path);
|
|
50
|
+
|
|
51
|
+
// 2. 处理填充(纯色/渐变)
|
|
52
|
+
if (type === 'pure') {
|
|
53
|
+
ctx.fillStyle = pure;
|
|
54
|
+
} else {
|
|
55
|
+
// 线性渐变(对应原 SVG linearGradient)
|
|
56
|
+
const centerX = canvasWidth / 2;
|
|
57
|
+
const centerY = canvasHeight / 2;
|
|
58
|
+
const rad = (angle + 180) * Math.PI / 180; // 旋转角度转弧度
|
|
59
|
+
const gradientLength = Math.hypot(canvasWidth, canvasHeight); // 渐变长度取对角线
|
|
60
|
+
|
|
61
|
+
// 计算渐变起点/终点(匹配 SVG rotate 效果)
|
|
62
|
+
const startX = centerX - Math.sin(rad) * gradientLength;
|
|
63
|
+
const startY = centerY - Math.cos(rad) * gradientLength;
|
|
64
|
+
const endX = centerX + Math.sin(rad) * gradientLength;
|
|
65
|
+
const endY = centerY + Math.cos(rad) * gradientLength;
|
|
66
|
+
|
|
67
|
+
// 创建渐变
|
|
68
|
+
const gradient = ctx.createLinearGradient(startX, startY, endX, endY);
|
|
69
|
+
stops.forEach(({ offset, color }) => {
|
|
70
|
+
gradient.addColorStop(offset / 100, color);
|
|
71
|
+
gradient.opacity = opacity; // 透明度
|
|
72
|
+
});
|
|
73
|
+
ctx.fillStyle = gradient;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 3. 处理描边
|
|
77
|
+
ctx.strokeStyle = stroke;
|
|
78
|
+
ctx.lineWidth = boderWidth;
|
|
79
|
+
|
|
80
|
+
// 4. 绘制路径
|
|
81
|
+
ctx.fill(path2D);
|
|
82
|
+
if (boderWidth > 0) {
|
|
83
|
+
ctx.stroke(path2D);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 5. 转换为 DataURL(替代 SVG DataURL)
|
|
87
|
+
return canvas.toDataURL('image/png');
|
|
88
|
+
};
|
|
21
89
|
const SvgBackground = ({
|
|
22
90
|
fill: {
|
|
23
91
|
type,
|
|
@@ -76,20 +144,21 @@ const getColorList = ({ type, pure, linear: { stops, angle, opacity } }) => {
|
|
|
76
144
|
}
|
|
77
145
|
return stops.map(({ color, offset }) => ({ color, offset: offset / 100 }));
|
|
78
146
|
};
|
|
79
|
-
const getMultiColorStr = (colors)=>{
|
|
80
|
-
if(colors){
|
|
147
|
+
const getMultiColorStr = (colors) => {
|
|
148
|
+
if (colors) {
|
|
81
149
|
const { stops, angle } = colors;
|
|
82
150
|
let result = 'linear-gradient(' + angle + 'deg, ';
|
|
83
151
|
const stops_ = JSON.parse(JSON.stringify(stops));
|
|
84
|
-
stops_.sort((a,b)=>a.offset-b.offset);
|
|
85
|
-
for(let i=0;i<stops_.length;i++){
|
|
152
|
+
stops_.sort((a, b) => a.offset - b.offset);
|
|
153
|
+
for (let i = 0; i < stops_.length; i++) {
|
|
86
154
|
const { color, offset } = stops_[i];
|
|
87
155
|
result += `${color} ${offset}%,`;
|
|
88
156
|
}
|
|
89
|
-
return result.slice(0
|
|
157
|
+
return result.slice(0, -1) + ')';
|
|
90
158
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const getIcon = (type, icon, lineType = "solid") => {
|
|
93
162
|
switch (type) {
|
|
94
163
|
case 'area':
|
|
95
164
|
case 'line':
|
|
@@ -99,7 +168,7 @@ const getIcon = (type, icon, lineType="solid") => {
|
|
|
99
168
|
...defaultLineIcon,
|
|
100
169
|
...icon,
|
|
101
170
|
minWidth: icon.width,
|
|
102
|
-
background:lineType=="solid"?color
|
|
171
|
+
background: lineType == "solid" ? color : `linear-gradient(90deg, ${color}, ${color} 66%, transparent 66%) 0 0/33% 100% repeat`
|
|
103
172
|
}
|
|
104
173
|
: defaultLineIcon;
|
|
105
174
|
default:
|
|
@@ -150,6 +219,7 @@ const dateFormat = (date, fmt) => {
|
|
|
150
219
|
);
|
|
151
220
|
return fmt;
|
|
152
221
|
};
|
|
222
|
+
|
|
153
223
|
const getBreakWord = (str, breakNumber) => {
|
|
154
224
|
const re = new RegExp('([^]){1,' + breakNumber + '}', 'g');
|
|
155
225
|
return str.match(re);
|
|
@@ -164,27 +234,27 @@ const getTicksOfAxis = (domain, ticksCount, showLast) => {
|
|
|
164
234
|
if (showLast) {
|
|
165
235
|
let count = ticksCount, gap = 0;
|
|
166
236
|
step = (len - 1) / (count - 1);
|
|
167
|
-
const maxGap = Math.max(count-2,len-count);
|
|
237
|
+
const maxGap = Math.max(count - 2, len - count);
|
|
168
238
|
//循环计算出最接近count值且能让step为整数的值
|
|
169
|
-
if(!Number.isInteger(step)){
|
|
170
|
-
while(gap<=maxGap){
|
|
239
|
+
if (!Number.isInteger(step)) {
|
|
240
|
+
while (gap <= maxGap) {
|
|
171
241
|
gap++;
|
|
172
|
-
const left = (len-1)/(count-gap-1), right = (len-1)/(count+gap-1);
|
|
173
|
-
if(Number.isInteger(left)){
|
|
242
|
+
const left = (len - 1) / (count - gap - 1), right = (len - 1) / (count + gap - 1);
|
|
243
|
+
if (Number.isInteger(left)) {
|
|
174
244
|
step = left;
|
|
175
245
|
break;
|
|
176
246
|
}
|
|
177
|
-
if(Number.isInteger(right)){
|
|
247
|
+
if (Number.isInteger(right)) {
|
|
178
248
|
step = right;
|
|
179
249
|
break;
|
|
180
250
|
}
|
|
181
251
|
}
|
|
182
252
|
}
|
|
183
|
-
if(!Number.isInteger(step)) step = 1; //如果找不到整数的step,直接取1,返回所有刻度
|
|
253
|
+
if (!Number.isInteger(step)) step = 1; //如果找不到整数的step,直接取1,返回所有刻度
|
|
184
254
|
ticksArr = domain.filter(function (d, i) {
|
|
185
255
|
return i % step === 0;
|
|
186
256
|
});
|
|
187
|
-
}else{
|
|
257
|
+
} else {
|
|
188
258
|
ticksArr = domain.filter(function (d, i) {
|
|
189
259
|
return i % (step + 1) === 0;
|
|
190
260
|
});
|
|
@@ -265,7 +335,7 @@ const getMousePos = (evt, dom) => {
|
|
|
265
335
|
};
|
|
266
336
|
|
|
267
337
|
const getFontStyle = (
|
|
268
|
-
{ color, bold, italic, fontSize, fontFamily, letterSpacing,lineHeight },
|
|
338
|
+
{ color, bold, italic, fontSize, fontFamily, letterSpacing, lineHeight },
|
|
269
339
|
type
|
|
270
340
|
) => {
|
|
271
341
|
if (type == 'svg') {
|
|
@@ -276,7 +346,7 @@ const getFontStyle = (
|
|
|
276
346
|
fill: color,
|
|
277
347
|
fontWeight: bold ? 'bold' : 'normal',
|
|
278
348
|
fontStyle: italic ? 'italic' : 'normal',
|
|
279
|
-
lineHeight:lineHeight+"px"
|
|
349
|
+
lineHeight: lineHeight + "px"
|
|
280
350
|
};
|
|
281
351
|
}
|
|
282
352
|
return {
|
|
@@ -286,26 +356,26 @@ const getFontStyle = (
|
|
|
286
356
|
color,
|
|
287
357
|
fontWeight: bold ? 'bold' : 'normal',
|
|
288
358
|
fontStyle: italic ? 'italic' : 'normal',
|
|
289
|
-
lineHeight:lineHeight+"px"//不加px默认是倍数关系
|
|
359
|
+
lineHeight: lineHeight + "px"//不加px默认是倍数关系
|
|
290
360
|
};
|
|
291
361
|
};
|
|
292
|
-
|
|
293
|
-
|
|
362
|
+
|
|
363
|
+
const formatFont = ({ color, fill, bold, italic, ...rest }, type) => {
|
|
294
364
|
if (type == 'svg') {
|
|
295
365
|
return {
|
|
296
366
|
fill: fill || color,
|
|
297
|
-
fontWeight: typeof bold=="string" ? bold : (
|
|
298
|
-
fontStyle: typeof italic=="string"? italic : (italic ? 'italic' : 'normal'),
|
|
367
|
+
fontWeight: typeof bold == "string" ? bold : (bold ? 'bold' : 'normal'),
|
|
368
|
+
fontStyle: typeof italic == "string" ? italic : (italic ? 'italic' : 'normal'),
|
|
299
369
|
...rest
|
|
300
370
|
};
|
|
301
371
|
}
|
|
302
372
|
return {
|
|
303
|
-
color:color|| fill,
|
|
304
|
-
fontWeight: typeof bold=="string" ? bold : (
|
|
305
|
-
fontStyle: typeof italic=="string"? italic : (italic ? 'italic' : 'normal'),
|
|
373
|
+
color: color || fill,
|
|
374
|
+
fontWeight: typeof bold == "string" ? bold : (bold ? 'bold' : 'normal'),
|
|
375
|
+
fontStyle: typeof italic == "string" ? italic : (italic ? 'italic' : 'normal'),
|
|
306
376
|
...rest
|
|
307
377
|
};
|
|
308
|
-
}
|
|
378
|
+
};
|
|
309
379
|
|
|
310
380
|
const getMargin = ({ marginTop, marginRight, marginBottom, marginLeft }) =>
|
|
311
381
|
marginTop +
|
|
@@ -316,9 +386,12 @@ const getMargin = ({ marginTop, marginRight, marginBottom, marginLeft }) =>
|
|
|
316
386
|
'px ' +
|
|
317
387
|
marginLeft +
|
|
318
388
|
'px';
|
|
389
|
+
|
|
319
390
|
const getTranslate3d = ({ x = 0, y = 0, z = 0 }) =>
|
|
320
391
|
'translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)';
|
|
392
|
+
|
|
321
393
|
const getTranslate2d = ({ x = 0, y = 0 }) => 'translate(' + x + ', ' + y + ')';
|
|
394
|
+
|
|
322
395
|
function band() {
|
|
323
396
|
var scale = ordinal().unknown(undefined),
|
|
324
397
|
domain = scale.domain,
|
|
@@ -330,9 +403,6 @@ function band() {
|
|
|
330
403
|
round = false,
|
|
331
404
|
paddingInner = 0,
|
|
332
405
|
paddingOuter = 0,
|
|
333
|
-
// seriesPaddingInner = 0,
|
|
334
|
-
// seriesPaddingOuter = 0,
|
|
335
|
-
// seriesLength = 0,
|
|
336
406
|
align = 0.5;
|
|
337
407
|
|
|
338
408
|
delete scale.unknown;
|
|
@@ -515,49 +585,51 @@ const getCurrentStack = (stack, stackMap) =>
|
|
|
515
585
|
_yOrZ == stack.yOrZ &&
|
|
516
586
|
_s.includes(stack.name)
|
|
517
587
|
);
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const stops = gradient.linear.stops;
|
|
523
|
-
//先按 offset 排序(升序),确保输入是规范的
|
|
524
|
-
const sortedStops = [...stops].sort((a, b) => a.offset - b.offset);
|
|
525
|
-
|
|
526
|
-
// 反转每个 stop 的 offset: newOffset = 100 - oldOffset
|
|
527
|
-
// 颜色保持不变,只是位置镜像翻转
|
|
528
|
-
const reversedStops = sortedStops.map(stop => ({
|
|
529
|
-
...stop,
|
|
530
|
-
offset: 100 - stop.offset
|
|
531
|
-
}));
|
|
532
|
-
//再按新的 offset 升序排序,确保输出结构正确
|
|
533
|
-
const finalStops = reversedStops.sort((a, b) => a.offset - b.offset);
|
|
534
|
-
|
|
535
|
-
return {
|
|
536
|
-
...gradient,
|
|
537
|
-
linear: {
|
|
538
|
-
...gradient.linear,
|
|
539
|
-
stops: finalStops
|
|
540
|
-
}
|
|
541
|
-
};
|
|
588
|
+
|
|
589
|
+
const reverseGradientStops = (gradient) => {
|
|
590
|
+
if (gradient.type !== 'linear' || !gradient.linear?.stops) {
|
|
591
|
+
return gradient;
|
|
542
592
|
}
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
593
|
+
const stops = gradient.linear.stops;
|
|
594
|
+
//先按 offset 排序(升序),确保输入是规范的
|
|
595
|
+
const sortedStops = [...stops].sort((a, b) => a.offset - b.offset);
|
|
596
|
+
|
|
597
|
+
// 反转每个 stop 的 offset: newOffset = 100 - oldOffset
|
|
598
|
+
// 颜色保持不变,只是位置镜像翻转
|
|
599
|
+
const reversedStops = sortedStops.map(stop => ({
|
|
600
|
+
...stop,
|
|
601
|
+
offset: 100 - stop.offset
|
|
602
|
+
}));
|
|
603
|
+
//再按新的 offset 升序排序,确保输出结构正确
|
|
604
|
+
const finalStops = reversedStops.sort((a, b) => a.offset - b.offset);
|
|
605
|
+
|
|
606
|
+
return {
|
|
607
|
+
...gradient,
|
|
608
|
+
linear: {
|
|
609
|
+
...gradient.linear,
|
|
610
|
+
stops: finalStops
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
const getBandBackground = (pattern, fill, y) => {
|
|
615
|
+
if (!(pattern && pattern.path)) {
|
|
616
|
+
return getColor(y < 0 ? reverseGradientStops(fill) : fill);//小于0颜色翻转
|
|
546
617
|
}
|
|
547
|
-
try{
|
|
618
|
+
try {
|
|
548
619
|
const { backgroundSize = '100% 100%', ..._pattern } = pattern;
|
|
620
|
+
// 替换原 SVG DataURL 为 Canvas DataURL
|
|
621
|
+
const canvasDataUrl = renderCanvasBackground({ fill, pattern: _pattern });
|
|
549
622
|
return (
|
|
550
623
|
'center top / ' +
|
|
551
624
|
backgroundSize +
|
|
552
|
-
' url("
|
|
553
|
-
encodeURIComponent(
|
|
554
|
-
renderToStaticMarkup(<SvgBackground fill={fill} pattern={_pattern} />)
|
|
555
|
-
) +
|
|
556
|
-
'")'
|
|
625
|
+
' url("' + canvasDataUrl + '")'
|
|
557
626
|
);
|
|
558
|
-
}catch(e){
|
|
627
|
+
} catch (e) {
|
|
628
|
+
console.error('Canvas 绘制背景失败:', e);
|
|
629
|
+
}
|
|
559
630
|
return "";
|
|
560
631
|
};
|
|
632
|
+
|
|
561
633
|
const getBandwidth = (step, paddingOuter) => step * (1 - paddingOuter);
|
|
562
634
|
|
|
563
635
|
const getBandSeriesStepAndWidth = ({ width, paddingInner, bandLength }) => {
|
|
@@ -708,37 +780,13 @@ const sortPie = (data, order) => {
|
|
|
708
780
|
return _data;
|
|
709
781
|
};
|
|
710
782
|
|
|
711
|
-
// const getDataWithPercent = (data = [], precision = 0, type) => {
|
|
712
|
-
// const digits = Math.pow(10, precision);
|
|
713
|
-
// const targetSeats = digits * 100;
|
|
714
|
-
|
|
715
|
-
// const total = sum(data, (d) => d.value);
|
|
716
|
-
|
|
717
|
-
// const votesPerQuota = data.map((d, index) => ({
|
|
718
|
-
// ...d,
|
|
719
|
-
// vote: Math.round((d.value / total) * digits * 100),
|
|
720
|
-
// index,
|
|
721
|
-
// }));
|
|
722
|
-
// const currentSum = sum(votesPerQuota, (d) => d.vote);
|
|
723
|
-
// const remainder = targetSeats - currentSum;
|
|
724
|
-
// console.log(type+":",votesPerQuota, toFixed);
|
|
725
|
-
// votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
|
|
726
|
-
|
|
727
|
-
// const tmp = votesPerQuota.map(({ vote, ...data }, index) => ({
|
|
728
|
-
// ...data,
|
|
729
|
-
// percent: toFixed((vote + (index < remainder ? 1 : 0)) / digits, precision),
|
|
730
|
-
// }));
|
|
731
|
-
|
|
732
|
-
// return tmp;
|
|
733
|
-
// };
|
|
734
|
-
|
|
735
783
|
const getDataWithPercent = (data = [], precision = 0) => {
|
|
736
784
|
let objData = [];
|
|
737
785
|
function getPercentWithPrecision(valueList, idx, precision) {
|
|
738
786
|
if (!valueList[idx]) {
|
|
739
787
|
return 0;
|
|
740
788
|
}
|
|
741
|
-
const sum = valueList.reduce(
|
|
789
|
+
const sum = valueList.reduce(function (acc, val) {
|
|
742
790
|
return acc + val.value;
|
|
743
791
|
}, 0);
|
|
744
792
|
if (sum === 0) {
|
|
@@ -752,7 +800,7 @@ const getDataWithPercent = (data = [], precision = 0) => {
|
|
|
752
800
|
const seats = votesPerQuota.map(function (votes) {
|
|
753
801
|
return Math.floor(votes);
|
|
754
802
|
});
|
|
755
|
-
let currentSum = seats.reduce(
|
|
803
|
+
let currentSum = seats.reduce(function (acc, val) {
|
|
756
804
|
return acc + val;
|
|
757
805
|
}, 0);
|
|
758
806
|
const remainder = votesPerQuota.map(function (votes, idx) {
|
|
@@ -800,10 +848,10 @@ const reduceConfig = (config = []) => {
|
|
|
800
848
|
};
|
|
801
849
|
|
|
802
850
|
//限制value的值在min和max之间
|
|
803
|
-
const mathR=(value, range)=>{
|
|
804
|
-
const [min,max] = range;
|
|
805
|
-
return Math.max(min,Math.min(value,max));
|
|
806
|
-
}
|
|
851
|
+
const mathR = (value, range) => {
|
|
852
|
+
const [min, max] = range;
|
|
853
|
+
return Math.max(min, Math.min(value, max));
|
|
854
|
+
};
|
|
807
855
|
|
|
808
856
|
export {
|
|
809
857
|
dateFormat,
|
|
@@ -838,5 +886,7 @@ export {
|
|
|
838
886
|
getDataWithPercent,
|
|
839
887
|
reduceConfig,
|
|
840
888
|
getSeriesInfo,
|
|
841
|
-
mathR
|
|
842
|
-
|
|
889
|
+
mathR,
|
|
890
|
+
renderCanvasBackground, // 导出 Canvas 绘制方法
|
|
891
|
+
SvgBackground
|
|
892
|
+
};
|