@easyv/charts 1.10.27 → 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.
@@ -259,16 +259,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
259
259
  triggerEvents ? triggerEvents(e, "setCurrent") : "";
260
260
  },
261
261
  onMouseMove: function onMouseMove(e) {
262
- var _e$currentTarget, _ref7, _e$pageX, _e$nativeEvent, _ref8, _e$pageY, _e$nativeEvent2;
263
- if (!triggerEvents) return;
264
- e.stopPropagation();
265
- var data = (_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 || (_e$currentTarget = _e$currentTarget.dataset) === null || _e$currentTarget === void 0 ? void 0 : _e$currentTarget.data;
266
- if (!data) return;
267
- handleMouseMove({
268
- data: data,
269
- pageX: (_ref7 = (_e$pageX = e.pageX) !== null && _e$pageX !== void 0 ? _e$pageX : (_e$nativeEvent = e.nativeEvent) === null || _e$nativeEvent === void 0 ? void 0 : _e$nativeEvent.pageX) !== null && _ref7 !== void 0 ? _ref7 : 0,
270
- pageY: (_ref8 = (_e$pageY = e.pageY) !== null && _e$pageY !== void 0 ? _e$pageY : (_e$nativeEvent2 = e.nativeEvent) === null || _e$nativeEvent2 === void 0 ? void 0 : _e$nativeEvent2.pageY) !== null && _ref8 !== void 0 ? _ref8 : 0
271
- });
262
+ triggerEvents ? handleMouseMove : "";
272
263
  },
273
264
  onMouseEnter: function onMouseEnter(e) {
274
265
  triggerEvents ? triggerEvents(e, "mouseenter") : "";
@@ -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, _ref3;
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
- if (ref_container.current) {
96
- var rowHeight = ref_container.current.querySelector("li").clientHeight + gridRowGap;
97
- setScrollStep(rowHeight);
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
- }, [gridRowGap]);
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 _ref2, _item$data$y, _item$data;
159
- var valueStr = ((_ref2 = (_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 && _ref2 !== void 0 ? _ref2 : "") + (valueSuffix || "");
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 = (_ref3 = componentWidth !== null && componentWidth !== void 0 ? componentWidth : chartWidth) !== null && _ref3 !== void 0 ? _ref3 : 0;
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: 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",
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: loop.show ? height : "auto",
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: loop.show ? height : "auto",
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
- }, getPosition(position, _alignment, x, y)), {}, {
314
- height: loop.show ? height : "auto",
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: loop.show ? height : "auto",
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: loop.show ? height : "auto",
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(Math.ceil(series.length / gridTemplateColumns))).map(function (_, indexs) {
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
- marginBottom: gridRowGap + "px"
505
+ margin: 0
485
506
  }
486
507
  }, _series.map(function (series, i) {
487
- if (Math.floor(i / gridTemplateColumns) == indexs) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.10.27",
3
+ "version": "1.10.29",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -259,15 +259,7 @@ export default memo(
259
259
  triggerEvents ? triggerEvents(e, "setCurrent") : "";
260
260
  }}
261
261
  onMouseMove={(e) => {
262
- if (!triggerEvents) return;
263
- e.stopPropagation();
264
- const data = e.currentTarget?.dataset?.data;
265
- if (!data) return;
266
- handleMouseMove({
267
- data,
268
- pageX: e.pageX ?? e.nativeEvent?.pageX ?? 0,
269
- pageY: e.pageY ?? e.nativeEvent?.pageY ?? 0,
270
- });
262
+ triggerEvents ? handleMouseMove : "";
271
263
  }}
272
264
  onMouseEnter={(e) => {
273
265
  triggerEvents ? triggerEvents(e, "mouseenter") : "";
@@ -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
- const rowHeight =
63
- ref_container.current.querySelector("li").clientHeight + gridRowGap;
64
- setScrollStep(rowHeight);
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
- }, [gridRowGap]);
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: loop.show ? height : "auto",
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: loop.show ? height : "auto",
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: loop.show ? height : "auto",
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: loop.show ? height : "auto",
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: loop.show ? height : "auto",
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(Math.ceil(series.length / gridTemplateColumns))].map(
581
- (_, indexs) => (
582
- <ul
583
- key={indexs}
584
- style={{
585
- display: "flex",
586
- width: "fit-content",
587
- justifyContent: legendMainAlign,
588
- gap: `${gridRowGap}px ${gridColumnGap}px`,
589
- marginBottom: gridRowGap + "px",
590
- }}
591
- >
592
- {_series.map((series, i) => {
593
- if (Math.floor(i / gridTemplateColumns) == indexs) {
594
- const {
595
- type,
596
- name,
597
- displayName,
598
- fieldName,
599
- icon,
600
- selected,
601
- index,
602
- } = series;
603
- const _icon = getIcon(
604
- type,
605
- icon,
606
- series?.config?.line?.type,
607
- );
608
- return (
609
- <li
610
- key={i}
611
- onClick={onClick(fieldName)}
612
- data-name={displayName || name}
613
- data-index={index}
614
- style={{
615
- display: "flex",
616
- opacity: selected === false ? opacity / 100 : 1,
617
- alignItems: "center",
618
- cursor: "pointer",
619
- gap: _icon.gap,
620
- overflow: "visible",
621
- }}
622
- >
623
- {formatter(series, {
624
- ...config,
625
- valueMaxWidth,
626
- percentMaxWidth,
627
- nameMaxWidth,
628
- otherData: data,
629
- columnsSeries,
630
- fieldColumnKeys,
631
- fieldsColumnWidths,
632
- })}
633
- </li>
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={{