@easyv/charts 1.8.17 → 1.8.18

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.
@@ -430,22 +430,33 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
430
430
  var bodyWidth = isVertical ? xLineRange + 100 + marginRight + marginLeft : xLineRange,
431
431
  bodyHeight = isVertical ? yLineRange : yLineRange + marginTop + marginBottom;
432
432
  var hasDuplicateX = function hasDuplicateX(data) {
433
- var xValues = new Set(); // 用Set存储已出现的x值,自动去重
433
+ var xValues = new Set();
434
434
  var _iterator = _createForOfIteratorHelper(data),
435
435
  _step;
436
436
  try {
437
437
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
438
438
  var item = _step.value;
439
- // 跳过空数据项(如示例中第三个data为空的对象)
439
+ // 跳过空数据项
440
440
  if (!item.data || !item.data.length) continue;
441
- // 获取当前项的x值(从嵌套结构中提取)
442
- var x = item.data[0].data.x;
443
- // 若x已存在于Set中,说明有重复,直接返回true
444
- if (xValues.has(x)) return true;
445
- // 否则将x存入Set
446
- xValues.add(x);
441
+
442
+ // 关键修改:遍历当前item.data的所有项(不再只取第1项)
443
+ var _iterator2 = _createForOfIteratorHelper(item.data),
444
+ _step2;
445
+ try {
446
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
447
+ var subItem = _step2.value;
448
+ // 确保subItem有data和x属性(兜底防错)
449
+ if (!subItem.data || subItem.data.x === undefined) continue;
450
+ var x = subItem.data.x;
451
+ if (xValues.has(x)) return true; // 任意x重复就返回true
452
+ xValues.add(x);
453
+ }
454
+ } catch (err) {
455
+ _iterator2.e(err);
456
+ } finally {
457
+ _iterator2.f();
458
+ }
447
459
  }
448
- // 遍历完所有项都无重复,返回false
449
460
  } catch (err) {
450
461
  _iterator.e(err);
451
462
  } finally {
@@ -599,7 +610,9 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
599
610
  yOrZ = _ref3.yOrZ,
600
611
  config = (0, _objectWithoutProperties2["default"])(_ref3, _excluded2);
601
612
  var yAxis = axes.get(yOrZ);
613
+ var isXRepeat = hasDuplicateX(series); //x项有重复项判断
602
614
  return yAxis && /*#__PURE__*/_react["default"].createElement(_.Label, (0, _extends2["default"])({
615
+ isXRepeat: isXRepeat,
603
616
  key: index
604
617
  }, config, {
605
618
  curXLabel: curXLabel,
@@ -44,7 +44,8 @@ var getHighlightData = function getHighlightData(data, extent) {
44
44
  }
45
45
  };
46
46
  var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref) {
47
- var _ref$config = _ref.config,
47
+ var isXRepeat = _ref.isXRepeat,
48
+ _ref$config = _ref.config,
48
49
  _ref$config$seriesInt = _ref$config.seriesIntervalWidth,
49
50
  paddingInner = _ref$config$seriesInt === void 0 ? 0 : _ref$config$seriesInt,
50
51
  _ref$config$paddingIn = _ref$config.paddingInner,
@@ -155,7 +156,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
155
156
  // const y2 = yScaler(isVertical ? start : end);
156
157
  var positionX = xScaler(x) - step / 2 + seriesStart + index * seriesStep;
157
158
  if (isNaN(positionX)) return null;
158
- var position = positionX + (config.line ? step : seriesWidth) / 2;
159
+ var position = isXRepeat ? positionX + (config.line ? step : seriesWidth) / 2 : xScaler(x);
159
160
  var labelPosition = isVertical ? getVerticalLabel({
160
161
  position: _position,
161
162
  y: y,
@@ -606,7 +606,6 @@ var getSeriesInfo = exports.getSeriesInfo = function getSeriesInfo(_ref19) {
606
606
  return {
607
607
  seriesWidth: _step,
608
608
  seriesStep: (1 + paddingInner) * _step,
609
- // seriesStart: 0,
610
609
  seriesStart: paddingOuter * _step,
611
610
  width: step - paddingOuter * 2 * _step
612
611
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.8.17",
3
+ "version": "1.8.18",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -400,21 +400,23 @@ const Chart = memo(
400
400
  const bodyWidth = isVertical?xLineRange + 100 + marginRight + marginLeft:xLineRange,
401
401
  bodyHeight = isVertical?yLineRange:yLineRange + marginTop + marginBottom;
402
402
  const hasDuplicateX = (data) => {
403
- const xValues = new Set(); // 用Set存储已出现的x值,自动去重
403
+ const xValues = new Set();
404
404
  for (const item of data) {
405
- // 跳过空数据项(如示例中第三个data为空的对象)
405
+ // 跳过空数据项
406
406
  if (!item.data || !item.data.length) continue;
407
- // 获取当前项的x值(从嵌套结构中提取)
408
- const x = item.data[0].data.x;
409
- // 若x已存在于Set中,说明有重复,直接返回true
410
- if (xValues.has(x)) return true;
411
- // 否则将x存入Set
412
- xValues.add(x);
407
+
408
+ // 关键修改:遍历当前item.data的所有项(不再只取第1项)
409
+ for (const subItem of item.data) {
410
+ // 确保subItem有data和x属性(兜底防错)
411
+ if (!subItem.data || subItem.data.x === undefined) continue;
412
+ const x = subItem.data.x;
413
+ if (xValues.has(x)) return true; // 任意x重复就返回true
414
+ xValues.add(x);
415
+ }
413
416
  }
414
- // 遍历完所有项都无重复,返回false
415
417
  return false;
416
418
  };
417
- useEffect(()=>{
419
+ useEffect(()=>{
418
420
  setCtlTip(pre=>{
419
421
  return {
420
422
  show:!!tickName, x:tooltipX, xName:tickName,
@@ -574,9 +576,11 @@ const Chart = memo(
574
576
  {/* 图表数值标签 */}
575
577
  {series.map(({ Component, yOrZ, ...config }, index) => {
576
578
  const yAxis = axes.get(yOrZ);
579
+ const isXRepeat=hasDuplicateX(series);//x项有重复项判断
577
580
  return (
578
581
  yAxis && (
579
582
  <Label
583
+ isXRepeat={isXRepeat}
580
584
  key={index}
581
585
  {...config}
582
586
  curXLabel={curXLabel}
@@ -27,6 +27,7 @@ const getHighlightData = (data, extent) => {
27
27
 
28
28
  export default memo(
29
29
  ({
30
+ isXRepeat,
30
31
  config: {
31
32
  seriesIntervalWidth: paddingInner = 0,
32
33
  paddingInner: paddingOuter = 0,
@@ -107,7 +108,7 @@ export default memo(
107
108
  xScaler(x) - step / 2 + seriesStart + index * seriesStep;
108
109
 
109
110
  if (isNaN(positionX)) return null;
110
- const position = positionX + (config.line ? step : seriesWidth) / 2;
111
+ const position =isXRepeat?positionX + (config.line ? step : seriesWidth) / 2: xScaler(x);
111
112
  const labelPosition = isVertical
112
113
  ? getVerticalLabel({
113
114
  position: _position,
@@ -585,7 +585,6 @@ const getSeriesInfo = ({
585
585
  return {
586
586
  seriesWidth: _step,
587
587
  seriesStep: (1 + paddingInner) * _step,
588
- // seriesStart: 0,
589
588
  seriesStart: paddingOuter * _step,
590
589
  width: step - paddingOuter * 2 * _step,
591
590
  };