@easyv/charts 1.7.36 → 1.7.38
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 +39 -10
- package/lib/css/index.module.css +4 -7
- package/lib/formatter/legend.js +55 -50
- package/package.json +1 -1
- package/src/components/Legend.js +29 -10
- package/src/css/index.module.css +4 -7
- package/src/formatter/legend.js +16 -9
package/lib/components/Legend.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports["default"] = void 0;
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
13
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -26,6 +26,7 @@ var defaultFont = {
|
|
|
26
26
|
fontWeight: 'normal'
|
|
27
27
|
};
|
|
28
28
|
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
29
|
+
var _config$value, _config$percent, _config$value2, _config$value3, _config$name;
|
|
29
30
|
var series = _ref.series,
|
|
30
31
|
height = _ref.height,
|
|
31
32
|
config = _ref.config,
|
|
@@ -124,6 +125,29 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
124
125
|
d.percent = 0;
|
|
125
126
|
});
|
|
126
127
|
}
|
|
128
|
+
|
|
129
|
+
// 计算最大宽度
|
|
130
|
+
var valueFont = ((_config$value = config.value) === null || _config$value === void 0 ? void 0 : _config$value.font) || {};
|
|
131
|
+
var percentFont = ((_config$percent = config.percent) === null || _config$percent === void 0 ? void 0 : _config$percent.font) || {};
|
|
132
|
+
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) || '';
|
|
133
|
+
var valueSplitConfig = ((_config$value3 = config.value) === null || _config$value3 === void 0 ? void 0 : _config$value3.splitConfig) || {};
|
|
134
|
+
var getValueStr = function getValueStr(item) {
|
|
135
|
+
var _ref2, _item$data$y, _item$data;
|
|
136
|
+
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 || '');
|
|
137
|
+
if (valueSplitConfig.show && valueSplitConfig.separator) {
|
|
138
|
+
valueStr = valueStr.toString().replace(/\B(?=(\d{3})+(?!\d))/g, valueSplitConfig.separator);
|
|
139
|
+
}
|
|
140
|
+
return valueStr;
|
|
141
|
+
};
|
|
142
|
+
var valueMaxWidth = Math.max.apply(Math, (0, _toConsumableArray2["default"])(_series.map(function (item) {
|
|
143
|
+
return parseFloat(getCanvasTextWidth(getValueStr(item), valueFont.letterSpacing || 0, "".concat(valueFont.fontSize || 12, "px ").concat(valueFont.fontFamily || 'Arial')));
|
|
144
|
+
})));
|
|
145
|
+
var percentMaxWidth = Math.max.apply(Math, (0, _toConsumableArray2["default"])(_series.map(function (item) {
|
|
146
|
+
var _item$data2;
|
|
147
|
+
var percentStr = (item.percent !== undefined ? item.percent : (_item$data2 = item.data) === null || _item$data2 === void 0 ? void 0 : _item$data2.percent) + '%';
|
|
148
|
+
return parseFloat(getCanvasTextWidth(percentStr, percentFont.letterSpacing || 0, "".concat(percentFont.fontSize || 12, "px ").concat(percentFont.fontFamily || 'Arial')));
|
|
149
|
+
})));
|
|
150
|
+
var nameMaxWidth = ((_config$name = config.name) === null || _config$name === void 0 ? void 0 : _config$name.maxWidth) || 80;
|
|
127
151
|
return LegendType == "FixedWidth" ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
128
152
|
className: "__easyv-legend-wrapper",
|
|
129
153
|
style: _objectSpread(_objectSpread({
|
|
@@ -131,15 +155,14 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
131
155
|
display: 'flex'
|
|
132
156
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
133
157
|
height: loop.show ? height : 'auto',
|
|
134
|
-
overflowY: loop.show ? 'scroll' : 'auto'
|
|
135
|
-
pointerEvents: "none" //鼠标穿透
|
|
158
|
+
overflowY: loop.show ? 'scroll' : 'auto'
|
|
136
159
|
}),
|
|
137
160
|
ref: ref_container
|
|
138
161
|
}, /*#__PURE__*/_react["default"].createElement("ul", {
|
|
139
162
|
style: {
|
|
140
163
|
display: 'grid',
|
|
141
164
|
gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
|
|
142
|
-
gridTemplateColumns:
|
|
165
|
+
gridTemplateColumns: "".concat(nameMaxWidth, "px ").concat(valueMaxWidth, "px ").concat(percentMaxWidth, "px")
|
|
143
166
|
}
|
|
144
167
|
}, _series.map(function (series, index) {
|
|
145
168
|
var _series$config;
|
|
@@ -160,7 +183,11 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
160
183
|
cursor: "pointer",
|
|
161
184
|
gap: _icon.gap
|
|
162
185
|
}
|
|
163
|
-
}, formatter ? formatter(series,
|
|
186
|
+
}, formatter ? formatter(series, _objectSpread(_objectSpread({}, config), {}, {
|
|
187
|
+
valueMaxWidth: valueMaxWidth,
|
|
188
|
+
percentMaxWidth: percentMaxWidth,
|
|
189
|
+
nameMaxWidth: nameMaxWidth
|
|
190
|
+
})) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
164
191
|
style: _icon
|
|
165
192
|
}), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
|
|
166
193
|
type: textOverflow,
|
|
@@ -182,9 +209,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
182
209
|
position: 'absolute'
|
|
183
210
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
184
211
|
height: loop.show ? height : 'auto',
|
|
185
|
-
overflowY: loop.show ? 'scroll' : 'auto'
|
|
186
|
-
width: "100%",
|
|
187
|
-
pointerEvents: "none"
|
|
212
|
+
overflowY: loop.show ? 'scroll' : 'auto'
|
|
188
213
|
}),
|
|
189
214
|
ref: ref_container
|
|
190
215
|
}, (0, _toConsumableArray2["default"])(Array(Math.ceil(series.length / gridTemplateColumns))).map(function (_, indexs) {
|
|
@@ -217,7 +242,11 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
217
242
|
cursor: "pointer",
|
|
218
243
|
gap: _icon.gap
|
|
219
244
|
}
|
|
220
|
-
}, formatter ? formatter(series,
|
|
245
|
+
}, formatter ? formatter(series, _objectSpread(_objectSpread({}, config), {}, {
|
|
246
|
+
valueMaxWidth: valueMaxWidth,
|
|
247
|
+
percentMaxWidth: percentMaxWidth,
|
|
248
|
+
nameMaxWidth: nameMaxWidth
|
|
249
|
+
})) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
221
250
|
style: _icon
|
|
222
251
|
}), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
|
|
223
252
|
ShowType: LegendType,
|
|
@@ -226,7 +255,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
226
255
|
style: _objectSpread(_objectSpread({}, font), {}, {
|
|
227
256
|
fontStyle: italic ? 'italic' : 'normal',
|
|
228
257
|
fontWeight: bold ? 'bold' : 'normal',
|
|
229
|
-
minWidth: getCanvasTextWidth(displayName.substring(0, 5) || name.substring(0, 5), font.letterSpacing, "".concat(font.fontSize, "px ").concat(font.fontFamily))
|
|
258
|
+
minWidth: getCanvasTextWidth(displayName ? displayName.substring(0, 5) || name.substring(0, 5) : "", font.letterSpacing, "".concat(font.fontSize, "px ").concat(font.fontFamily))
|
|
230
259
|
}),
|
|
231
260
|
speed: speed
|
|
232
261
|
})));
|
package/lib/css/index.module.css
CHANGED
|
@@ -27,17 +27,14 @@
|
|
|
27
27
|
.showAllStyle {
|
|
28
28
|
display: grid;
|
|
29
29
|
width: 100%;
|
|
30
|
-
grid-template-columns:
|
|
30
|
+
grid-template-columns: 100px 80px 60px;
|
|
31
31
|
align-items: center;
|
|
32
|
-
|
|
33
|
-
justify-content: space-between;
|
|
32
|
+
column-gap: 12px;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
.notShowAllStyle {
|
|
37
|
-
display:
|
|
36
|
+
display: grid;
|
|
38
37
|
width: 100%;
|
|
39
|
-
/* flex:1; */
|
|
40
38
|
align-items: center;
|
|
41
|
-
|
|
42
|
-
justify-content: space-between;
|
|
39
|
+
column-gap: 12px;
|
|
43
40
|
}
|
package/lib/formatter/legend.js
CHANGED
|
@@ -11,54 +11,60 @@ var _utils = require("../utils");
|
|
|
11
11
|
var _components = require("../components");
|
|
12
12
|
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; }
|
|
13
13
|
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; }
|
|
14
|
-
var pieLegendFormatter = exports.pieLegendFormatter = function pieLegendFormatter(
|
|
15
|
-
var displayName =
|
|
16
|
-
data =
|
|
17
|
-
percent =
|
|
18
|
-
|
|
19
|
-
seriesColor =
|
|
20
|
-
|
|
21
|
-
icon =
|
|
22
|
-
|
|
23
|
-
showName =
|
|
24
|
-
nameFont =
|
|
25
|
-
textOverflow =
|
|
26
|
-
speed =
|
|
27
|
-
maxWidth =
|
|
28
|
-
|
|
29
|
-
nameX =
|
|
30
|
-
nameY =
|
|
31
|
-
|
|
32
|
-
showValue =
|
|
33
|
-
valueFont =
|
|
34
|
-
valueSameColor =
|
|
35
|
-
valueGap =
|
|
36
|
-
valueAlign =
|
|
37
|
-
|
|
38
|
-
valueX =
|
|
39
|
-
valueY =
|
|
40
|
-
splitConfig =
|
|
41
|
-
|
|
42
|
-
showSuffix =
|
|
43
|
-
text =
|
|
44
|
-
fontSize =
|
|
45
|
-
|
|
46
|
-
x =
|
|
47
|
-
y =
|
|
48
|
-
|
|
49
|
-
showPercent =
|
|
50
|
-
percentFont =
|
|
51
|
-
percentSameColor =
|
|
52
|
-
percentGap =
|
|
53
|
-
percentAlign =
|
|
54
|
-
|
|
55
|
-
percentX =
|
|
56
|
-
percentY =
|
|
14
|
+
var pieLegendFormatter = exports.pieLegendFormatter = function pieLegendFormatter(series, props) {
|
|
15
|
+
var displayName = series.displayName,
|
|
16
|
+
data = series.data,
|
|
17
|
+
percent = series.percent,
|
|
18
|
+
_series$series = series.series,
|
|
19
|
+
seriesColor = _series$series.color,
|
|
20
|
+
_series$series$icon = _series$series.icon,
|
|
21
|
+
icon = _series$series$icon === void 0 ? "" : _series$series$icon,
|
|
22
|
+
_props$name = props.name,
|
|
23
|
+
showName = _props$name.show,
|
|
24
|
+
nameFont = _props$name.font,
|
|
25
|
+
textOverflow = _props$name.textOverflow,
|
|
26
|
+
speed = _props$name.speed,
|
|
27
|
+
maxWidth = _props$name.maxWidth,
|
|
28
|
+
_props$name$translate = _props$name.translate,
|
|
29
|
+
nameX = _props$name$translate.x,
|
|
30
|
+
nameY = _props$name$translate.y,
|
|
31
|
+
_props$value = props.value,
|
|
32
|
+
showValue = _props$value.show,
|
|
33
|
+
valueFont = _props$value.font,
|
|
34
|
+
valueSameColor = _props$value.sameColor,
|
|
35
|
+
valueGap = _props$value.gap,
|
|
36
|
+
valueAlign = _props$value.align,
|
|
37
|
+
_props$value$translat = _props$value.translate,
|
|
38
|
+
valueX = _props$value$translat.x,
|
|
39
|
+
valueY = _props$value$translat.y,
|
|
40
|
+
splitConfig = _props$value.splitConfig,
|
|
41
|
+
_props$value$suffix = _props$value.suffix,
|
|
42
|
+
showSuffix = _props$value$suffix.show,
|
|
43
|
+
text = _props$value$suffix.text,
|
|
44
|
+
fontSize = _props$value$suffix.fontSize,
|
|
45
|
+
_props$value$suffix$t = _props$value$suffix.translate,
|
|
46
|
+
x = _props$value$suffix$t.x,
|
|
47
|
+
y = _props$value$suffix$t.y,
|
|
48
|
+
_props$percent = props.percent,
|
|
49
|
+
showPercent = _props$percent.show,
|
|
50
|
+
percentFont = _props$percent.font,
|
|
51
|
+
percentSameColor = _props$percent.sameColor,
|
|
52
|
+
percentGap = _props$percent.gap,
|
|
53
|
+
percentAlign = _props$percent.align,
|
|
54
|
+
_props$percent$transl = _props$percent.translate,
|
|
55
|
+
percentX = _props$percent$transl.x,
|
|
56
|
+
percentY = _props$percent$transl.y;
|
|
57
57
|
var seriesColorType = seriesColor.type,
|
|
58
58
|
pure = seriesColor.pure,
|
|
59
59
|
stops = seriesColor.linear.stops;
|
|
60
60
|
var _color = seriesColorType == 'pure' ? pure : stops[0].color;
|
|
61
61
|
var textMarginLeft = 5;
|
|
62
|
+
|
|
63
|
+
// 1. 计算每列宽度(加上间距)
|
|
64
|
+
var columns = [];
|
|
65
|
+
if (showName) columns.push("".concat(props.nameMaxWidth, "px"));
|
|
66
|
+
if (showValue) columns.push("".concat(props.valueMaxWidth + valueGap, "px"));
|
|
67
|
+
if (showPercent) columns.push("".concat(props.percentMaxWidth + percentGap, "px"));
|
|
62
68
|
return /*#__PURE__*/React.createElement(React.Fragment, null, icon && /*#__PURE__*/React.createElement("span", {
|
|
63
69
|
style: _objectSpread(_objectSpread({}, icon), {}, {
|
|
64
70
|
marginRight: icon.marginRight,
|
|
@@ -67,7 +73,8 @@ var pieLegendFormatter = exports.pieLegendFormatter = function pieLegendFormatte
|
|
|
67
73
|
}), /*#__PURE__*/React.createElement("div", {
|
|
68
74
|
className: showName && showValue && showPercent ? _indexModule["default"].showAllStyle : _indexModule["default"].notShowAllStyle,
|
|
69
75
|
style: {
|
|
70
|
-
width: "calc( 100% + ".concat(textMarginLeft + valueGap + percentGap, "px )")
|
|
76
|
+
width: "calc( 100% + ".concat(textMarginLeft + valueGap + percentGap, "px )"),
|
|
77
|
+
gridTemplateColumns: columns.join(' ')
|
|
71
78
|
}
|
|
72
79
|
}, showName && /*#__PURE__*/React.createElement(_components.TextOverflow, {
|
|
73
80
|
value: displayName,
|
|
@@ -85,11 +92,10 @@ var pieLegendFormatter = exports.pieLegendFormatter = function pieLegendFormatte
|
|
|
85
92
|
}, (0, _utils.getFontStyle)(valueFont)), {}, {
|
|
86
93
|
marginLeft: valueGap,
|
|
87
94
|
transform: "translate(".concat(valueX, "px,").concat(valueY, "px)"),
|
|
88
|
-
display: 'flex',
|
|
89
|
-
flex: 1,
|
|
90
95
|
color: valueSameColor ? _color : valueFont.color,
|
|
91
96
|
alignItems: 'center',
|
|
92
|
-
justifyContent: valueAlign == "left" ? "flex-start" : valueAlign == "right" ? "flex-end" : 'center'
|
|
97
|
+
justifyContent: valueAlign == "left" ? "flex-start" : valueAlign == "right" ? "flex-end" : 'center',
|
|
98
|
+
textAlign: valueAlign === "left" ? "left" : valueAlign === "right" ? "right" : "center"
|
|
93
99
|
})
|
|
94
100
|
}, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(_components.SplitText, {
|
|
95
101
|
value: data.y,
|
|
@@ -106,11 +112,10 @@ var pieLegendFormatter = exports.pieLegendFormatter = function pieLegendFormatte
|
|
|
106
112
|
}, (0, _utils.getFontStyle)(percentFont)), {}, {
|
|
107
113
|
marginLeft: percentGap,
|
|
108
114
|
transform: "translate(".concat(percentX, "px,").concat(percentY, "px)"),
|
|
109
|
-
|
|
110
|
-
flex: 1,
|
|
115
|
+
color: percentSameColor ? _color : percentFont.color,
|
|
111
116
|
alignItems: 'center',
|
|
112
117
|
justifyContent: percentAlign == "left" ? "flex-start" : percentAlign == "right" ? "flex-end" : 'center',
|
|
113
|
-
|
|
118
|
+
textAlign: percentAlign === "left" ? "left" : percentAlign === "right" ? "right" : "center"
|
|
114
119
|
})
|
|
115
120
|
}, percent + '%')));
|
|
116
121
|
};
|
package/package.json
CHANGED
package/src/components/Legend.js
CHANGED
|
@@ -100,6 +100,29 @@ export default memo(
|
|
|
100
100
|
})
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
// 计算最大宽度
|
|
104
|
+
const valueFont = config.value?.font || {};
|
|
105
|
+
const percentFont = config.percent?.font || {};
|
|
106
|
+
const valueSuffix = config.value?.suffix?.text || '';
|
|
107
|
+
const valueSplitConfig = config.value?.splitConfig || {};
|
|
108
|
+
const getValueStr = (item) => {
|
|
109
|
+
let valueStr = (item.data?.y ?? item.value ?? '') + (valueSuffix || '');
|
|
110
|
+
if (valueSplitConfig.show && valueSplitConfig.separator) {
|
|
111
|
+
valueStr = valueStr.toString().replace(/\B(?=(\d{3})+(?!\d))/g, valueSplitConfig.separator);
|
|
112
|
+
}
|
|
113
|
+
return valueStr;
|
|
114
|
+
};
|
|
115
|
+
const valueMaxWidth = Math.max(
|
|
116
|
+
..._series.map(item => parseFloat(getCanvasTextWidth(getValueStr(item), valueFont.letterSpacing || 0, `${valueFont.fontSize || 12}px ${valueFont.fontFamily || 'Arial'}`)))
|
|
117
|
+
);
|
|
118
|
+
const percentMaxWidth = Math.max(
|
|
119
|
+
..._series.map(item => {
|
|
120
|
+
const percentStr = (item.percent !== undefined ? item.percent : item.data?.percent) + '%';
|
|
121
|
+
return parseFloat(getCanvasTextWidth(percentStr, percentFont.letterSpacing || 0, `${percentFont.fontSize || 12}px ${percentFont.fontFamily || 'Arial'}`));
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
const nameMaxWidth = config.name?.maxWidth || 80;
|
|
125
|
+
|
|
103
126
|
return (
|
|
104
127
|
LegendType=="FixedWidth"?
|
|
105
128
|
<div
|
|
@@ -109,8 +132,7 @@ export default memo(
|
|
|
109
132
|
display: 'flex',
|
|
110
133
|
...getPosition(position, _alignment, x, y),
|
|
111
134
|
height: loop.show ? height : 'auto',
|
|
112
|
-
overflowY: loop.show ? 'scroll' : 'auto'
|
|
113
|
-
pointerEvents:"none"//鼠标穿透
|
|
135
|
+
overflowY: loop.show ? 'scroll' : 'auto'
|
|
114
136
|
}}
|
|
115
137
|
ref={ref_container}
|
|
116
138
|
>
|
|
@@ -118,8 +140,7 @@ export default memo(
|
|
|
118
140
|
style={{
|
|
119
141
|
display: 'grid',
|
|
120
142
|
gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
|
|
121
|
-
gridTemplateColumns:
|
|
122
|
-
'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)',
|
|
143
|
+
gridTemplateColumns: `${nameMaxWidth}px ${valueMaxWidth}px ${percentMaxWidth}px`,
|
|
123
144
|
}}
|
|
124
145
|
>
|
|
125
146
|
{_series.map((series, index) => {
|
|
@@ -139,7 +160,7 @@ export default memo(
|
|
|
139
160
|
}}
|
|
140
161
|
>
|
|
141
162
|
{formatter ? (
|
|
142
|
-
formatter(series, config)
|
|
163
|
+
formatter(series, { ...config, valueMaxWidth, percentMaxWidth, nameMaxWidth })
|
|
143
164
|
) : (
|
|
144
165
|
<>
|
|
145
166
|
<span style={_icon} />
|
|
@@ -166,9 +187,7 @@ export default memo(
|
|
|
166
187
|
position: 'absolute',
|
|
167
188
|
...getPosition(position, _alignment, x, y),
|
|
168
189
|
height: loop.show ? height : 'auto',
|
|
169
|
-
overflowY: loop.show ? 'scroll' : 'auto'
|
|
170
|
-
width:"100%",
|
|
171
|
-
pointerEvents:"none"
|
|
190
|
+
overflowY: loop.show ? 'scroll' : 'auto'
|
|
172
191
|
}}
|
|
173
192
|
ref={ref_container}
|
|
174
193
|
>
|
|
@@ -203,7 +222,7 @@ export default memo(
|
|
|
203
222
|
}}
|
|
204
223
|
>
|
|
205
224
|
{formatter ? (
|
|
206
|
-
formatter(series, config)
|
|
225
|
+
formatter(series, { ...config, valueMaxWidth, percentMaxWidth, nameMaxWidth })
|
|
207
226
|
) : (
|
|
208
227
|
<>
|
|
209
228
|
<span style={_icon} />
|
|
@@ -211,7 +230,7 @@ export default memo(
|
|
|
211
230
|
...font,
|
|
212
231
|
fontStyle: italic ? 'italic' : 'normal',
|
|
213
232
|
fontWeight: bold ? 'bold' : 'normal',
|
|
214
|
-
minWidth:getCanvasTextWidth(displayName.substring(0,5) || name.substring(0,5),font.letterSpacing,`${font.fontSize}px ${font.fontFamily}` )
|
|
233
|
+
minWidth:getCanvasTextWidth(displayName?(displayName.substring(0,5) || name.substring(0,5)):"",font.letterSpacing,`${font.fontSize}px ${font.fontFamily}` )
|
|
215
234
|
}} speed={speed}></TextOverflow>
|
|
216
235
|
|
|
217
236
|
</>
|
package/src/css/index.module.css
CHANGED
|
@@ -27,17 +27,14 @@
|
|
|
27
27
|
.showAllStyle {
|
|
28
28
|
display: grid;
|
|
29
29
|
width: 100%;
|
|
30
|
-
grid-template-columns:
|
|
30
|
+
grid-template-columns: 100px 80px 60px;
|
|
31
31
|
align-items: center;
|
|
32
|
-
|
|
33
|
-
justify-content: space-between;
|
|
32
|
+
column-gap: 12px;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
.notShowAllStyle {
|
|
37
|
-
display:
|
|
36
|
+
display: grid;
|
|
38
37
|
width: 100%;
|
|
39
|
-
/* flex:1; */
|
|
40
38
|
align-items: center;
|
|
41
|
-
|
|
42
|
-
justify-content: space-between;
|
|
39
|
+
column-gap: 12px;
|
|
43
40
|
}
|
package/src/formatter/legend.js
CHANGED
|
@@ -3,7 +3,10 @@ import { getFontStyle } from '../utils';
|
|
|
3
3
|
import { TextOverflow, SplitText } from '../components';
|
|
4
4
|
|
|
5
5
|
export const pieLegendFormatter = (
|
|
6
|
-
|
|
6
|
+
series,
|
|
7
|
+
props
|
|
8
|
+
) => {
|
|
9
|
+
const { displayName, data, percent, series: { color: seriesColor, icon="" } } = series,
|
|
7
10
|
{
|
|
8
11
|
name: { show: showName, font: nameFont, textOverflow, speed, maxWidth, translate: { x:nameX, y:nameY } },
|
|
9
12
|
value: {
|
|
@@ -35,8 +38,7 @@ export const pieLegendFormatter = (
|
|
|
35
38
|
y:percentY
|
|
36
39
|
}
|
|
37
40
|
},
|
|
38
|
-
}
|
|
39
|
-
) => {
|
|
41
|
+
} = props;
|
|
40
42
|
const {
|
|
41
43
|
type: seriesColorType,
|
|
42
44
|
pure,
|
|
@@ -46,6 +48,12 @@ export const pieLegendFormatter = (
|
|
|
46
48
|
const _color = seriesColorType == 'pure' ? pure : stops[0].color;
|
|
47
49
|
const textMarginLeft = 5;
|
|
48
50
|
|
|
51
|
+
// 1. 计算每列宽度(加上间距)
|
|
52
|
+
const columns = [];
|
|
53
|
+
if (showName) columns.push(`${props.nameMaxWidth}px`);
|
|
54
|
+
if (showValue) columns.push(`${props.valueMaxWidth + valueGap}px`);
|
|
55
|
+
if (showPercent) columns.push(`${props.percentMaxWidth + percentGap}px`);
|
|
56
|
+
|
|
49
57
|
return (
|
|
50
58
|
<>
|
|
51
59
|
{icon &&<span style={{ ...icon, marginRight: icon.marginRight, transform:`translate(${nameX}px, ${nameY}px)` }} />}
|
|
@@ -56,7 +64,8 @@ export const pieLegendFormatter = (
|
|
|
56
64
|
: css.notShowAllStyle
|
|
57
65
|
}
|
|
58
66
|
style={{
|
|
59
|
-
width:`calc( 100% + ${textMarginLeft+valueGap+percentGap}px )
|
|
67
|
+
width:`calc( 100% + ${textMarginLeft+valueGap+percentGap}px )`,
|
|
68
|
+
gridTemplateColumns: columns.join(' ')
|
|
60
69
|
}}
|
|
61
70
|
>
|
|
62
71
|
{showName && (
|
|
@@ -71,11 +80,10 @@ export const pieLegendFormatter = (
|
|
|
71
80
|
...getFontStyle(valueFont),
|
|
72
81
|
marginLeft: valueGap,
|
|
73
82
|
transform:`translate(${valueX}px,${valueY}px)`,
|
|
74
|
-
display: 'flex',
|
|
75
|
-
flex:1,
|
|
76
83
|
color: valueSameColor ? _color : valueFont.color,
|
|
77
84
|
alignItems: 'center',
|
|
78
85
|
justifyContent: valueAlign=="left"?"flex-start":valueAlign=="right"?"flex-end":'center',
|
|
86
|
+
textAlign: valueAlign === "left" ? "left" : valueAlign === "right" ? "right" : "center",
|
|
79
87
|
}}
|
|
80
88
|
>
|
|
81
89
|
<span><SplitText value={data.y} config={splitConfig} /></span>
|
|
@@ -99,11 +107,10 @@ export const pieLegendFormatter = (
|
|
|
99
107
|
...getFontStyle(percentFont),
|
|
100
108
|
marginLeft: percentGap,
|
|
101
109
|
transform:`translate(${percentX}px,${percentY}px)`,
|
|
102
|
-
|
|
103
|
-
flex:1,
|
|
110
|
+
color: percentSameColor ? _color : percentFont.color,
|
|
104
111
|
alignItems: 'center',
|
|
105
112
|
justifyContent: percentAlign=="left"?"flex-start":percentAlign=="right"?"flex-end":'center',
|
|
106
|
-
|
|
113
|
+
textAlign: percentAlign === "left" ? "left" : percentAlign === "right" ? "right" : "center",
|
|
107
114
|
}}
|
|
108
115
|
>
|
|
109
116
|
{percent + '%'}
|