@easyv/charts 1.10.33 → 1.10.35
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/Legend.js +79 -6
- package/lib/components/PieChart.js +494 -287
- package/package.json +1 -1
- package/src/components/Legend.js +91 -0
- package/src/components/PieChart.js +207 -13
|
@@ -7,10 +7,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports["default"] = void 0;
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
14
14
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
15
|
var _ = require(".");
|
|
16
16
|
var _context = require("../context");
|
|
@@ -196,16 +196,116 @@ var getCoord = function getCoord(deg, radius) {
|
|
|
196
196
|
y = Math.sin(deg) * radius;
|
|
197
197
|
return [x, y];
|
|
198
198
|
};
|
|
199
|
-
var
|
|
200
|
-
var
|
|
201
|
-
|
|
199
|
+
var parseFontSize = function parseFontSize(value) {
|
|
200
|
+
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
|
|
201
|
+
var n = parseFloat(value);
|
|
202
|
+
return Number.isFinite(n) ? n : fallback;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// 与 getFontStyle 一致:实际行盒高度取 lineHeight,否则用 fontSize
|
|
206
|
+
var getFontLineHeight = function getFontLineHeight(font) {
|
|
207
|
+
var fontSize = parseFontSize(font === null || font === void 0 ? void 0 : font.fontSize);
|
|
208
|
+
var lineHeight = parseFontSize(font === null || font === void 0 ? void 0 : font.lineHeight, 0);
|
|
209
|
+
return Math.max(lineHeight, fontSize);
|
|
210
|
+
};
|
|
211
|
+
var getLabelRowHeight = function getLabelRowHeight(_ref) {
|
|
212
|
+
var showName = _ref.showName,
|
|
213
|
+
showValue = _ref.showValue,
|
|
214
|
+
showPercent = _ref.showPercent,
|
|
215
|
+
nameFont = _ref.nameFont,
|
|
216
|
+
valueFont = _ref.valueFont,
|
|
217
|
+
percentFont = _ref.percentFont;
|
|
218
|
+
var sizes = [];
|
|
219
|
+
if (showName) sizes.push(getFontLineHeight(nameFont));
|
|
220
|
+
if (showValue) sizes.push(getFontLineHeight(valueFont));
|
|
221
|
+
if (showPercent) sizes.push(getFontLineHeight(percentFont));
|
|
222
|
+
return sizes.length ? Math.max.apply(Math, sizes) : 12;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// 上下布局:名称/数值/百分比纵向排列,高度 = 各可见行的行高之和
|
|
226
|
+
var getLabelColumnHeight = function getLabelColumnHeight(_ref2) {
|
|
227
|
+
var showName = _ref2.showName,
|
|
228
|
+
showValue = _ref2.showValue,
|
|
229
|
+
showPercent = _ref2.showPercent,
|
|
230
|
+
nameFont = _ref2.nameFont,
|
|
231
|
+
valueFont = _ref2.valueFont,
|
|
232
|
+
percentFont = _ref2.percentFont;
|
|
233
|
+
var height = 0;
|
|
234
|
+
if (showName) height += getFontLineHeight(nameFont);
|
|
235
|
+
if (showValue) height += getFontLineHeight(valueFont);
|
|
236
|
+
if (showPercent) height += getFontLineHeight(percentFont);
|
|
237
|
+
return height || 12;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// 水平布局:同侧重叠时按半高之和推开
|
|
241
|
+
var resolveLabelY = function resolveLabelY(y2, side, placedYBySide, labelHeight) {
|
|
242
|
+
var placed = placedYBySide[side];
|
|
243
|
+
var finalY = y2;
|
|
244
|
+
var stackDown = y2 >= 0;
|
|
245
|
+
var isOverlap = function isOverlap(y, py, h) {
|
|
246
|
+
return Math.abs(y - py) < (labelHeight + h) / 2;
|
|
247
|
+
};
|
|
248
|
+
var guard = 0;
|
|
249
|
+
while (guard++ < 50 && placed.some(function (_ref3) {
|
|
250
|
+
var py = _ref3.y,
|
|
251
|
+
h = _ref3.height;
|
|
252
|
+
return isOverlap(finalY, py, h);
|
|
253
|
+
})) {
|
|
254
|
+
var hits = placed.filter(function (_ref4) {
|
|
255
|
+
var py = _ref4.y,
|
|
256
|
+
h = _ref4.height;
|
|
257
|
+
return isOverlap(finalY, py, h);
|
|
258
|
+
});
|
|
259
|
+
finalY = stackDown ? Math.max.apply(Math, (0, _toConsumableArray2["default"])(hits.map(function (_ref5) {
|
|
260
|
+
var py = _ref5.y,
|
|
261
|
+
h = _ref5.height;
|
|
262
|
+
return py + (labelHeight + h) / 2;
|
|
263
|
+
}))) : Math.min.apply(Math, (0, _toConsumableArray2["default"])(hits.map(function (_ref6) {
|
|
264
|
+
var py = _ref6.y,
|
|
265
|
+
h = _ref6.height;
|
|
266
|
+
return py - (labelHeight + h) / 2;
|
|
267
|
+
})));
|
|
268
|
+
}
|
|
269
|
+
placed.push({
|
|
270
|
+
y: finalY,
|
|
271
|
+
height: labelHeight
|
|
272
|
+
});
|
|
273
|
+
return finalY;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// 上下布局:过近时只按「自身标签高度」相对上一个已放置位置偏移
|
|
277
|
+
var resolveLabelYVertical = function resolveLabelYVertical(y2, side, placedYBySide, labelHeight) {
|
|
278
|
+
var placed = placedYBySide[side];
|
|
279
|
+
var stackDown = y2 >= 0;
|
|
280
|
+
var finalY = y2;
|
|
281
|
+
if (placed.some(function (_ref7) {
|
|
282
|
+
var py = _ref7.y;
|
|
283
|
+
return Math.abs(finalY - py) < labelHeight;
|
|
284
|
+
})) {
|
|
285
|
+
finalY = stackDown ? Math.max.apply(Math, (0, _toConsumableArray2["default"])(placed.map(function (_ref8) {
|
|
286
|
+
var py = _ref8.y;
|
|
287
|
+
return py;
|
|
288
|
+
}))) + labelHeight : Math.min.apply(Math, (0, _toConsumableArray2["default"])(placed.map(function (_ref9) {
|
|
289
|
+
var py = _ref9.y;
|
|
290
|
+
return py;
|
|
291
|
+
}))) - labelHeight;
|
|
292
|
+
}
|
|
293
|
+
placed.push({
|
|
294
|
+
y: finalY,
|
|
295
|
+
height: labelHeight
|
|
296
|
+
});
|
|
297
|
+
return finalY;
|
|
298
|
+
};
|
|
299
|
+
var getRoseRadius = function getRoseRadius(_ref10) {
|
|
300
|
+
var innerRadius = _ref10.innerRadius,
|
|
301
|
+
baseRadius = _ref10.baseRadius;
|
|
202
302
|
return innerRadius + (1 - innerRadius) * baseRadius;
|
|
203
303
|
};
|
|
204
|
-
var getAngle = function getAngle(
|
|
205
|
-
var startAngle =
|
|
206
|
-
endAngle =
|
|
207
|
-
antiClockwise =
|
|
208
|
-
rest = (0, _objectWithoutProperties2["default"])(
|
|
304
|
+
var getAngle = function getAngle(_ref11) {
|
|
305
|
+
var startAngle = _ref11.startAngle,
|
|
306
|
+
endAngle = _ref11.endAngle,
|
|
307
|
+
antiClockwise = _ref11.antiClockwise,
|
|
308
|
+
rest = (0, _objectWithoutProperties2["default"])(_ref11, _excluded);
|
|
209
309
|
if (antiClockwise) return _objectSpread(_objectSpread({}, rest), {}, {
|
|
210
310
|
startAngle: endAngle - 180,
|
|
211
311
|
endAngle: startAngle - 180
|
|
@@ -215,20 +315,20 @@ var getAngle = function getAngle(_ref2) {
|
|
|
215
315
|
endAngle: endAngle
|
|
216
316
|
});
|
|
217
317
|
};
|
|
218
|
-
var getArc = function getArc(radius,
|
|
219
|
-
var
|
|
220
|
-
padAngle =
|
|
221
|
-
|
|
222
|
-
innerRadius =
|
|
223
|
-
|
|
224
|
-
outerRadius =
|
|
225
|
-
|
|
226
|
-
cornerRadius =
|
|
227
|
-
|
|
228
|
-
startAngle =
|
|
229
|
-
|
|
230
|
-
endAngle =
|
|
231
|
-
rest = (0, _objectWithoutProperties2["default"])(
|
|
318
|
+
var getArc = function getArc(radius, _ref12, series_, index) {
|
|
319
|
+
var _ref12$padAngle = _ref12.padAngle,
|
|
320
|
+
padAngle = _ref12$padAngle === void 0 ? 0 : _ref12$padAngle,
|
|
321
|
+
_ref12$innerRadius = _ref12.innerRadius,
|
|
322
|
+
innerRadius = _ref12$innerRadius === void 0 ? 0 : _ref12$innerRadius,
|
|
323
|
+
_ref12$outerRadius = _ref12.outerRadius,
|
|
324
|
+
outerRadius = _ref12$outerRadius === void 0 ? 1 : _ref12$outerRadius,
|
|
325
|
+
_ref12$cornerRadius = _ref12.cornerRadius,
|
|
326
|
+
cornerRadius = _ref12$cornerRadius === void 0 ? 0 : _ref12$cornerRadius,
|
|
327
|
+
_ref12$startAngle = _ref12.startAngle,
|
|
328
|
+
startAngle = _ref12$startAngle === void 0 ? 0 : _ref12$startAngle,
|
|
329
|
+
_ref12$endAngle = _ref12.endAngle,
|
|
330
|
+
endAngle = _ref12$endAngle === void 0 ? 360 : _ref12$endAngle,
|
|
331
|
+
rest = (0, _objectWithoutProperties2["default"])(_ref12, _excluded2);
|
|
232
332
|
var series = series_.find(function (s) {
|
|
233
333
|
return s.fieldName == rest.data.s;
|
|
234
334
|
}) || series_[index % series_.length];
|
|
@@ -243,11 +343,11 @@ var getArc = function getArc(radius, _ref3, series_, index) {
|
|
|
243
343
|
});
|
|
244
344
|
};
|
|
245
345
|
var getCircleScale = function getCircleScale() {
|
|
246
|
-
var
|
|
247
|
-
count =
|
|
248
|
-
color =
|
|
249
|
-
width =
|
|
250
|
-
length =
|
|
346
|
+
var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : tick,
|
|
347
|
+
count = _ref13.count,
|
|
348
|
+
color = _ref13.color,
|
|
349
|
+
width = _ref13.width,
|
|
350
|
+
length = _ref13.length;
|
|
251
351
|
var radius = arguments.length > 1 ? arguments[1] : undefined;
|
|
252
352
|
var data = [],
|
|
253
353
|
arcs = [],
|
|
@@ -273,78 +373,78 @@ var getCircleScale = function getCircleScale() {
|
|
|
273
373
|
});
|
|
274
374
|
}));
|
|
275
375
|
};
|
|
276
|
-
var Component = /*#__PURE__*/(0, _react.memo)(function (
|
|
376
|
+
var Component = /*#__PURE__*/(0, _react.memo)(function (_ref14) {
|
|
277
377
|
var _legend$config2;
|
|
278
|
-
var width =
|
|
279
|
-
height =
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
label =
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
formatter =
|
|
286
|
-
legend = (0, _objectWithoutProperties2["default"])(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
ringDuration =
|
|
290
|
-
labelDuration =
|
|
291
|
-
|
|
292
|
-
marginLeft =
|
|
293
|
-
marginTop =
|
|
294
|
-
marginRight =
|
|
295
|
-
marginBottom =
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
chart =
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
outerRadius =
|
|
303
|
-
padAngle =
|
|
304
|
-
|
|
305
|
-
angle =
|
|
306
|
-
|
|
307
|
-
|
|
378
|
+
var width = _ref14.width,
|
|
379
|
+
height = _ref14.height,
|
|
380
|
+
_ref14$config = _ref14.config,
|
|
381
|
+
_ref14$config$chart = _ref14$config.chart,
|
|
382
|
+
label = _ref14$config$chart.label,
|
|
383
|
+
_ref14$config$chart$l = _ref14$config$chart.legend,
|
|
384
|
+
_ref14$config$chart$l2 = _ref14$config$chart$l.formatter,
|
|
385
|
+
formatter = _ref14$config$chart$l2 === void 0 ? _formatter.pieLegendFormatter : _ref14$config$chart$l2,
|
|
386
|
+
legend = (0, _objectWithoutProperties2["default"])(_ref14$config$chart$l, _excluded3),
|
|
387
|
+
_ref14$config$chart$a = _ref14$config$chart.animation,
|
|
388
|
+
_ref14$config$chart$a2 = _ref14$config$chart$a === void 0 ? {} : _ref14$config$chart$a,
|
|
389
|
+
ringDuration = _ref14$config$chart$a2.ringDuration,
|
|
390
|
+
labelDuration = _ref14$config$chart$a2.labelDuration,
|
|
391
|
+
_ref14$config$chart$m = _ref14$config$chart.margin,
|
|
392
|
+
marginLeft = _ref14$config$chart$m.marginLeft,
|
|
393
|
+
marginTop = _ref14$config$chart$m.marginTop,
|
|
394
|
+
marginRight = _ref14$config$chart$m.marginRight,
|
|
395
|
+
marginBottom = _ref14$config$chart$m.marginBottom,
|
|
396
|
+
_ref14$config$fan = _ref14$config.fan,
|
|
397
|
+
_ref14$config$fan2 = _ref14$config$fan === void 0 ? {} : _ref14$config$fan,
|
|
398
|
+
_ref14$config$fan2$ch = _ref14$config$fan2.chart,
|
|
399
|
+
chart = _ref14$config$fan2$ch === void 0 ? defaultChart : _ref14$config$fan2$ch,
|
|
400
|
+
_ref14$config$fan2$ch2 = _ref14$config$fan2.chart,
|
|
401
|
+
_ref14$config$fan2$ch3 = _ref14$config$fan2$ch2.outerRadius,
|
|
402
|
+
outerRadius = _ref14$config$fan2$ch3 === void 0 ? defaultChart.outerRadius : _ref14$config$fan2$ch3,
|
|
403
|
+
padAngle = _ref14$config$fan2$ch2.padAngle,
|
|
404
|
+
_ref14$config$fan2$an = _ref14$config$fan2.angle,
|
|
405
|
+
angle = _ref14$config$fan2$an === void 0 ? defaultAngle : _ref14$config$fan2$an,
|
|
406
|
+
_ref14$config$fan2$st = _ref14$config$fan2.stroke,
|
|
407
|
+
_ref14$config$fan2$st2 = _ref14$config$fan2$st === void 0 ? {
|
|
308
408
|
show: false
|
|
309
|
-
} :
|
|
310
|
-
show =
|
|
311
|
-
strokeWidth =
|
|
312
|
-
color =
|
|
313
|
-
decorate =
|
|
314
|
-
decorate2 =
|
|
315
|
-
categoryText =
|
|
316
|
-
outerDecorate =
|
|
317
|
-
current =
|
|
318
|
-
order =
|
|
319
|
-
columnsSeries =
|
|
320
|
-
series =
|
|
321
|
-
|
|
322
|
-
on =
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
widthen =
|
|
326
|
-
|
|
327
|
-
heighten =
|
|
328
|
-
|
|
329
|
-
opacity =
|
|
330
|
-
|
|
331
|
-
radiusWidthAdd =
|
|
332
|
-
animateColor =
|
|
333
|
-
animateCTS =
|
|
334
|
-
|
|
335
|
-
gap =
|
|
336
|
-
|
|
337
|
-
rotate =
|
|
338
|
-
|
|
339
|
-
tooltip =
|
|
340
|
-
config =
|
|
341
|
-
|
|
342
|
-
currentIndex =
|
|
343
|
-
trigger =
|
|
344
|
-
onEvent =
|
|
345
|
-
hoverEvent =
|
|
346
|
-
|
|
347
|
-
originData =
|
|
409
|
+
} : _ref14$config$fan2$st,
|
|
410
|
+
show = _ref14$config$fan2$st2.show,
|
|
411
|
+
strokeWidth = _ref14$config$fan2$st2.strokeWidth,
|
|
412
|
+
color = _ref14$config$fan2$st2.color,
|
|
413
|
+
decorate = _ref14$config$fan2.decorate,
|
|
414
|
+
decorate2 = _ref14$config$fan2.decorate2,
|
|
415
|
+
categoryText = _ref14$config$fan2.categoryText,
|
|
416
|
+
outerDecorate = _ref14$config$fan2.outerDecorate,
|
|
417
|
+
current = _ref14$config$fan2.current,
|
|
418
|
+
order = _ref14$config.order,
|
|
419
|
+
columnsSeries = _ref14$config.columnsSeries,
|
|
420
|
+
series = _ref14$config.series,
|
|
421
|
+
_ref14$config$animati = _ref14$config.animation,
|
|
422
|
+
on = _ref14$config$animati.on,
|
|
423
|
+
_ref14$config$animati2 = _ref14$config$animati.current,
|
|
424
|
+
_ref14$config$animati3 = _ref14$config$animati2.widthen,
|
|
425
|
+
widthen = _ref14$config$animati3 === void 0 ? 0 : _ref14$config$animati3,
|
|
426
|
+
_ref14$config$animati4 = _ref14$config$animati2.heighten,
|
|
427
|
+
heighten = _ref14$config$animati4 === void 0 ? 0 : _ref14$config$animati4,
|
|
428
|
+
_ref14$config$animati5 = _ref14$config$animati2.opacity,
|
|
429
|
+
opacity = _ref14$config$animati5 === void 0 ? 0 : _ref14$config$animati5,
|
|
430
|
+
_ref14$config$animati6 = _ref14$config$animati2.width,
|
|
431
|
+
radiusWidthAdd = _ref14$config$animati6 === void 0 ? 0 : _ref14$config$animati6,
|
|
432
|
+
animateColor = _ref14$config$animati2.color,
|
|
433
|
+
animateCTS = _ref14$config$animati2.textStyle,
|
|
434
|
+
_ref14$config$animati7 = _ref14$config$animati2.gap,
|
|
435
|
+
gap = _ref14$config$animati7 === void 0 ? 0 : _ref14$config$animati7,
|
|
436
|
+
_ref14$config$animati8 = _ref14$config$animati.rotate,
|
|
437
|
+
rotate = _ref14$config$animati8 === void 0 ? 0 : _ref14$config$animati8,
|
|
438
|
+
_ref14$config$tooltip = _ref14$config.tooltip,
|
|
439
|
+
tooltip = _ref14$config$tooltip === void 0 ? {} : _ref14$config$tooltip,
|
|
440
|
+
config = _ref14.config,
|
|
441
|
+
_ref14$state = _ref14.state,
|
|
442
|
+
currentIndex = _ref14$state.currentIndex,
|
|
443
|
+
trigger = _ref14$state.trigger,
|
|
444
|
+
onEvent = _ref14.onEvent,
|
|
445
|
+
hoverEvent = _ref14.hoverEvent,
|
|
446
|
+
_ref14$data = _ref14.data,
|
|
447
|
+
originData = _ref14$data === void 0 ? [] : _ref14$data;
|
|
348
448
|
var data = originData.map(function (d) {
|
|
349
449
|
return _objectSpread(_objectSpread({}, d), {}, {
|
|
350
450
|
y: d.y < 0 ? 0 : d.y
|
|
@@ -479,10 +579,10 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
479
579
|
var roseRadius = getRoseRadius(_chart);
|
|
480
580
|
var scaler = (0, _d3v.scaleLinear)().domain(domain).range([roseRadius, 1]);
|
|
481
581
|
var _angle = PI * 2 / _legendDataWithPercent.length;
|
|
482
|
-
return _legendDataWithPercent.map(function (
|
|
483
|
-
var startAngle =
|
|
484
|
-
endAngle =
|
|
485
|
-
arc = (0, _objectWithoutProperties2["default"])(
|
|
582
|
+
return _legendDataWithPercent.map(function (_ref15, index) {
|
|
583
|
+
var startAngle = _ref15.startAngle,
|
|
584
|
+
endAngle = _ref15.endAngle,
|
|
585
|
+
arc = (0, _objectWithoutProperties2["default"])(_ref15, _excluded4);
|
|
486
586
|
return _objectSpread(_objectSpread({}, arc), {}, {
|
|
487
587
|
id: id + "_linear_" + index,
|
|
488
588
|
startAngle: roseType == "area" ? _angle * index : startAngle,
|
|
@@ -635,13 +735,13 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
635
735
|
fill: "none",
|
|
636
736
|
stroke: outerDecorate.color,
|
|
637
737
|
strokeWidth: outerDecorate.width
|
|
638
|
-
}), _arcs.map(function (
|
|
639
|
-
var id =
|
|
640
|
-
value =
|
|
641
|
-
series =
|
|
642
|
-
arc =
|
|
643
|
-
innerRadius =
|
|
644
|
-
outerRadius =
|
|
738
|
+
}), _arcs.map(function (_ref16, index) {
|
|
739
|
+
var id = _ref16.id,
|
|
740
|
+
value = _ref16.value,
|
|
741
|
+
series = _ref16.series,
|
|
742
|
+
arc = _ref16.arc,
|
|
743
|
+
innerRadius = _ref16.innerRadius,
|
|
744
|
+
outerRadius = _ref16.outerRadius;
|
|
645
745
|
var arcWidth = outerRadius - innerRadius;
|
|
646
746
|
var path = arc.innerRadius(centerRadius).outerRadius(centerRadius)(value);
|
|
647
747
|
var dashLength = Math.ceil(Math.PI * centerRadius * 2 / _arcs.length);
|
|
@@ -744,14 +844,14 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
744
844
|
transition: "transform ease-in-out 0.3s",
|
|
745
845
|
transform: "translate(" + halfChartWidth + "px, " + halfChartHeight + "px) rotate(" + rotate_ + "deg)"
|
|
746
846
|
}
|
|
747
|
-
}, _arcs.map(function (
|
|
748
|
-
var id =
|
|
749
|
-
value =
|
|
750
|
-
series =
|
|
751
|
-
arc =
|
|
752
|
-
innerRadius =
|
|
753
|
-
outerRadius =
|
|
754
|
-
dataIndex =
|
|
847
|
+
}, _arcs.map(function (_ref17, index) {
|
|
848
|
+
var id = _ref17.id,
|
|
849
|
+
value = _ref17.value,
|
|
850
|
+
series = _ref17.series,
|
|
851
|
+
arc = _ref17.arc,
|
|
852
|
+
innerRadius = _ref17.innerRadius,
|
|
853
|
+
outerRadius = _ref17.outerRadius,
|
|
854
|
+
dataIndex = _ref17.index;
|
|
755
855
|
var current = index == currentIndex;
|
|
756
856
|
var prev = index == prevIndex.current;
|
|
757
857
|
var offset = current ? y : prev ? 1 - y : 0;
|
|
@@ -901,53 +1001,53 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
901
1001
|
mousePos: mousePos
|
|
902
1002
|
})));
|
|
903
1003
|
});
|
|
904
|
-
var Current = function Current(
|
|
905
|
-
var
|
|
906
|
-
show =
|
|
907
|
-
gap =
|
|
908
|
-
|
|
909
|
-
showName =
|
|
910
|
-
nameColor =
|
|
911
|
-
nameFont =
|
|
912
|
-
|
|
913
|
-
translate =
|
|
1004
|
+
var Current = function Current(_ref18) {
|
|
1005
|
+
var _ref18$config = _ref18.config,
|
|
1006
|
+
show = _ref18$config.show,
|
|
1007
|
+
gap = _ref18$config.gap,
|
|
1008
|
+
_ref18$config$name = _ref18$config.name,
|
|
1009
|
+
showName = _ref18$config$name.show,
|
|
1010
|
+
nameColor = _ref18$config$name.sameColor,
|
|
1011
|
+
nameFont = _ref18$config$name.font,
|
|
1012
|
+
_ref18$config$name$tr = _ref18$config$name.translate,
|
|
1013
|
+
translate = _ref18$config$name$tr === void 0 ? {
|
|
914
1014
|
x: 0,
|
|
915
1015
|
y: 0
|
|
916
|
-
} :
|
|
917
|
-
maxWidth =
|
|
918
|
-
textOverflow =
|
|
919
|
-
speed =
|
|
920
|
-
|
|
921
|
-
showPercent =
|
|
922
|
-
percentColor =
|
|
923
|
-
percentFont =
|
|
924
|
-
precision =
|
|
925
|
-
|
|
926
|
-
translatePercentX =
|
|
927
|
-
translatePercentY =
|
|
928
|
-
|
|
929
|
-
showValue =
|
|
930
|
-
valueColor =
|
|
931
|
-
valueFont =
|
|
932
|
-
|
|
933
|
-
translateValueX =
|
|
934
|
-
translateValueY =
|
|
935
|
-
|
|
936
|
-
showSuffix =
|
|
937
|
-
fontSize =
|
|
938
|
-
text =
|
|
939
|
-
|
|
940
|
-
translateSuffixX =
|
|
941
|
-
translateSuffixY =
|
|
942
|
-
|
|
943
|
-
isIOS =
|
|
944
|
-
marginLeft =
|
|
945
|
-
marginTop =
|
|
946
|
-
width =
|
|
947
|
-
height =
|
|
948
|
-
data =
|
|
949
|
-
judge =
|
|
950
|
-
currentIndex =
|
|
1016
|
+
} : _ref18$config$name$tr,
|
|
1017
|
+
maxWidth = _ref18$config$name.maxWidth,
|
|
1018
|
+
textOverflow = _ref18$config$name.textOverflow,
|
|
1019
|
+
speed = _ref18$config$name.speed,
|
|
1020
|
+
_ref18$config$percent = _ref18$config.percent,
|
|
1021
|
+
showPercent = _ref18$config$percent.show,
|
|
1022
|
+
percentColor = _ref18$config$percent.sameColor,
|
|
1023
|
+
percentFont = _ref18$config$percent.font,
|
|
1024
|
+
precision = _ref18$config$percent.precision,
|
|
1025
|
+
_ref18$config$percent2 = _ref18$config$percent.translate,
|
|
1026
|
+
translatePercentX = _ref18$config$percent2.x,
|
|
1027
|
+
translatePercentY = _ref18$config$percent2.y,
|
|
1028
|
+
_ref18$config$value = _ref18$config.value,
|
|
1029
|
+
showValue = _ref18$config$value.show,
|
|
1030
|
+
valueColor = _ref18$config$value.sameColor,
|
|
1031
|
+
valueFont = _ref18$config$value.font,
|
|
1032
|
+
_ref18$config$value$t = _ref18$config$value.translate,
|
|
1033
|
+
translateValueX = _ref18$config$value$t.x,
|
|
1034
|
+
translateValueY = _ref18$config$value$t.y,
|
|
1035
|
+
_ref18$config$value$s = _ref18$config$value.suffix,
|
|
1036
|
+
showSuffix = _ref18$config$value$s.show,
|
|
1037
|
+
fontSize = _ref18$config$value$s.fontSize,
|
|
1038
|
+
text = _ref18$config$value$s.text,
|
|
1039
|
+
_ref18$config$value$s2 = _ref18$config$value$s.translate,
|
|
1040
|
+
translateSuffixX = _ref18$config$value$s2.x,
|
|
1041
|
+
translateSuffixY = _ref18$config$value$s2.y,
|
|
1042
|
+
_ref18$iosStyle = _ref18.iosStyle,
|
|
1043
|
+
isIOS = _ref18$iosStyle.isIOS,
|
|
1044
|
+
marginLeft = _ref18$iosStyle.marginLeft,
|
|
1045
|
+
marginTop = _ref18$iosStyle.marginTop,
|
|
1046
|
+
width = _ref18.width,
|
|
1047
|
+
height = _ref18.height,
|
|
1048
|
+
data = _ref18.data,
|
|
1049
|
+
judge = _ref18.judge,
|
|
1050
|
+
currentIndex = _ref18.currentIndex;
|
|
951
1051
|
var _data = (0, _react.useMemo)(function () {
|
|
952
1052
|
var legendDataWithPercent = (0, _utils.getDataWithPercent)(data, precision);
|
|
953
1053
|
return (0, _utils.sortPie)(legendDataWithPercent, "");
|
|
@@ -1032,51 +1132,51 @@ var Current = function Current(_ref9) {
|
|
|
1032
1132
|
})
|
|
1033
1133
|
}, percent + "%")));
|
|
1034
1134
|
};
|
|
1035
|
-
var Label = function Label(
|
|
1036
|
-
var
|
|
1037
|
-
|
|
1038
|
-
maxRadius =
|
|
1039
|
-
lineLength =
|
|
1040
|
-
lineColor =
|
|
1041
|
-
distance =
|
|
1042
|
-
mode =
|
|
1043
|
-
align =
|
|
1044
|
-
show =
|
|
1045
|
-
|
|
1046
|
-
translateX =
|
|
1047
|
-
translateY =
|
|
1048
|
-
|
|
1049
|
-
showName =
|
|
1050
|
-
nameFont =
|
|
1051
|
-
maxWidth =
|
|
1052
|
-
textOverflow =
|
|
1053
|
-
speed =
|
|
1054
|
-
NameTranslate =
|
|
1055
|
-
|
|
1056
|
-
showValue =
|
|
1057
|
-
valueFont =
|
|
1058
|
-
valueSameColor =
|
|
1059
|
-
|
|
1060
|
-
showSuffix =
|
|
1061
|
-
text =
|
|
1062
|
-
suffixFontSize =
|
|
1063
|
-
|
|
1064
|
-
suffixTranslateX =
|
|
1065
|
-
suffixTranslateY =
|
|
1066
|
-
ValueTranslate =
|
|
1067
|
-
|
|
1068
|
-
showPercent =
|
|
1069
|
-
percentSameColor =
|
|
1070
|
-
percentFont =
|
|
1071
|
-
precision =
|
|
1072
|
-
PercentTranslate =
|
|
1073
|
-
|
|
1074
|
-
isIOS =
|
|
1075
|
-
left =
|
|
1076
|
-
top =
|
|
1077
|
-
arcs =
|
|
1078
|
-
judge =
|
|
1079
|
-
animation =
|
|
1135
|
+
var Label = function Label(_ref19) {
|
|
1136
|
+
var _ref19$config = _ref19.config,
|
|
1137
|
+
_ref19$config$maxRadi = _ref19$config.maxRadius,
|
|
1138
|
+
maxRadius = _ref19$config$maxRadi === void 0 ? 0 : _ref19$config$maxRadi,
|
|
1139
|
+
lineLength = _ref19$config.lineLength,
|
|
1140
|
+
lineColor = _ref19$config.lineColor,
|
|
1141
|
+
distance = _ref19$config.distance,
|
|
1142
|
+
mode = _ref19$config.mode,
|
|
1143
|
+
align = _ref19$config.align,
|
|
1144
|
+
show = _ref19$config.show,
|
|
1145
|
+
_ref19$config$transla = _ref19$config.translate,
|
|
1146
|
+
translateX = _ref19$config$transla.x,
|
|
1147
|
+
translateY = _ref19$config$transla.y,
|
|
1148
|
+
_ref19$config$name = _ref19$config.name,
|
|
1149
|
+
showName = _ref19$config$name.show,
|
|
1150
|
+
nameFont = _ref19$config$name.font,
|
|
1151
|
+
maxWidth = _ref19$config$name.maxWidth,
|
|
1152
|
+
textOverflow = _ref19$config$name.textOverflow,
|
|
1153
|
+
speed = _ref19$config$name.speed,
|
|
1154
|
+
NameTranslate = _ref19$config$name.translate,
|
|
1155
|
+
_ref19$config$value = _ref19$config.value,
|
|
1156
|
+
showValue = _ref19$config$value.show,
|
|
1157
|
+
valueFont = _ref19$config$value.font,
|
|
1158
|
+
valueSameColor = _ref19$config$value.sameColor,
|
|
1159
|
+
_ref19$config$value$s = _ref19$config$value.suffix,
|
|
1160
|
+
showSuffix = _ref19$config$value$s.show,
|
|
1161
|
+
text = _ref19$config$value$s.text,
|
|
1162
|
+
suffixFontSize = _ref19$config$value$s.fontSize,
|
|
1163
|
+
_ref19$config$value$s2 = _ref19$config$value$s.translate,
|
|
1164
|
+
suffixTranslateX = _ref19$config$value$s2.x,
|
|
1165
|
+
suffixTranslateY = _ref19$config$value$s2.y,
|
|
1166
|
+
ValueTranslate = _ref19$config$value.translate,
|
|
1167
|
+
_ref19$config$percent = _ref19$config.percent,
|
|
1168
|
+
showPercent = _ref19$config$percent.show,
|
|
1169
|
+
percentSameColor = _ref19$config$percent.sameColor,
|
|
1170
|
+
percentFont = _ref19$config$percent.font,
|
|
1171
|
+
precision = _ref19$config$percent.precision,
|
|
1172
|
+
PercentTranslate = _ref19$config$percent.translate,
|
|
1173
|
+
_ref19$iosStyle = _ref19.iosStyle,
|
|
1174
|
+
isIOS = _ref19$iosStyle.isIOS,
|
|
1175
|
+
left = _ref19$iosStyle.left,
|
|
1176
|
+
top = _ref19$iosStyle.top,
|
|
1177
|
+
arcs = _ref19.arcs,
|
|
1178
|
+
judge = _ref19.judge,
|
|
1179
|
+
animation = _ref19.animation;
|
|
1080
1180
|
var _arcs = (0, _react.useMemo)(function () {
|
|
1081
1181
|
return (0, _utils.getDataWithPercent)(arcs, precision);
|
|
1082
1182
|
}, [arcs, precision]);
|
|
@@ -1086,18 +1186,54 @@ var Label = function Label(_ref10) {
|
|
|
1086
1186
|
d.percent = 0;
|
|
1087
1187
|
});
|
|
1088
1188
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1189
|
+
var isHorizontal = mode === "horizontal";
|
|
1190
|
+
var labelElsRef = (0, _react.useRef)({});
|
|
1191
|
+
var _useState7 = (0, _react.useState)({}),
|
|
1192
|
+
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
|
1193
|
+
measuredHeights = _useState8[0],
|
|
1194
|
+
setMeasuredHeights = _useState8[1];
|
|
1195
|
+
|
|
1196
|
+
// 上下布局:渲染后读取每个标签真实高度(仅在高度变化时更新,避免死循环)
|
|
1197
|
+
(0, _react.useLayoutEffect)(function () {
|
|
1198
|
+
if (isHorizontal) {
|
|
1199
|
+
setMeasuredHeights(function (prev) {
|
|
1200
|
+
return Object.keys(prev).length ? {} : prev;
|
|
1201
|
+
});
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
setMeasuredHeights(function (prev) {
|
|
1205
|
+
var next = {};
|
|
1206
|
+
var changed = false;
|
|
1207
|
+
Object.keys(labelElsRef.current).forEach(function (key) {
|
|
1208
|
+
var el = labelElsRef.current[key];
|
|
1209
|
+
if (!el) return;
|
|
1210
|
+
var h = Math.round(el.getBoundingClientRect().height);
|
|
1211
|
+
if (!h) return;
|
|
1212
|
+
next[key] = h;
|
|
1213
|
+
if (prev[key] !== h) changed = true;
|
|
1214
|
+
});
|
|
1215
|
+
var prevKeys = Object.keys(prev);
|
|
1216
|
+
var nextKeys = Object.keys(next);
|
|
1217
|
+
if (prevKeys.length !== nextKeys.length) changed = true;
|
|
1218
|
+
return changed ? next : prev;
|
|
1219
|
+
});
|
|
1220
|
+
}, [isHorizontal, _arcs, mode, showName, showValue, showPercent, showSuffix]);
|
|
1221
|
+
var placedYBySide = {
|
|
1222
|
+
left: [],
|
|
1223
|
+
right: []
|
|
1224
|
+
};
|
|
1225
|
+
return /*#__PURE__*/_react["default"].createElement("g", null, _arcs.map(function (_ref20, index) {
|
|
1226
|
+
var _ref20$series$color = _ref20.series.color,
|
|
1227
|
+
type = _ref20$series$color.type,
|
|
1228
|
+
pure = _ref20$series$color.pure,
|
|
1229
|
+
stops = _ref20$series$color.linear.stops,
|
|
1230
|
+
data = _ref20.data,
|
|
1231
|
+
displayName = _ref20.displayName,
|
|
1232
|
+
value = _ref20.value,
|
|
1233
|
+
percent = _ref20.percent,
|
|
1234
|
+
arc = _ref20.arc,
|
|
1235
|
+
outerRadius = _ref20.outerRadius,
|
|
1236
|
+
actualIndex = _ref20.index;
|
|
1101
1237
|
var _arc$centroid = arc.centroid(),
|
|
1102
1238
|
_arc$centroid2 = (0, _slicedToArray2["default"])(_arc$centroid, 2),
|
|
1103
1239
|
x = _arc$centroid2[0],
|
|
@@ -1118,30 +1254,48 @@ var Label = function Label(_ref10) {
|
|
|
1118
1254
|
var _showName = showName && displayName;
|
|
1119
1255
|
var _showValue = showValue && (value || showSuffix);
|
|
1120
1256
|
var nameStyle = (0, _utils.getFontStyle)(nameFont);
|
|
1121
|
-
|
|
1257
|
+
var shouldShow = show && (_showName || showPercent || showValue);
|
|
1258
|
+
// 与真实渲染一致:showValue 开启时值为 0 也会渲染
|
|
1259
|
+
var labelSizeOptions = {
|
|
1260
|
+
showName: _showName,
|
|
1261
|
+
showValue: showValue,
|
|
1262
|
+
showPercent: showPercent,
|
|
1263
|
+
nameFont: nameFont,
|
|
1264
|
+
valueFont: valueFont,
|
|
1265
|
+
percentFont: percentFont
|
|
1266
|
+
};
|
|
1267
|
+
var estimatedHeight = isHorizontal ? getLabelRowHeight(labelSizeOptions) : getLabelColumnHeight(labelSizeOptions);
|
|
1268
|
+
// 上下布局优先用 DOM 实测高度
|
|
1269
|
+
var labelHeight = !isHorizontal && measuredHeights[index] != null ? measuredHeights[index] : estimatedHeight;
|
|
1270
|
+
var side = x2 < 0 ? "left" : "right";
|
|
1271
|
+
var finalY = shouldShow ? isHorizontal ? resolveLabelY(y2, side, placedYBySide, labelHeight) : resolveLabelYVertical(y2, side, placedYBySide, labelHeight) : y2;
|
|
1272
|
+
return shouldShow && /*#__PURE__*/_react["default"].createElement("g", {
|
|
1122
1273
|
key: index
|
|
1123
1274
|
}, /*#__PURE__*/_react["default"].createElement("path", {
|
|
1124
1275
|
className: animation ? _piechartModule["default"]["label-line"] : "",
|
|
1125
1276
|
style: {
|
|
1126
1277
|
animationDelay: "".concat(animation ? (actualIndex + 1) * ringDuration - labelDuration : 0, "ms")
|
|
1127
1278
|
},
|
|
1128
|
-
d: "M" + x1 + ", " + y1 + "L" + x2 + ", " +
|
|
1279
|
+
d: "M" + x1 + ", " + y1 + "L" + x2 + ", " + finalY + "L" + x3 + ", " + finalY,
|
|
1129
1280
|
stroke: lineColor ? lineColor : type == "pure" ? pure : stops[0].color,
|
|
1130
1281
|
fill: "none"
|
|
1131
1282
|
}), /*#__PURE__*/_react["default"].createElement("foreignObject", {
|
|
1132
1283
|
width: "1",
|
|
1133
1284
|
height: "1",
|
|
1134
1285
|
x: _x,
|
|
1135
|
-
y:
|
|
1286
|
+
y: finalY + translateY,
|
|
1136
1287
|
style: {
|
|
1137
1288
|
overflow: "visible",
|
|
1138
1289
|
position: "relative"
|
|
1139
1290
|
}
|
|
1140
1291
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
1292
|
+
ref: function ref(el) {
|
|
1293
|
+
if (el) labelElsRef.current[index] = el;else delete labelElsRef.current[index];
|
|
1294
|
+
},
|
|
1141
1295
|
className: animation ? _piechartModule["default"]["label-text"] : "",
|
|
1142
1296
|
style: {
|
|
1143
1297
|
position: isIOS ? "absolute" : "relative",
|
|
1144
|
-
transform: isIOS ? "translate(calc(".concat(x3 < 0 ? "-100%" : "0px", " + ").concat(left + _x, "px),calc(-50% + ").concat(top +
|
|
1298
|
+
transform: isIOS ? "translate(calc(".concat(x3 < 0 ? "-100%" : "0px", " + ").concat(left + _x, "px),calc(-50% + ").concat(top + finalY + translateY, "px))") : "translate(0,-50%)",
|
|
1145
1299
|
whiteSpace: "nowrap",
|
|
1146
1300
|
"float": x3 >= 0 ? "left" : "right",
|
|
1147
1301
|
width: "max-content",
|
|
@@ -1190,53 +1344,53 @@ function getTranslate(translate, reverse) {
|
|
|
1190
1344
|
y = translate.y;
|
|
1191
1345
|
return "translate(".concat(reverse ? -x : x, "px, ").concat(y, "px)");
|
|
1192
1346
|
}
|
|
1193
|
-
var RingLabel = function RingLabel(
|
|
1194
|
-
var
|
|
1195
|
-
ringDuration =
|
|
1196
|
-
labelDuration =
|
|
1197
|
-
|
|
1198
|
-
maxRadius =
|
|
1199
|
-
lineLength =
|
|
1200
|
-
lineColor =
|
|
1201
|
-
distance =
|
|
1202
|
-
mode =
|
|
1203
|
-
|
|
1204
|
-
align =
|
|
1205
|
-
show =
|
|
1206
|
-
|
|
1207
|
-
translateX =
|
|
1208
|
-
translateY =
|
|
1209
|
-
|
|
1210
|
-
showName =
|
|
1211
|
-
nameFont =
|
|
1212
|
-
maxWidth =
|
|
1213
|
-
textOverflow =
|
|
1214
|
-
speed =
|
|
1215
|
-
nameTranslate =
|
|
1216
|
-
|
|
1217
|
-
showValue =
|
|
1218
|
-
valueFont =
|
|
1219
|
-
valueSameColor =
|
|
1220
|
-
|
|
1221
|
-
showSuffix =
|
|
1222
|
-
text =
|
|
1223
|
-
suffixFontSize =
|
|
1224
|
-
|
|
1225
|
-
suffixTranslateX =
|
|
1226
|
-
suffixTranslateY =
|
|
1227
|
-
valueTranslate =
|
|
1228
|
-
|
|
1229
|
-
showPercent =
|
|
1230
|
-
percentSameColor =
|
|
1231
|
-
percentFont =
|
|
1232
|
-
precision =
|
|
1233
|
-
percentTranslate =
|
|
1234
|
-
|
|
1235
|
-
isIOS =
|
|
1236
|
-
left =
|
|
1237
|
-
top =
|
|
1238
|
-
judge =
|
|
1239
|
-
arcs =
|
|
1347
|
+
var RingLabel = function RingLabel(_ref21) {
|
|
1348
|
+
var _ref21$config = _ref21.config,
|
|
1349
|
+
ringDuration = _ref21$config.ringDuration,
|
|
1350
|
+
labelDuration = _ref21$config.labelDuration,
|
|
1351
|
+
_ref21$config$maxRadi = _ref21$config.maxRadius,
|
|
1352
|
+
maxRadius = _ref21$config$maxRadi === void 0 ? 0 : _ref21$config$maxRadi,
|
|
1353
|
+
lineLength = _ref21$config.lineLength,
|
|
1354
|
+
lineColor = _ref21$config.lineColor,
|
|
1355
|
+
distance = _ref21$config.distance,
|
|
1356
|
+
mode = _ref21$config.mode,
|
|
1357
|
+
_ref21$config$align = _ref21$config.align,
|
|
1358
|
+
align = _ref21$config$align === void 0 ? "center" : _ref21$config$align,
|
|
1359
|
+
show = _ref21$config.show,
|
|
1360
|
+
_ref21$config$transla = _ref21$config.translate,
|
|
1361
|
+
translateX = _ref21$config$transla.x,
|
|
1362
|
+
translateY = _ref21$config$transla.y,
|
|
1363
|
+
_ref21$config$name = _ref21$config.name,
|
|
1364
|
+
showName = _ref21$config$name.show,
|
|
1365
|
+
nameFont = _ref21$config$name.font,
|
|
1366
|
+
maxWidth = _ref21$config$name.maxWidth,
|
|
1367
|
+
textOverflow = _ref21$config$name.textOverflow,
|
|
1368
|
+
speed = _ref21$config$name.speed,
|
|
1369
|
+
nameTranslate = _ref21$config$name.translate,
|
|
1370
|
+
_ref21$config$value = _ref21$config.value,
|
|
1371
|
+
showValue = _ref21$config$value.show,
|
|
1372
|
+
valueFont = _ref21$config$value.font,
|
|
1373
|
+
valueSameColor = _ref21$config$value.sameColor,
|
|
1374
|
+
_ref21$config$value$s = _ref21$config$value.suffix,
|
|
1375
|
+
showSuffix = _ref21$config$value$s.show,
|
|
1376
|
+
text = _ref21$config$value$s.text,
|
|
1377
|
+
suffixFontSize = _ref21$config$value$s.fontSize,
|
|
1378
|
+
_ref21$config$value$s2 = _ref21$config$value$s.translate,
|
|
1379
|
+
suffixTranslateX = _ref21$config$value$s2.x,
|
|
1380
|
+
suffixTranslateY = _ref21$config$value$s2.y,
|
|
1381
|
+
valueTranslate = _ref21$config$value.translate,
|
|
1382
|
+
_ref21$config$percent = _ref21$config.percent,
|
|
1383
|
+
showPercent = _ref21$config$percent.show,
|
|
1384
|
+
percentSameColor = _ref21$config$percent.sameColor,
|
|
1385
|
+
percentFont = _ref21$config$percent.font,
|
|
1386
|
+
precision = _ref21$config$percent.precision,
|
|
1387
|
+
percentTranslate = _ref21$config$percent.translate,
|
|
1388
|
+
_ref21$iosStyle = _ref21.iosStyle,
|
|
1389
|
+
isIOS = _ref21$iosStyle.isIOS,
|
|
1390
|
+
left = _ref21$iosStyle.left,
|
|
1391
|
+
top = _ref21$iosStyle.top,
|
|
1392
|
+
judge = _ref21.judge,
|
|
1393
|
+
arcs = _ref21.arcs;
|
|
1240
1394
|
var _arcs = (0, _react.useMemo)(function () {
|
|
1241
1395
|
return (0, _utils.getDataWithPercent)(arcs, precision);
|
|
1242
1396
|
}, [arcs, precision]);
|
|
@@ -1247,18 +1401,54 @@ var RingLabel = function RingLabel(_ref12) {
|
|
|
1247
1401
|
d.percent = 0;
|
|
1248
1402
|
});
|
|
1249
1403
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1404
|
+
var isHorizontal = mode === "horizontal";
|
|
1405
|
+
var labelElsRef = (0, _react.useRef)({});
|
|
1406
|
+
var _useState9 = (0, _react.useState)({}),
|
|
1407
|
+
_useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
|
|
1408
|
+
measuredHeights = _useState10[0],
|
|
1409
|
+
setMeasuredHeights = _useState10[1];
|
|
1410
|
+
|
|
1411
|
+
// 上下布局:渲染后读取每个标签真实高度(仅在高度变化时更新,避免死循环)
|
|
1412
|
+
(0, _react.useLayoutEffect)(function () {
|
|
1413
|
+
if (isHorizontal) {
|
|
1414
|
+
setMeasuredHeights(function (prev) {
|
|
1415
|
+
return Object.keys(prev).length ? {} : prev;
|
|
1416
|
+
});
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
setMeasuredHeights(function (prev) {
|
|
1420
|
+
var next = {};
|
|
1421
|
+
var changed = false;
|
|
1422
|
+
Object.keys(labelElsRef.current).forEach(function (key) {
|
|
1423
|
+
var el = labelElsRef.current[key];
|
|
1424
|
+
if (!el) return;
|
|
1425
|
+
var h = Math.round(el.getBoundingClientRect().height);
|
|
1426
|
+
if (!h) return;
|
|
1427
|
+
next[key] = h;
|
|
1428
|
+
if (prev[key] !== h) changed = true;
|
|
1429
|
+
});
|
|
1430
|
+
var prevKeys = Object.keys(prev);
|
|
1431
|
+
var nextKeys = Object.keys(next);
|
|
1432
|
+
if (prevKeys.length !== nextKeys.length) changed = true;
|
|
1433
|
+
return changed ? next : prev;
|
|
1434
|
+
});
|
|
1435
|
+
}, [isHorizontal, _arcs, mode, showName, showValue, showPercent, showSuffix]);
|
|
1436
|
+
var placedYBySide = {
|
|
1437
|
+
left: [],
|
|
1438
|
+
right: []
|
|
1439
|
+
};
|
|
1440
|
+
return /*#__PURE__*/_react["default"].createElement("g", null, _arcs.map(function (_ref22, index) {
|
|
1441
|
+
var _ref22$series$color = _ref22.series.color,
|
|
1442
|
+
type = _ref22$series$color.type,
|
|
1443
|
+
pure = _ref22$series$color.pure,
|
|
1444
|
+
stops = _ref22$series$color.linear.stops,
|
|
1445
|
+
realData = _ref22.data,
|
|
1446
|
+
displayName = _ref22.displayName,
|
|
1447
|
+
value = _ref22.value,
|
|
1448
|
+
percent = _ref22.percent,
|
|
1449
|
+
arc = _ref22.arc,
|
|
1450
|
+
outerRadius = _ref22.outerRadius,
|
|
1451
|
+
actualIndex = _ref22.index;
|
|
1262
1452
|
var _arc$centroid3 = arc.centroid(),
|
|
1263
1453
|
_arc$centroid4 = (0, _slicedToArray2["default"])(_arc$centroid3, 2),
|
|
1264
1454
|
x = _arc$centroid4[0],
|
|
@@ -1274,35 +1464,52 @@ var RingLabel = function RingLabel(_ref12) {
|
|
|
1274
1464
|
x2 = _getCoord8[0],
|
|
1275
1465
|
y2 = _getCoord8[1];
|
|
1276
1466
|
var directionX = x2 < 0 ? -1 : 1;
|
|
1277
|
-
var directionY = y2 < 0 ? -1 : 1;
|
|
1278
1467
|
var x3 = x2 + lineLength * directionX;
|
|
1279
1468
|
var _x = x3 + (translateX + 6) * directionX;
|
|
1280
1469
|
var _showName = showName && displayName;
|
|
1281
1470
|
var _showValue = showValue && (value || showSuffix);
|
|
1282
|
-
|
|
1471
|
+
var shouldShow = show && (_showName || showPercent || _showValue);
|
|
1472
|
+
// 与真实渲染一致:showValue 开启时值为 0 也会渲染
|
|
1473
|
+
var labelSizeOptions = {
|
|
1474
|
+
showName: _showName,
|
|
1475
|
+
showValue: showValue,
|
|
1476
|
+
showPercent: showPercent,
|
|
1477
|
+
nameFont: nameFont,
|
|
1478
|
+
valueFont: valueFont,
|
|
1479
|
+
percentFont: percentFont
|
|
1480
|
+
};
|
|
1481
|
+
var estimatedHeight = isHorizontal ? getLabelRowHeight(labelSizeOptions) : getLabelColumnHeight(labelSizeOptions);
|
|
1482
|
+
// 上下布局优先用 DOM 实测高度
|
|
1483
|
+
var labelHeight = !isHorizontal && measuredHeights[index] != null ? measuredHeights[index] : estimatedHeight;
|
|
1484
|
+
var side = x2 < 0 ? "left" : "right";
|
|
1485
|
+
var finalY = shouldShow ? isHorizontal ? resolveLabelY(y2, side, placedYBySide, labelHeight) : resolveLabelYVertical(y2, side, placedYBySide, labelHeight) : y2;
|
|
1486
|
+
return shouldShow && /*#__PURE__*/_react["default"].createElement("g", {
|
|
1283
1487
|
key: index
|
|
1284
1488
|
}, /*#__PURE__*/_react["default"].createElement("path", {
|
|
1285
1489
|
className: _piechartModule["default"]["label-line"],
|
|
1286
1490
|
style: {
|
|
1287
1491
|
animationDelay: "".concat((actualIndex + 1) * ringDuration - labelDuration, "ms")
|
|
1288
1492
|
},
|
|
1289
|
-
d: "M" + x1 + ", " + y1 + "L" + x2 + ", " +
|
|
1493
|
+
d: "M" + x1 + ", " + y1 + "L" + x2 + ", " + finalY + "L" + x3 + ", " + finalY,
|
|
1290
1494
|
stroke: lineColor ? lineColor : type == "pure" ? pure : stops[0].color,
|
|
1291
1495
|
fill: "none"
|
|
1292
1496
|
}), /*#__PURE__*/_react["default"].createElement("foreignObject", {
|
|
1293
1497
|
width: "1",
|
|
1294
1498
|
height: "1",
|
|
1295
1499
|
x: _x,
|
|
1296
|
-
y:
|
|
1500
|
+
y: finalY + translateY,
|
|
1297
1501
|
style: {
|
|
1298
1502
|
overflow: "visible",
|
|
1299
1503
|
position: "relative"
|
|
1300
1504
|
}
|
|
1301
1505
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
1506
|
+
ref: function ref(el) {
|
|
1507
|
+
if (el) labelElsRef.current[index] = el;else delete labelElsRef.current[index];
|
|
1508
|
+
},
|
|
1302
1509
|
className: _piechartModule["default"]["label-text"],
|
|
1303
1510
|
style: {
|
|
1304
1511
|
position: isIOS ? "absolute" : "relative",
|
|
1305
|
-
transform: isIOS ? "translate(calc(".concat(x3 < 0 ? "-100%" : "0px", " + ").concat(left + _x, "px),calc(-50% + ").concat(top +
|
|
1512
|
+
transform: isIOS ? "translate(calc(".concat(x3 < 0 ? "-100%" : "0px", " + ").concat(left + _x, "px),calc(-50% + ").concat(top + finalY + translateY, "px))") : "translate(0,-50%)",
|
|
1306
1513
|
whiteSpace: "nowrap",
|
|
1307
1514
|
"float": x3 >= 0 ? "left" : "right",
|
|
1308
1515
|
width: "max-content",
|