@easyv/charts 1.10.28 → 1.10.29
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 +42 -21
- package/package.json +1 -1
- package/src/components/Legend.js +101 -84
package/lib/components/Legend.js
CHANGED
|
@@ -27,7 +27,7 @@ var defaultFont = {
|
|
|
27
27
|
fontWeight: "normal"
|
|
28
28
|
};
|
|
29
29
|
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
30
|
-
var _config$value, _config$percent, _config$value2, _config$value3, _config$name,
|
|
30
|
+
var _ref2, _config$value, _config$percent, _config$value2, _config$value3, _config$name, _ref4;
|
|
31
31
|
var series = _ref.series,
|
|
32
32
|
height = _ref.height,
|
|
33
33
|
data = _ref.data,
|
|
@@ -88,15 +88,30 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
88
88
|
var _useState = (0, _react.useState)(0),
|
|
89
89
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
90
90
|
scrollStep = _useState2[0],
|
|
91
|
-
setScrollStep = _useState2[1]; //
|
|
91
|
+
setScrollStep = _useState2[1]; // 每次滚动距离
|
|
92
|
+
var _useState3 = (0, _react.useState)(null),
|
|
93
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
94
|
+
loopContainerHeight = _useState4[0],
|
|
95
|
+
setLoopContainerHeight = _useState4[1]; // 按父高度推算的 loop 视口高度
|
|
92
96
|
|
|
93
|
-
//
|
|
97
|
+
// 根据父级 height 计算可见项数,视口高度 = N*行高 + (N-1)*间距(最后一项下方不留空)
|
|
94
98
|
(0, _react.useEffect)(function () {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
var _series$length;
|
|
100
|
+
if (!ref_container.current) return;
|
|
101
|
+
var li = ref_container.current.querySelector("li");
|
|
102
|
+
if (!li) return;
|
|
103
|
+
var itemHeight = li.offsetHeight;
|
|
104
|
+
var step = itemHeight + gridRowGap;
|
|
105
|
+
setScrollStep(step);
|
|
106
|
+
if (!loop.show || !height) {
|
|
107
|
+
setLoopContainerHeight(null);
|
|
108
|
+
return;
|
|
98
109
|
}
|
|
99
|
-
|
|
110
|
+
var totalItems = (_series$length = series === null || series === void 0 ? void 0 : series.length) !== null && _series$length !== void 0 ? _series$length : 0;
|
|
111
|
+
var visibleCount = Math.min(totalItems, Math.max(1, Math.floor((height + gridRowGap) / step)));
|
|
112
|
+
setLoopContainerHeight(visibleCount * itemHeight + Math.max(0, visibleCount - 1) * gridRowGap);
|
|
113
|
+
}, [gridRowGap, loop.show, series, height]);
|
|
114
|
+
var loopHeight = loop.show ? (_ref2 = loopContainerHeight !== null && loopContainerHeight !== void 0 ? loopContainerHeight : height) !== null && _ref2 !== void 0 ? _ref2 : "auto" : "auto";
|
|
100
115
|
|
|
101
116
|
// 启动自动滚动定时器
|
|
102
117
|
(0, _react.useEffect)(function () {
|
|
@@ -155,8 +170,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
155
170
|
var valueSuffix = ((_config$value2 = config.value) === null || _config$value2 === void 0 || (_config$value2 = _config$value2.suffix) === null || _config$value2 === void 0 ? void 0 : _config$value2.text) || "";
|
|
156
171
|
var valueSplitConfig = ((_config$value3 = config.value) === null || _config$value3 === void 0 ? void 0 : _config$value3.splitConfig) || {};
|
|
157
172
|
var getValueStr = function getValueStr(item) {
|
|
158
|
-
var
|
|
159
|
-
var valueStr = ((
|
|
173
|
+
var _ref3, _item$data$y, _item$data;
|
|
174
|
+
var valueStr = ((_ref3 = (_item$data$y = (_item$data = item.data) === null || _item$data === void 0 ? void 0 : _item$data.y) !== null && _item$data$y !== void 0 ? _item$data$y : item.value) !== null && _ref3 !== void 0 ? _ref3 : "") + (valueSuffix || "");
|
|
160
175
|
if (valueSplitConfig.show && valueSplitConfig.separator) {
|
|
161
176
|
valueStr = valueStr.toString().replace(/\B(?=(\d{3})+(?!\d))/g, valueSplitConfig.separator);
|
|
162
177
|
}
|
|
@@ -213,13 +228,15 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
213
228
|
var isFixedWidth = isPieChart ? isPieFixedWidthGrid : LegendType == "FixedWidth";
|
|
214
229
|
var isSideLegend = isPieAdaptive && isSidePlacement;
|
|
215
230
|
var isTopBottomAdaptive = isPieAdaptive && isCenterTopOrBottom;
|
|
216
|
-
var fullWidth = (
|
|
231
|
+
var fullWidth = (_ref4 = componentWidth !== null && componentWidth !== void 0 ? componentWidth : chartWidth) !== null && _ref4 !== void 0 ? _ref4 : 0;
|
|
217
232
|
// Adaptive+上下:组件总宽;Adaptive+左右:仅 maxWidth = 总宽 − 左右 chart.margin,宽度由内容撑开
|
|
218
233
|
var pieLegendFullWidth = Math.max(0, fullWidth);
|
|
219
234
|
var pieLegendInnerWidth = Math.max(0, fullWidth - marginLeft - marginRight);
|
|
220
235
|
var sideLegendMaxWidth = isSideLegend ? pieLegendInnerWidth : 0;
|
|
221
236
|
var fixedColumnsPerRow = Math.min(Math.max(1, Number(gridTemplateColumns) || 1), length);
|
|
222
237
|
var isPieTopBottomFixedMultiCol = isPieChart && isFixedWidth && isCenterTopOrBottom && fixedColumnsPerRow > 1;
|
|
238
|
+
var columnsPerRow = Math.max(1, Number(gridTemplateColumns) || 1);
|
|
239
|
+
var totalRows = Math.ceil(length / columnsPerRow);
|
|
223
240
|
var formatterExtra = _objectSpread(_objectSpread(_objectSpread({}, config), {}, {
|
|
224
241
|
valueMaxWidth: valueMaxWidth,
|
|
225
242
|
percentMaxWidth: percentMaxWidth,
|
|
@@ -284,13 +301,15 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
284
301
|
speed: speed
|
|
285
302
|
})));
|
|
286
303
|
};
|
|
304
|
+
var legendAlignContent = alignment.split(" ")[0] == "center" && (alignment.split(" ")[1] == "left" || alignment.split(" ")[1] == "right") ? alignment.split(" ")[1] == "left" ? "flex-start" : "flex-end" : alignment.split(" ")[0] == "left" ? "flex-start" : alignment.split(" ")[0] == "center" ? "center" : "flex-end";
|
|
287
305
|
var stylePieOrAxis = formatter ? _objectSpread(_objectSpread({
|
|
288
306
|
display: "flex",
|
|
289
|
-
alignContent:
|
|
307
|
+
alignContent: loop.show ? "flex-start" : legendAlignContent,
|
|
290
308
|
flexDirection: "column",
|
|
309
|
+
gap: loop.show ? "".concat(gridRowGap, "px") : undefined,
|
|
291
310
|
position: "absolute"
|
|
292
311
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
293
|
-
height:
|
|
312
|
+
height: loopHeight,
|
|
294
313
|
overflowY: loop.show ? "scroll" : "auto"
|
|
295
314
|
}) : _objectSpread(_objectSpread({
|
|
296
315
|
width: "100%",
|
|
@@ -298,20 +317,22 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
298
317
|
boxSizing: "border-box",
|
|
299
318
|
position: "absolute"
|
|
300
319
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
301
|
-
height:
|
|
320
|
+
height: loopHeight,
|
|
302
321
|
overflowY: loop.show ? "scroll" : "auto"
|
|
303
322
|
});
|
|
304
323
|
if (isPieAdaptive && isSideLegend) {
|
|
305
324
|
// 左右侧图例:水平方向始终左对齐,图标落在同一条纵线上(与九宫格水平分量无关)
|
|
306
|
-
var pieAdaptiveWrapperStyle = _objectSpread(_objectSpread({
|
|
325
|
+
var pieAdaptiveWrapperStyle = _objectSpread(_objectSpread(_objectSpread({
|
|
307
326
|
position: "absolute",
|
|
308
327
|
display: "flex",
|
|
309
328
|
flexDirection: "column",
|
|
310
329
|
width: "max-content",
|
|
311
330
|
maxWidth: sideLegendMaxWidth || undefined,
|
|
312
331
|
alignItems: "flex-start"
|
|
313
|
-
},
|
|
314
|
-
|
|
332
|
+
}, loop.show ? {
|
|
333
|
+
justifyContent: "flex-start"
|
|
334
|
+
} : {}), getPosition(position, _alignment, x, y)), {}, {
|
|
335
|
+
height: loopHeight,
|
|
315
336
|
overflowY: loop.show ? "scroll" : "auto"
|
|
316
337
|
});
|
|
317
338
|
var pieAdaptiveListStyle = {
|
|
@@ -342,7 +363,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
342
363
|
maxWidth: pieLegendFullWidth || "100%",
|
|
343
364
|
boxSizing: "border-box"
|
|
344
365
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
345
|
-
height:
|
|
366
|
+
height: loopHeight,
|
|
346
367
|
overflowY: loop.show ? "scroll" : "auto"
|
|
347
368
|
});
|
|
348
369
|
var topBottomListStyle = {
|
|
@@ -414,7 +435,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
414
435
|
position: "absolute",
|
|
415
436
|
display: "flex"
|
|
416
437
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
417
|
-
height:
|
|
438
|
+
height: loopHeight,
|
|
418
439
|
overflowY: loop.show ? "scroll" : "auto"
|
|
419
440
|
}),
|
|
420
441
|
ref: ref_container
|
|
@@ -473,7 +494,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
473
494
|
className: "__easyv-legend-wrapper",
|
|
474
495
|
style: stylePieOrAxis,
|
|
475
496
|
ref: ref_container
|
|
476
|
-
}, formatter ? (0, _toConsumableArray2["default"])(Array(
|
|
497
|
+
}, formatter ? (0, _toConsumableArray2["default"])(Array(totalRows)).map(function (_, indexs) {
|
|
477
498
|
return /*#__PURE__*/_react["default"].createElement("ul", {
|
|
478
499
|
key: indexs,
|
|
479
500
|
style: {
|
|
@@ -481,10 +502,10 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
481
502
|
width: "fit-content",
|
|
482
503
|
justifyContent: legendMainAlign,
|
|
483
504
|
gap: "".concat(gridRowGap, "px ").concat(gridColumnGap, "px"),
|
|
484
|
-
|
|
505
|
+
margin: 0
|
|
485
506
|
}
|
|
486
507
|
}, _series.map(function (series, i) {
|
|
487
|
-
if (Math.floor(i /
|
|
508
|
+
if (Math.floor(i / columnsPerRow) == indexs) {
|
|
488
509
|
var _series$config4;
|
|
489
510
|
var type = series.type,
|
|
490
511
|
name = series.name,
|
package/package.json
CHANGED
package/src/components/Legend.js
CHANGED
|
@@ -54,16 +54,34 @@ export default memo(
|
|
|
54
54
|
const ref_container = useRef(null); // 滚动容器
|
|
55
55
|
const ref_scrollTop = useRef(0); // 当前滚动距离
|
|
56
56
|
|
|
57
|
-
const [scrollStep, setScrollStep] = useState(0); //
|
|
57
|
+
const [scrollStep, setScrollStep] = useState(0); // 每次滚动距离
|
|
58
|
+
const [loopContainerHeight, setLoopContainerHeight] = useState(null); // 按父高度推算的 loop 视口高度
|
|
58
59
|
|
|
59
|
-
//
|
|
60
|
+
// 根据父级 height 计算可见项数,视口高度 = N*行高 + (N-1)*间距(最后一项下方不留空)
|
|
60
61
|
useEffect(() => {
|
|
61
|
-
if (ref_container.current)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
if (!ref_container.current) return;
|
|
63
|
+
const li = ref_container.current.querySelector("li");
|
|
64
|
+
if (!li) return;
|
|
65
|
+
const itemHeight = li.offsetHeight;
|
|
66
|
+
const step = itemHeight + gridRowGap;
|
|
67
|
+
setScrollStep(step);
|
|
68
|
+
if (!loop.show || !height) {
|
|
69
|
+
setLoopContainerHeight(null);
|
|
70
|
+
return;
|
|
65
71
|
}
|
|
66
|
-
|
|
72
|
+
const totalItems = series?.length ?? 0;
|
|
73
|
+
const visibleCount = Math.min(
|
|
74
|
+
totalItems,
|
|
75
|
+
Math.max(1, Math.floor((height + gridRowGap) / step)),
|
|
76
|
+
);
|
|
77
|
+
setLoopContainerHeight(
|
|
78
|
+
visibleCount * itemHeight + Math.max(0, visibleCount - 1) * gridRowGap,
|
|
79
|
+
);
|
|
80
|
+
}, [gridRowGap, loop.show, series, height]);
|
|
81
|
+
|
|
82
|
+
const loopHeight = loop.show
|
|
83
|
+
? (loopContainerHeight ?? height ?? "auto")
|
|
84
|
+
: "auto";
|
|
67
85
|
|
|
68
86
|
// 启动自动滚动定时器
|
|
69
87
|
useEffect(() => {
|
|
@@ -249,6 +267,9 @@ export default memo(
|
|
|
249
267
|
isCenterTopOrBottom &&
|
|
250
268
|
fixedColumnsPerRow > 1;
|
|
251
269
|
|
|
270
|
+
const columnsPerRow = Math.max(1, Number(gridTemplateColumns) || 1);
|
|
271
|
+
const totalRows = Math.ceil(length / columnsPerRow);
|
|
272
|
+
|
|
252
273
|
const formatterExtra = {
|
|
253
274
|
...config,
|
|
254
275
|
valueMaxWidth,
|
|
@@ -330,25 +351,26 @@ export default memo(
|
|
|
330
351
|
);
|
|
331
352
|
};
|
|
332
353
|
|
|
354
|
+
const legendAlignContent =
|
|
355
|
+
alignment.split(" ")[0] == "center" &&
|
|
356
|
+
(alignment.split(" ")[1] == "left" || alignment.split(" ")[1] == "right")
|
|
357
|
+
? alignment.split(" ")[1] == "left"
|
|
358
|
+
? "flex-start"
|
|
359
|
+
: "flex-end"
|
|
360
|
+
: alignment.split(" ")[0] == "left"
|
|
361
|
+
? "flex-start"
|
|
362
|
+
: alignment.split(" ")[0] == "center"
|
|
363
|
+
? "center"
|
|
364
|
+
: "flex-end";
|
|
333
365
|
const stylePieOrAxis = formatter
|
|
334
366
|
? {
|
|
335
367
|
display: "flex",
|
|
336
|
-
alignContent:
|
|
337
|
-
alignment.split(" ")[0] == "center" &&
|
|
338
|
-
(alignment.split(" ")[1] == "left" ||
|
|
339
|
-
alignment.split(" ")[1] == "right")
|
|
340
|
-
? alignment.split(" ")[1] == "left"
|
|
341
|
-
? "flex-start"
|
|
342
|
-
: "flex-end"
|
|
343
|
-
: alignment.split(" ")[0] == "left"
|
|
344
|
-
? "flex-start"
|
|
345
|
-
: alignment.split(" ")[0] == "center"
|
|
346
|
-
? "center"
|
|
347
|
-
: "flex-end",
|
|
368
|
+
alignContent: loop.show ? "flex-start" : legendAlignContent,
|
|
348
369
|
flexDirection: "column",
|
|
370
|
+
gap: loop.show ? `${gridRowGap}px` : undefined,
|
|
349
371
|
position: "absolute",
|
|
350
372
|
...getPosition(position, _alignment, x, y),
|
|
351
|
-
height:
|
|
373
|
+
height: loopHeight,
|
|
352
374
|
overflowY: loop.show ? "scroll" : "auto",
|
|
353
375
|
}
|
|
354
376
|
: {
|
|
@@ -357,7 +379,7 @@ export default memo(
|
|
|
357
379
|
boxSizing: "border-box",
|
|
358
380
|
position: "absolute",
|
|
359
381
|
...getPosition(position, _alignment, x, y),
|
|
360
|
-
height:
|
|
382
|
+
height: loopHeight,
|
|
361
383
|
overflowY: loop.show ? "scroll" : "auto",
|
|
362
384
|
};
|
|
363
385
|
if (isPieAdaptive && isSideLegend) {
|
|
@@ -369,8 +391,9 @@ export default memo(
|
|
|
369
391
|
width: "max-content",
|
|
370
392
|
maxWidth: sideLegendMaxWidth || undefined,
|
|
371
393
|
alignItems: "flex-start",
|
|
394
|
+
...(loop.show ? { justifyContent: "flex-start" } : {}),
|
|
372
395
|
...getPosition(position, _alignment, x, y),
|
|
373
|
-
height:
|
|
396
|
+
height: loopHeight,
|
|
374
397
|
overflowY: loop.show ? "scroll" : "auto",
|
|
375
398
|
};
|
|
376
399
|
const pieAdaptiveListStyle = {
|
|
@@ -404,7 +427,7 @@ export default memo(
|
|
|
404
427
|
maxWidth: pieLegendFullWidth || "100%",
|
|
405
428
|
boxSizing: "border-box",
|
|
406
429
|
...getPosition(position, _alignment, x, y),
|
|
407
|
-
height:
|
|
430
|
+
height: loopHeight,
|
|
408
431
|
overflowY: loop.show ? "scroll" : "auto",
|
|
409
432
|
};
|
|
410
433
|
const topBottomListStyle = {
|
|
@@ -491,7 +514,7 @@ export default memo(
|
|
|
491
514
|
position: "absolute",
|
|
492
515
|
display: "flex",
|
|
493
516
|
...getPosition(position, _alignment, x, y),
|
|
494
|
-
height:
|
|
517
|
+
height: loopHeight,
|
|
495
518
|
overflowY: loop.show ? "scroll" : "auto",
|
|
496
519
|
}}
|
|
497
520
|
ref={ref_container}
|
|
@@ -577,66 +600,60 @@ export default memo(
|
|
|
577
600
|
ref={ref_container}
|
|
578
601
|
>
|
|
579
602
|
{formatter ? (
|
|
580
|
-
[...Array(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
);
|
|
635
|
-
}
|
|
636
|
-
})}
|
|
637
|
-
</ul>
|
|
638
|
-
),
|
|
639
|
-
)
|
|
603
|
+
[...Array(totalRows)].map((_, indexs) => (
|
|
604
|
+
<ul
|
|
605
|
+
key={indexs}
|
|
606
|
+
style={{
|
|
607
|
+
display: "flex",
|
|
608
|
+
width: "fit-content",
|
|
609
|
+
justifyContent: legendMainAlign,
|
|
610
|
+
gap: `${gridRowGap}px ${gridColumnGap}px`,
|
|
611
|
+
margin: 0,
|
|
612
|
+
}}
|
|
613
|
+
>
|
|
614
|
+
{_series.map((series, i) => {
|
|
615
|
+
if (Math.floor(i / columnsPerRow) == indexs) {
|
|
616
|
+
const {
|
|
617
|
+
type,
|
|
618
|
+
name,
|
|
619
|
+
displayName,
|
|
620
|
+
fieldName,
|
|
621
|
+
icon,
|
|
622
|
+
selected,
|
|
623
|
+
index,
|
|
624
|
+
} = series;
|
|
625
|
+
const _icon = getIcon(type, icon, series?.config?.line?.type);
|
|
626
|
+
return (
|
|
627
|
+
<li
|
|
628
|
+
key={i}
|
|
629
|
+
onClick={onClick(fieldName)}
|
|
630
|
+
data-name={displayName || name}
|
|
631
|
+
data-index={index}
|
|
632
|
+
style={{
|
|
633
|
+
display: "flex",
|
|
634
|
+
opacity: selected === false ? opacity / 100 : 1,
|
|
635
|
+
alignItems: "center",
|
|
636
|
+
cursor: "pointer",
|
|
637
|
+
gap: _icon.gap,
|
|
638
|
+
overflow: "visible",
|
|
639
|
+
}}
|
|
640
|
+
>
|
|
641
|
+
{formatter(series, {
|
|
642
|
+
...config,
|
|
643
|
+
valueMaxWidth,
|
|
644
|
+
percentMaxWidth,
|
|
645
|
+
nameMaxWidth,
|
|
646
|
+
otherData: data,
|
|
647
|
+
columnsSeries,
|
|
648
|
+
fieldColumnKeys,
|
|
649
|
+
fieldsColumnWidths,
|
|
650
|
+
})}
|
|
651
|
+
</li>
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
})}
|
|
655
|
+
</ul>
|
|
656
|
+
))
|
|
640
657
|
) : (
|
|
641
658
|
<ul
|
|
642
659
|
style={{
|