@easyv/charts 1.8.17 → 1.8.19
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/CartesianChart.js +22 -9
- package/lib/components/Label.js +3 -2
- package/lib/components/PieChart.js +11 -4
- package/lib/utils/index.js +0 -1
- package/package.json +1 -1
- package/src/components/CartesianChart.js +14 -10
- package/src/components/Label.js +2 -1
- package/src/components/PieChart.js +8 -2
- package/src/utils/index.js +0 -1
|
@@ -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();
|
|
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
|
-
//
|
|
439
|
+
// 跳过空数据项
|
|
440
440
|
if (!item.data || !item.data.length) continue;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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,
|
package/lib/components/Label.js
CHANGED
|
@@ -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
|
|
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,
|
|
@@ -936,6 +936,7 @@ var Label = function Label(_ref10) {
|
|
|
936
936
|
lineColor = _ref10$config.lineColor,
|
|
937
937
|
distance = _ref10$config.distance,
|
|
938
938
|
mode = _ref10$config.mode,
|
|
939
|
+
align = _ref10$config.align,
|
|
939
940
|
show = _ref10$config.show,
|
|
940
941
|
_ref10$config$transla = _ref10$config.translate,
|
|
941
942
|
translateX = _ref10$config$transla.x,
|
|
@@ -946,6 +947,7 @@ var Label = function Label(_ref10) {
|
|
|
946
947
|
maxWidth = _ref10$config$name.maxWidth,
|
|
947
948
|
textOverflow = _ref10$config$name.textOverflow,
|
|
948
949
|
speed = _ref10$config$name.speed,
|
|
950
|
+
NameTranslate = _ref10$config$name.translate,
|
|
949
951
|
_ref10$config$value = _ref10$config.value,
|
|
950
952
|
showValue = _ref10$config$value.show,
|
|
951
953
|
valueFont = _ref10$config$value.font,
|
|
@@ -957,11 +959,13 @@ var Label = function Label(_ref10) {
|
|
|
957
959
|
_ref10$config$value$s2 = _ref10$config$value$s.translate,
|
|
958
960
|
suffixTranslateX = _ref10$config$value$s2.x,
|
|
959
961
|
suffixTranslateY = _ref10$config$value$s2.y,
|
|
962
|
+
ValueTranslate = _ref10$config$value.translate,
|
|
960
963
|
_ref10$config$percent = _ref10$config.percent,
|
|
961
964
|
showPercent = _ref10$config$percent.show,
|
|
962
965
|
percentSameColor = _ref10$config$percent.sameColor,
|
|
963
966
|
percentFont = _ref10$config$percent.font,
|
|
964
967
|
precision = _ref10$config$percent.precision,
|
|
968
|
+
PercentTranslate = _ref10$config$percent.translate,
|
|
965
969
|
_ref10$iosStyle = _ref10.iosStyle,
|
|
966
970
|
isIOS = _ref10$iosStyle.isIOS,
|
|
967
971
|
left = _ref10$iosStyle.left,
|
|
@@ -1039,7 +1043,7 @@ var Label = function Label(_ref10) {
|
|
|
1039
1043
|
width: "max-content",
|
|
1040
1044
|
display: "flex",
|
|
1041
1045
|
flexDirection: mode == "horizontal" ? "row" : "column",
|
|
1042
|
-
alignItems: "center",
|
|
1046
|
+
alignItems: align == "left" ? "flex-start" : align == "center" ? "center" : "flex-end",
|
|
1043
1047
|
justifyContent: "center"
|
|
1044
1048
|
}
|
|
1045
1049
|
}, _showName && /*#__PURE__*/_react["default"].createElement(_.TextOverflow, {
|
|
@@ -1049,11 +1053,13 @@ var Label = function Label(_ref10) {
|
|
|
1049
1053
|
style: _objectSpread(_objectSpread({
|
|
1050
1054
|
maxWidth: maxWidth
|
|
1051
1055
|
}, nameStyle), {}, {
|
|
1052
|
-
"float": mode == "horizontal" ? "left" : "none"
|
|
1056
|
+
"float": mode == "horizontal" ? "left" : "none",
|
|
1057
|
+
transform: "translate(".concat(NameTranslate.x, "px, ").concat(NameTranslate.y, "px)")
|
|
1053
1058
|
})
|
|
1054
1059
|
}), showValue && /*#__PURE__*/_react["default"].createElement("span", {
|
|
1055
1060
|
style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(valueFont)), {}, {
|
|
1056
|
-
color: valueSameColor ? pure : valueFont.color
|
|
1061
|
+
color: valueSameColor ? pure : valueFont.color,
|
|
1062
|
+
transform: "translate(".concat(ValueTranslate.x, "px, ").concat(ValueTranslate.y, "px)")
|
|
1057
1063
|
})
|
|
1058
1064
|
}, data.y, showSuffix && /*#__PURE__*/_react["default"].createElement("span", {
|
|
1059
1065
|
style: {
|
|
@@ -1064,7 +1070,8 @@ var Label = function Label(_ref10) {
|
|
|
1064
1070
|
}
|
|
1065
1071
|
}, text)), showPercent && /*#__PURE__*/_react["default"].createElement("span", {
|
|
1066
1072
|
style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(percentFont)), {}, {
|
|
1067
|
-
color: percentSameColor ? pure : percentFont.color
|
|
1073
|
+
color: percentSameColor ? pure : percentFont.color,
|
|
1074
|
+
transform: "translate(".concat(PercentTranslate.x, "px, ").concat(PercentTranslate.y, "px)")
|
|
1068
1075
|
})
|
|
1069
1076
|
}, (_showValue ? "(" : "") + percent + "%" + (_showValue ? ")" : "")))));
|
|
1070
1077
|
}));
|
package/lib/utils/index.js
CHANGED
|
@@ -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
|
@@ -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();
|
|
403
|
+
const xValues = new Set();
|
|
404
404
|
for (const item of data) {
|
|
405
|
-
//
|
|
405
|
+
// 跳过空数据项
|
|
406
406
|
if (!item.data || !item.data.length) continue;
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
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}
|
package/src/components/Label.js
CHANGED
|
@@ -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 =
|
|
111
|
+
const position =isXRepeat?positionX + (config.line ? step : seriesWidth) / 2: xScaler(x);
|
|
111
112
|
const labelPosition = isVertical
|
|
112
113
|
? getVerticalLabel({
|
|
113
114
|
position: _position,
|
|
@@ -1103,9 +1103,10 @@ const Label = ({
|
|
|
1103
1103
|
lineColor,
|
|
1104
1104
|
distance,
|
|
1105
1105
|
mode,
|
|
1106
|
+
align,
|
|
1106
1107
|
show,
|
|
1107
1108
|
translate: { x: translateX, y: translateY },
|
|
1108
|
-
name: { show: showName, font: nameFont, maxWidth, textOverflow, speed },
|
|
1109
|
+
name: { show: showName, font: nameFont, maxWidth, textOverflow, speed,translate:NameTranslate },
|
|
1109
1110
|
value: {
|
|
1110
1111
|
show: showValue,
|
|
1111
1112
|
font: valueFont,
|
|
@@ -1116,12 +1117,14 @@ const Label = ({
|
|
|
1116
1117
|
fontSize: suffixFontSize,
|
|
1117
1118
|
translate: { x: suffixTranslateX, y: suffixTranslateY },
|
|
1118
1119
|
},
|
|
1120
|
+
translate:ValueTranslate
|
|
1119
1121
|
},
|
|
1120
1122
|
percent: {
|
|
1121
1123
|
show: showPercent,
|
|
1122
1124
|
sameColor: percentSameColor,
|
|
1123
1125
|
font: percentFont,
|
|
1124
1126
|
precision,
|
|
1127
|
+
translate:PercentTranslate
|
|
1125
1128
|
},
|
|
1126
1129
|
},
|
|
1127
1130
|
iosStyle: { isIOS, left, top },
|
|
@@ -1237,7 +1240,7 @@ const Label = ({
|
|
|
1237
1240
|
width: "max-content",
|
|
1238
1241
|
display: "flex",
|
|
1239
1242
|
flexDirection: mode == "horizontal" ? "row" : "column",
|
|
1240
|
-
alignItems: "center",
|
|
1243
|
+
alignItems: align=="left"?"flex-start":align=="center"?"center":"flex-end",
|
|
1241
1244
|
justifyContent: "center",
|
|
1242
1245
|
}}
|
|
1243
1246
|
>
|
|
@@ -1252,6 +1255,7 @@ const Label = ({
|
|
|
1252
1255
|
maxWidth,
|
|
1253
1256
|
...nameStyle,
|
|
1254
1257
|
float: mode == "horizontal" ? "left" : "none",
|
|
1258
|
+
transform: `translate(${NameTranslate.x}px, ${NameTranslate.y}px)`
|
|
1255
1259
|
}}
|
|
1256
1260
|
></TextOverflow>
|
|
1257
1261
|
)}
|
|
@@ -1260,6 +1264,7 @@ const Label = ({
|
|
|
1260
1264
|
style={{
|
|
1261
1265
|
...getFontStyle(valueFont),
|
|
1262
1266
|
color: valueSameColor ? pure : valueFont.color,
|
|
1267
|
+
transform: `translate(${ValueTranslate.x}px, ${ValueTranslate.y}px)`
|
|
1263
1268
|
}}
|
|
1264
1269
|
>
|
|
1265
1270
|
{data.y}
|
|
@@ -1282,6 +1287,7 @@ const Label = ({
|
|
|
1282
1287
|
style={{
|
|
1283
1288
|
...getFontStyle(percentFont),
|
|
1284
1289
|
color: percentSameColor ? pure : percentFont.color,
|
|
1290
|
+
transform: `translate(${PercentTranslate.x}px, ${PercentTranslate.y}px)`,
|
|
1285
1291
|
}}
|
|
1286
1292
|
>
|
|
1287
1293
|
{(_showValue ? "(" : "") +
|