@easyv/charts 1.8.3 → 1.8.4

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.
@@ -92,6 +92,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
92
92
  _ref3$isControlChart = _ref3.isControlChart,
93
93
  isControlChart = _ref3$isControlChart === void 0 ? false : _ref3$isControlChart,
94
94
  setCtlTip = _ref3.setCtlTip,
95
+ isXRepeat = _ref3.isXRepeat,
95
96
  _ref3$config = _ref3.config,
96
97
  _ref3$config$pattern = _ref3$config.pattern,
97
98
  pattern = _ref3$config$pattern === void 0 ? {} : _ref3$config$pattern,
@@ -197,7 +198,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
197
198
  borderWidth = _ref6$borderWidth === void 0 ? 0 : _ref6$borderWidth;
198
199
  var borderStr = "".concat(pure, " solid ").concat(borderWidth, "px");
199
200
  var borderImageSource = (0, _utils.getMultiColorStr)(linear);
200
- var positionX = _data.length == 1 ? xScaler(x) - seriesStart / 2 : xScaler(x) - step / 2 + seriesStart + index * seriesStep;
201
+ var positionX = isXRepeat ? xScaler(x) - step / 2 + seriesStart + index * seriesStep : xScaler(x) - seriesStart / 2;
201
202
  var showHead, headType, headUrl, headVideo, headWidth, headHeight, headTranslate;
202
203
  if (headDecorate) {
203
204
  showHead = headDecorate.show, headType = headDecorate.type, headUrl = headDecorate.url, headVideo = headDecorate.video, headWidth = headDecorate.size.width, headHeight = headDecorate.size.height, headTranslate = headDecorate.translate;
@@ -19,6 +19,9 @@ var _excluded = ["Component", "yOrZ"],
19
19
  _excluded2 = ["Component", "yOrZ"];
20
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
21
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
22
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
23
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
24
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
22
25
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
23
26
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
24
27
  * 轴类图表
@@ -426,6 +429,30 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
426
429
  });
427
430
  var bodyWidth = isVertical ? xLineRange + 100 + marginRight + marginLeft : xLineRange,
428
431
  bodyHeight = isVertical ? yLineRange : yLineRange + marginTop + marginBottom;
432
+ var hasDuplicateX = function hasDuplicateX(data) {
433
+ var xValues = new Set(); // 用Set存储已出现的x值,自动去重
434
+ var _iterator = _createForOfIteratorHelper(data),
435
+ _step;
436
+ try {
437
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
438
+ var item = _step.value;
439
+ // 跳过空数据项(如示例中第三个data为空的对象)
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);
447
+ }
448
+ // 遍历完所有项都无重复,返回false
449
+ } catch (err) {
450
+ _iterator.e(err);
451
+ } finally {
452
+ _iterator.f();
453
+ }
454
+ return false;
455
+ };
429
456
  (0, _react.useEffect)(function () {
430
457
  setCtlTip(function (pre) {
431
458
  return {
@@ -549,6 +576,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
549
576
  yOrZ = _ref2.yOrZ,
550
577
  config = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
551
578
  var yAxis = axes.get(yOrZ);
579
+ var isXRepeat = hasDuplicateX(series); //x项有重复项判断
552
580
  return yAxis && Component && /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({
553
581
  key: index
554
582
  }, config, {
@@ -563,7 +591,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
563
591
  isControlChart: !!control,
564
592
  indicatorWidth: indicatorWidth,
565
593
  triggerClick: onInteraction,
566
- setCtlTip: setCtlTip
594
+ setCtlTip: setCtlTip,
595
+ isXRepeat: isXRepeat
567
596
  }));
568
597
  }), series.map(function (_ref3, index) {
569
598
  var Component = _ref3.Component,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -87,6 +87,7 @@ export default memo(
87
87
  indicatorWidth,
88
88
  isControlChart = false,
89
89
  setCtlTip,
90
+ isXRepeat,
90
91
  config: {
91
92
  pattern = {},
92
93
  seriesIntervalWidth: paddingInner = 0,
@@ -164,8 +165,7 @@ export default memo(
164
165
  }, borderWidth=0 } = border || {};
165
166
  const borderStr = `${pure} solid ${borderWidth}px`;
166
167
  const borderImageSource = getMultiColorStr(linear);
167
- const positionX =_data.length==1? xScaler(x) -seriesStart/2 :xScaler(x) - step / 2 + seriesStart + index * seriesStep;
168
-
168
+ const positionX =isXRepeat? xScaler(x) - step / 2 + seriesStart + index * seriesStep: xScaler(x) -seriesStart/2;
169
169
  let showHead, headType, headUrl, headVideo, headWidth, headHeight, headTranslate;
170
170
  if (headDecorate) {
171
171
  (showHead = headDecorate.show),
@@ -399,7 +399,21 @@ const Chart = memo(
399
399
  const controlChartTooltipData = ctlXName && originData.filter((d) => d.x === ctlXName);
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值,自动去重
404
+ for (const item of data) {
405
+ // 跳过空数据项(如示例中第三个data为空的对象)
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);
413
+ }
414
+ // 遍历完所有项都无重复,返回false
415
+ return false;
416
+ };
403
417
  useEffect(()=>{
404
418
  setCtlTip(pre=>{
405
419
  return {
@@ -534,6 +548,7 @@ const Chart = memo(
534
548
  {/**绘制图表主体 */}
535
549
  {series.map(({ Component, yOrZ, ...config }, index) => {
536
550
  const yAxis = axes.get(yOrZ);
551
+ const isXRepeat=hasDuplicateX(series);//x项有重复项判断
537
552
  return (
538
553
  yAxis &&
539
554
  Component && (
@@ -551,6 +566,7 @@ const Chart = memo(
551
566
  indicatorWidth={indicatorWidth}
552
567
  triggerClick={onInteraction}
553
568
  setCtlTip={setCtlTip}
569
+ isXRepeat={isXRepeat}
554
570
  />
555
571
  )
556
572
  );