@easyv/charts 1.7.30 → 1.7.32
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 +2 -1
- package/lib/components/Legend.js +71 -2
- package/lib/components/Mapping.js +14 -3
- package/lib/components/StackData.js +2 -1
- package/lib/components/TextOverflow.js +5 -2
- package/lib/hooks/useStackData.js +40 -3
- package/package.json +1 -1
- package/src/components/CartesianChart.js +2 -1
- package/src/components/Chart.js +3 -3
- package/src/components/Legend.js +75 -0
- package/src/components/Mapping.js +8 -5
- package/src/components/StackData.js +2 -2
- package/src/components/TextOverflow.tsx +6 -3
- package/src/hooks/useStackData.js +41 -3
|
@@ -26,6 +26,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
26
26
|
var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
27
27
|
var width = _ref.width,
|
|
28
28
|
height = _ref.height,
|
|
29
|
+
seriesData = _ref.seriesData,
|
|
29
30
|
_ref$config = _ref.config,
|
|
30
31
|
axesConfig = _ref$config.axes,
|
|
31
32
|
background = _ref$config.background,
|
|
@@ -639,7 +640,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
639
640
|
}
|
|
640
641
|
}), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
|
|
641
642
|
filterData: filterData,
|
|
642
|
-
series:
|
|
643
|
+
series: seriesData
|
|
643
644
|
})), showTooltip && !control && /*#__PURE__*/_react["default"].createElement(_.Tooltip, (0, _extends2["default"])({
|
|
644
645
|
isVertical: isVertical
|
|
645
646
|
}, tooltip, {
|
package/lib/components/Legend.js
CHANGED
|
@@ -6,6 +6,7 @@ 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"));
|
|
9
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
@@ -33,6 +34,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
33
34
|
_ref$config$order = _ref$config.order,
|
|
34
35
|
order = _ref$config$order === void 0 ? '' : _ref$config$order,
|
|
35
36
|
interactive = _ref$config.interactive,
|
|
37
|
+
LegendType = _ref$config.LegendType,
|
|
36
38
|
maxWidth = _ref$config.maxWidth,
|
|
37
39
|
textOverflow = _ref$config.textOverflow,
|
|
38
40
|
speed = _ref$config.speed,
|
|
@@ -122,7 +124,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
122
124
|
d.percent = 0;
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
|
-
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
127
|
+
return LegendType == "FixedWidth" ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
126
128
|
className: "__easyv-legend-wrapper",
|
|
127
129
|
style: _objectSpread(_objectSpread({
|
|
128
130
|
position: 'absolute',
|
|
@@ -169,7 +171,66 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
169
171
|
}),
|
|
170
172
|
speed: speed
|
|
171
173
|
})));
|
|
172
|
-
})))
|
|
174
|
+
}))) : /*#__PURE__*/_react["default"].createElement("div", {
|
|
175
|
+
className: "__easyv-legend-wrapper",
|
|
176
|
+
style: _objectSpread(_objectSpread({
|
|
177
|
+
display: 'flex',
|
|
178
|
+
flexWrap: "wrap",
|
|
179
|
+
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",
|
|
180
|
+
flexDirection: "column",
|
|
181
|
+
position: 'absolute'
|
|
182
|
+
}, getPosition(position, _alignment, x, y)), {}, {
|
|
183
|
+
height: loop.show ? height : 'auto',
|
|
184
|
+
overflowY: loop.show ? 'scroll' : 'auto',
|
|
185
|
+
width: "100%"
|
|
186
|
+
}),
|
|
187
|
+
ref: ref_container
|
|
188
|
+
}, (0, _toConsumableArray2["default"])(Array(Math.ceil(series.length / gridTemplateColumns))).map(function (_, indexs) {
|
|
189
|
+
return /*#__PURE__*/_react["default"].createElement("ul", {
|
|
190
|
+
key: indexs,
|
|
191
|
+
style: (0, _defineProperty2["default"])({
|
|
192
|
+
display: 'flex',
|
|
193
|
+
width: 'fit-content',
|
|
194
|
+
justifyContent: alignment.split(" ")[0] == "left" ? "flex-start" : alignment.split(" ")[0] == "center" ? "center" : "flex-end",
|
|
195
|
+
marginBottom: "0px",
|
|
196
|
+
gap: "".concat(gridRowGap, "px ").concat(gridColumnGap, "px")
|
|
197
|
+
}, "marginBottom", gridRowGap + "px")
|
|
198
|
+
}, _series.map(function (series, index) {
|
|
199
|
+
if (Math.floor(index / gridTemplateColumns) == indexs) {
|
|
200
|
+
var _series$config2;
|
|
201
|
+
var type = series.type,
|
|
202
|
+
name = series.name,
|
|
203
|
+
displayName = series.displayName,
|
|
204
|
+
icon = series.icon,
|
|
205
|
+
selected = series.selected;
|
|
206
|
+
var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config2 = series.config) === null || _series$config2 === void 0 || (_series$config2 = _series$config2.line) === null || _series$config2 === void 0 ? void 0 : _series$config2.type);
|
|
207
|
+
return /*#__PURE__*/_react["default"].createElement("li", {
|
|
208
|
+
key: index,
|
|
209
|
+
onClick: onClick,
|
|
210
|
+
"data-name": name,
|
|
211
|
+
style: {
|
|
212
|
+
display: 'flex',
|
|
213
|
+
opacity: selected === false ? opacity / 100 : 1,
|
|
214
|
+
alignItems: 'center',
|
|
215
|
+
cursor: "pointer",
|
|
216
|
+
gap: _icon.gap
|
|
217
|
+
}
|
|
218
|
+
}, formatter ? formatter(series, config) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
219
|
+
style: _icon
|
|
220
|
+
}), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
|
|
221
|
+
ShowType: LegendType,
|
|
222
|
+
type: "ellipsis",
|
|
223
|
+
value: displayName || name,
|
|
224
|
+
style: _objectSpread(_objectSpread({}, font), {}, {
|
|
225
|
+
fontStyle: italic ? 'italic' : 'normal',
|
|
226
|
+
fontWeight: bold ? 'bold' : 'normal',
|
|
227
|
+
minWidth: getCanvasTextWidth(displayName.substring(0, 5) || name.substring(0, 5), font.letterSpacing, "".concat(font.fontSize, "px ").concat(font.fontFamily))
|
|
228
|
+
}),
|
|
229
|
+
speed: speed
|
|
230
|
+
})));
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
233
|
+
}));
|
|
173
234
|
});
|
|
174
235
|
var getPosition = function getPosition(position, alignment) {
|
|
175
236
|
var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
@@ -203,4 +264,12 @@ var getPosition = function getPosition(position, alignment) {
|
|
|
203
264
|
transform: "translate3d(calc(".concat(alignment == 'center' ? '-50%' : '0px', " + ").concat(x, "px), ").concat(y, "px, 0px)")
|
|
204
265
|
};
|
|
205
266
|
}
|
|
267
|
+
};
|
|
268
|
+
var getCanvasTextWidth = function getCanvasTextWidth(text, letterSpacing) {
|
|
269
|
+
var font = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '16px Arial';
|
|
270
|
+
var canvas = document.createElement('canvas');
|
|
271
|
+
var ctx = canvas.getContext('2d');
|
|
272
|
+
ctx.font = font;
|
|
273
|
+
return ctx.measureText(text).width + text.length * letterSpacing + "px";
|
|
274
|
+
// return ctx.measureText(text).width+(text.length-1)*letterSpacing+"px";//-1有bug
|
|
206
275
|
};
|
|
@@ -65,8 +65,18 @@ var _default = exports["default"] = function _default(Component) {
|
|
|
65
65
|
var fieldName = _ref2.fieldName;
|
|
66
66
|
return !fieldName;
|
|
67
67
|
});
|
|
68
|
-
var
|
|
68
|
+
var lastSeries = series[seriesLength - 1];
|
|
69
|
+
var tmp = new Map(series.filter(function (d) {
|
|
70
|
+
return d.fieldName;
|
|
71
|
+
}).map(function (d) {
|
|
72
|
+
return [d.fieldName, {}];
|
|
73
|
+
})); //确定的系列样式
|
|
74
|
+
var i = 0;
|
|
75
|
+
var emptyArray = series.filter(function (d) {
|
|
76
|
+
return !d.fieldName;
|
|
77
|
+
}); //没有fieldsName的系列样式
|
|
69
78
|
if (!!noName) {
|
|
79
|
+
//都没名
|
|
70
80
|
data.forEach(function (_ref3, index) {
|
|
71
81
|
var key = _ref3.key;
|
|
72
82
|
var current = series[index % seriesLength];
|
|
@@ -77,14 +87,15 @@ var _default = exports["default"] = function _default(Component) {
|
|
|
77
87
|
});
|
|
78
88
|
return tmp;
|
|
79
89
|
}
|
|
80
|
-
var lastSeries = series[seriesLength - 1];
|
|
81
90
|
data.forEach(function (_ref4) {
|
|
82
91
|
var key = _ref4.key;
|
|
92
|
+
//先把有系列的渲染了,无系列的排后面
|
|
83
93
|
var current = series.find(function (_ref5) {
|
|
84
94
|
var fieldName = _ref5.fieldName;
|
|
85
95
|
return fieldName == key;
|
|
86
96
|
});
|
|
87
|
-
var result = current || lastSeries;
|
|
97
|
+
var result = current || emptyArray[i] || lastSeries;
|
|
98
|
+
if (!current) i = (i + 1) % emptyArray.length;
|
|
88
99
|
var name = (current ? current.fieldName || current.displayName : key) || '';
|
|
89
100
|
tmp.set(name, _objectSpread(_objectSpread({}, result), {}, {
|
|
90
101
|
name: name,
|
|
@@ -30,7 +30,8 @@ var _default = exports["default"] = function _default(Component) {
|
|
|
30
30
|
});
|
|
31
31
|
return /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({}, props, {
|
|
32
32
|
config: _objectSpread(_objectSpread({}, config), _config),
|
|
33
|
-
data: data
|
|
33
|
+
data: data,
|
|
34
|
+
seriesData: _config.seriesdata
|
|
34
35
|
}));
|
|
35
36
|
});
|
|
36
37
|
};
|
|
@@ -24,7 +24,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
24
24
|
_props$speed = props.speed,
|
|
25
25
|
speed = _props$speed === void 0 ? 5 : _props$speed,
|
|
26
26
|
_props$config = props.config,
|
|
27
|
-
config = _props$config === void 0 ? {} : _props$config
|
|
27
|
+
config = _props$config === void 0 ? {} : _props$config,
|
|
28
|
+
ShowType = props.ShowType;
|
|
28
29
|
var _config$needTitle = config.needTitle,
|
|
29
30
|
needTitle = _config$needTitle === void 0 ? true : _config$needTitle;
|
|
30
31
|
var getTextOverflow = function getTextOverflow(type) {
|
|
@@ -59,7 +60,9 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
59
60
|
style: styles,
|
|
60
61
|
ref: ref
|
|
61
62
|
}) : /*#__PURE__*/_react["default"].createElement("div", {
|
|
62
|
-
style: styles,
|
|
63
|
+
style: _objectSpread(_objectSpread({}, styles), {}, {
|
|
64
|
+
whiteSpace: ShowType == "Adaptive" ? "normal" : styles.whiteSpace
|
|
65
|
+
}),
|
|
63
66
|
ref: ref,
|
|
64
67
|
title: needTitle && type == "ellipsis" ? text || undefined : undefined,
|
|
65
68
|
dangerouslySetInnerHTML: {
|
|
@@ -74,7 +74,41 @@ var setStackData = function setStackData(data, series, stacks) {
|
|
|
74
74
|
dataMap.clear();
|
|
75
75
|
return series;
|
|
76
76
|
};
|
|
77
|
+
var mergeDataAndSeries = function mergeDataAndSeries(data, _series) {
|
|
78
|
+
// 创建一个映射,键为系列名称,值为数据点数组
|
|
79
|
+
var dataMap = new Map();
|
|
77
80
|
|
|
81
|
+
// 遍历 data 数组,按系列名称分组数据点
|
|
82
|
+
data.forEach(function (item) {
|
|
83
|
+
var seriesName = item.s;
|
|
84
|
+
if (!dataMap.has(seriesName)) {
|
|
85
|
+
dataMap.set(seriesName, []);
|
|
86
|
+
}
|
|
87
|
+
// 构建符合目标格式的数据点对象
|
|
88
|
+
var dataPoint = {
|
|
89
|
+
data: {
|
|
90
|
+
s: item.s,
|
|
91
|
+
x: item.x,
|
|
92
|
+
y: item.y,
|
|
93
|
+
showY: item.showY
|
|
94
|
+
},
|
|
95
|
+
index: 0,
|
|
96
|
+
bound: [0, item.y]
|
|
97
|
+
};
|
|
98
|
+
dataMap.get(seriesName).push(dataPoint);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// 遍历 _series 数组,为每个系列添加对应的数据
|
|
102
|
+
return _series.map(function (series) {
|
|
103
|
+
var seriesName = series.name || series.fieldName;
|
|
104
|
+
// 查找对应系列的数据
|
|
105
|
+
var seriesData = dataMap.get(seriesName) || [];
|
|
106
|
+
// 返回合并后完整的系列对象,包含原始配置和新添加的数据
|
|
107
|
+
return _objectSpread(_objectSpread({}, series), {}, {
|
|
108
|
+
data: seriesData
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
78
112
|
/**
|
|
79
113
|
* 计算堆叠数据
|
|
80
114
|
* @param {Array} data 数据
|
|
@@ -96,12 +130,13 @@ var _default = exports["default"] = function _default(_ref2) {
|
|
|
96
130
|
return (0, _utils.dataYOrZ)(data, _series.series);
|
|
97
131
|
}, [data, _series]);
|
|
98
132
|
var tmp = (0, _react.useMemo)(function () {
|
|
133
|
+
var seriesdata = mergeDataAndSeries(data, Array.from(series.values()));
|
|
99
134
|
var dataY = _data.y,
|
|
100
135
|
dataZ = _data.z;
|
|
101
136
|
var stacks = _series.stacks,
|
|
102
137
|
_series$series = _series.series,
|
|
103
|
-
|
|
104
|
-
|
|
138
|
+
seriesZ = _series$series.z,
|
|
139
|
+
seriesY = _series$series.y;
|
|
105
140
|
resetStackData(seriesY);
|
|
106
141
|
resetStackData(seriesZ);
|
|
107
142
|
setStackData(dataY, seriesY, stacks);
|
|
@@ -110,7 +145,9 @@ var _default = exports["default"] = function _default(_ref2) {
|
|
|
110
145
|
bandLength: stacks.filter(function (item) {
|
|
111
146
|
return item.type == 'band';
|
|
112
147
|
}).length,
|
|
113
|
-
series:
|
|
148
|
+
// series: mergeDataAndSeries(data,Array.from(series.values())),
|
|
149
|
+
series: [].concat((0, _toConsumableArray2["default"])(seriesY.values()), (0, _toConsumableArray2["default"])(seriesZ.values())),
|
|
150
|
+
seriesdata: seriesdata
|
|
114
151
|
};
|
|
115
152
|
}, [_data, _series]);
|
|
116
153
|
return tmp;
|
package/package.json
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
const Chart = memo(
|
|
35
35
|
({
|
|
36
36
|
width, height,
|
|
37
|
+
seriesData,
|
|
37
38
|
config: {
|
|
38
39
|
axes: axesConfig,
|
|
39
40
|
background,
|
|
@@ -659,7 +660,7 @@ const Chart = memo(
|
|
|
659
660
|
}}
|
|
660
661
|
></Control>
|
|
661
662
|
)}
|
|
662
|
-
<Legend {...legend} filterData={filterData} series={
|
|
663
|
+
<Legend {...legend} filterData={filterData} series={seriesData} />
|
|
663
664
|
{/* 非控制图下的提示框 */}
|
|
664
665
|
{showTooltip && !control && (
|
|
665
666
|
<Tooltip
|
package/src/components/Chart.js
CHANGED
|
@@ -89,7 +89,7 @@ const Chart = memo(
|
|
|
89
89
|
}),
|
|
90
90
|
[id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
|
|
91
91
|
);
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
useEffect(()=>{
|
|
94
94
|
let isAnimation = window.screenConfig?window.screenConfig.isAnimation:true; //大屏的全局设置是否允许开启动画,false为不允许
|
|
95
95
|
if(!isAnimation) setActive(false);
|
|
@@ -107,14 +107,14 @@ const Chart = memo(
|
|
|
107
107
|
},[]);
|
|
108
108
|
|
|
109
109
|
let data = checkData(originData);
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
return (
|
|
112
112
|
<chartContext.Provider value={context}>
|
|
113
113
|
{type == 'pie' ? (
|
|
114
114
|
<PieChart id={id} config={config} data={data} active={active} {...props} />
|
|
115
115
|
) : (
|
|
116
116
|
<CartesianChart id={id} config={config} data={data} active={active} {...props} />
|
|
117
|
-
|
|
117
|
+
)}
|
|
118
118
|
</chartContext.Provider>
|
|
119
119
|
|
|
120
120
|
);
|
package/src/components/Legend.js
CHANGED
|
@@ -19,6 +19,7 @@ export default memo(
|
|
|
19
19
|
show,
|
|
20
20
|
order = '',
|
|
21
21
|
interactive,
|
|
22
|
+
LegendType,//类型
|
|
22
23
|
maxWidth,
|
|
23
24
|
textOverflow,
|
|
24
25
|
speed,
|
|
@@ -100,6 +101,7 @@ export default memo(
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
return (
|
|
104
|
+
LegendType=="FixedWidth"?
|
|
103
105
|
<div
|
|
104
106
|
className='__easyv-legend-wrapper'
|
|
105
107
|
style={{
|
|
@@ -153,6 +155,72 @@ export default memo(
|
|
|
153
155
|
);
|
|
154
156
|
})}
|
|
155
157
|
</ul>
|
|
158
|
+
</div>:<div
|
|
159
|
+
className='__easyv-legend-wrapper'
|
|
160
|
+
style={{
|
|
161
|
+
display:'flex',
|
|
162
|
+
flexWrap:"wrap",
|
|
163
|
+
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",
|
|
164
|
+
flexDirection: "column",
|
|
165
|
+
position: 'absolute',
|
|
166
|
+
...getPosition(position, _alignment, x, y),
|
|
167
|
+
height: loop.show ? height : 'auto',
|
|
168
|
+
overflowY: loop.show ? 'scroll' : 'auto',
|
|
169
|
+
width:"100%"
|
|
170
|
+
}}
|
|
171
|
+
ref={ref_container}
|
|
172
|
+
>
|
|
173
|
+
|
|
174
|
+
{[...Array(Math.ceil(series.length/gridTemplateColumns))].map((_,indexs)=>(
|
|
175
|
+
<ul
|
|
176
|
+
key={indexs}
|
|
177
|
+
style={{
|
|
178
|
+
display: 'flex',
|
|
179
|
+
width: 'fit-content',
|
|
180
|
+
justifyContent:alignment.split(" ")[0]=="left"?"flex-start":alignment.split(" ")[0]=="center"?"center":"flex-end",
|
|
181
|
+
marginBottom:"0px",
|
|
182
|
+
gap:`${gridRowGap}px ${gridColumnGap}px`,
|
|
183
|
+
marginBottom:gridRowGap+"px"
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
{_series.map((series, index) => {
|
|
187
|
+
if(Math.floor(index/gridTemplateColumns)==indexs){
|
|
188
|
+
const { type, name, displayName, icon, selected } = series;
|
|
189
|
+
const _icon = getIcon(type, icon, series?.config?.line?.type);
|
|
190
|
+
return (
|
|
191
|
+
<li
|
|
192
|
+
key={index}
|
|
193
|
+
onClick={onClick}
|
|
194
|
+
data-name={name}
|
|
195
|
+
style={{
|
|
196
|
+
display: 'flex',
|
|
197
|
+
opacity: selected === false ? opacity / 100 : 1,
|
|
198
|
+
alignItems: 'center',
|
|
199
|
+
cursor: "pointer",
|
|
200
|
+
gap: _icon.gap,
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
203
|
+
{formatter ? (
|
|
204
|
+
formatter(series, config)
|
|
205
|
+
) : (
|
|
206
|
+
<>
|
|
207
|
+
<span style={_icon} />
|
|
208
|
+
<TextOverflow ShowType={LegendType} type="ellipsis" value={displayName || name} style={{
|
|
209
|
+
...font,
|
|
210
|
+
fontStyle: italic ? 'italic' : 'normal',
|
|
211
|
+
fontWeight: bold ? 'bold' : 'normal',
|
|
212
|
+
minWidth:getCanvasTextWidth(displayName.substring(0,5) || name.substring(0,5),font.letterSpacing,`${font.fontSize}px ${font.fontFamily}` )
|
|
213
|
+
}} speed={speed}></TextOverflow>
|
|
214
|
+
|
|
215
|
+
</>
|
|
216
|
+
)}
|
|
217
|
+
</li>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
})}
|
|
221
|
+
</ul>
|
|
222
|
+
))
|
|
223
|
+
}
|
|
156
224
|
</div>
|
|
157
225
|
);
|
|
158
226
|
}
|
|
@@ -188,3 +256,10 @@ const getPosition = (position, alignment, x = 0, y = 0) => {
|
|
|
188
256
|
};
|
|
189
257
|
}
|
|
190
258
|
};
|
|
259
|
+
const getCanvasTextWidth=(text,letterSpacing, font = '16px Arial')=>{
|
|
260
|
+
const canvas = document.createElement('canvas');
|
|
261
|
+
const ctx = canvas.getContext('2d');
|
|
262
|
+
ctx.font = font;
|
|
263
|
+
return ctx.measureText(text).width+(text.length)*letterSpacing+"px";
|
|
264
|
+
// return ctx.measureText(text).width+(text.length-1)*letterSpacing+"px";//-1有bug
|
|
265
|
+
}
|
|
@@ -31,8 +31,11 @@ export default (Component) =>
|
|
|
31
31
|
if (!!data.length) {
|
|
32
32
|
const seriesLength = series.length;
|
|
33
33
|
const noName = series.every(({ fieldName }) => !fieldName);
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const lastSeries = series[seriesLength - 1];
|
|
35
|
+
const tmp = new Map(series.filter(d=>d.fieldName).map(d=>[d.fieldName,{}])); //确定的系列样式
|
|
36
|
+
let i = 0;
|
|
37
|
+
const emptyArray = series.filter(d=>!d.fieldName); //没有fieldsName的系列样式
|
|
38
|
+
if (!!noName) {//都没名
|
|
36
39
|
data.forEach(({ key }, index) => {
|
|
37
40
|
const current = series[index % seriesLength];
|
|
38
41
|
const name = key || '';
|
|
@@ -43,10 +46,10 @@ export default (Component) =>
|
|
|
43
46
|
});
|
|
44
47
|
return tmp;
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
data.forEach(({ key }) => {
|
|
49
|
+
data.forEach(({ key }) => {//先把有系列的渲染了,无系列的排后面
|
|
48
50
|
const current = series.find(({ fieldName }) => fieldName == key);
|
|
49
|
-
const result = current || lastSeries;
|
|
51
|
+
const result = current || emptyArray[i]|| lastSeries;
|
|
52
|
+
if(!current) i=(i+1)%emptyArray.length;
|
|
50
53
|
const name = (current ? current.fieldName || current.displayName : key) || '';
|
|
51
54
|
tmp.set(name, {
|
|
52
55
|
...result,
|
|
@@ -7,10 +7,10 @@ export default (Component) => {
|
|
|
7
7
|
return memo(({ config: { series, ...config }, data, ...props }) => {
|
|
8
8
|
const _config = useStackData({
|
|
9
9
|
series,
|
|
10
|
-
data
|
|
10
|
+
data
|
|
11
11
|
});
|
|
12
12
|
return (
|
|
13
|
-
<Component {...props} config={{ ...config, ..._config }} data={data} />
|
|
13
|
+
<Component {...props} config={{ ...config, ..._config }} data={data} seriesData={_config.seriesdata} />
|
|
14
14
|
);
|
|
15
15
|
});
|
|
16
16
|
};
|
|
@@ -10,7 +10,8 @@ interface flowText{
|
|
|
10
10
|
value:string,
|
|
11
11
|
speed:number,
|
|
12
12
|
style:CSSProperties,
|
|
13
|
-
config?:any
|
|
13
|
+
config?:any,
|
|
14
|
+
ShowType:string
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export default memo(forwardRef((props:flowText, ref:any) => {
|
|
@@ -19,7 +20,8 @@ export default memo(forwardRef((props:flowText, ref:any) => {
|
|
|
19
20
|
value, // 文本
|
|
20
21
|
style, // 样式
|
|
21
22
|
speed = 5, // 动画速度
|
|
22
|
-
config = {}
|
|
23
|
+
config = {},
|
|
24
|
+
ShowType
|
|
23
25
|
} = props;
|
|
24
26
|
const { needTitle = true } = config;
|
|
25
27
|
|
|
@@ -60,6 +62,7 @@ export default memo(forwardRef((props:flowText, ref:any) => {
|
|
|
60
62
|
style={styles}
|
|
61
63
|
ref={ref} />
|
|
62
64
|
) : (
|
|
63
|
-
<div style={styles
|
|
65
|
+
<div style={{...styles,
|
|
66
|
+
whiteSpace:ShowType=="Adaptive"?"normal":styles.whiteSpace}} ref={ref} title={needTitle && type=="ellipsis"?text || undefined:undefined} dangerouslySetInnerHTML={{__html:value}}></div>
|
|
64
67
|
);
|
|
65
68
|
}));
|
|
@@ -67,7 +67,42 @@ const setStackData = (data, series, stacks) => {
|
|
|
67
67
|
dataMap.clear();
|
|
68
68
|
return series;
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
const mergeDataAndSeries=(data, _series) =>{
|
|
71
|
+
// 创建一个映射,键为系列名称,值为数据点数组
|
|
72
|
+
const dataMap = new Map();
|
|
73
|
+
|
|
74
|
+
// 遍历 data 数组,按系列名称分组数据点
|
|
75
|
+
data.forEach(item => {
|
|
76
|
+
const seriesName = item.s;
|
|
77
|
+
if (!dataMap.has(seriesName)) {
|
|
78
|
+
dataMap.set(seriesName, []);
|
|
79
|
+
}
|
|
80
|
+
// 构建符合目标格式的数据点对象
|
|
81
|
+
const dataPoint = {
|
|
82
|
+
data: {
|
|
83
|
+
s: item.s,
|
|
84
|
+
x: item.x,
|
|
85
|
+
y: item.y,
|
|
86
|
+
showY: item.showY
|
|
87
|
+
},
|
|
88
|
+
index: 0,
|
|
89
|
+
bound: [0, item.y]
|
|
90
|
+
};
|
|
91
|
+
dataMap.get(seriesName).push(dataPoint);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// 遍历 _series 数组,为每个系列添加对应的数据
|
|
95
|
+
return _series.map(series => {
|
|
96
|
+
const seriesName = series.name || series.fieldName;
|
|
97
|
+
// 查找对应系列的数据
|
|
98
|
+
const seriesData = dataMap.get(seriesName) || [];
|
|
99
|
+
// 返回合并后完整的系列对象,包含原始配置和新添加的数据
|
|
100
|
+
return {
|
|
101
|
+
...series,
|
|
102
|
+
data: seriesData
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
71
106
|
/**
|
|
72
107
|
* 计算堆叠数据
|
|
73
108
|
* @param {Array} data 数据
|
|
@@ -81,13 +116,14 @@ export default ({ data, series }) => {
|
|
|
81
116
|
const _series = getSeriesMap(series);
|
|
82
117
|
return { stacks, series: seriesYOrZ(_series) };
|
|
83
118
|
}, [series]);
|
|
84
|
-
|
|
119
|
+
|
|
85
120
|
const _data = useMemo(() => dataYOrZ(data, _series.series), [data, _series]);
|
|
86
121
|
const tmp = useMemo(() => {
|
|
122
|
+
const seriesdata=mergeDataAndSeries(data,Array.from(series.values()))
|
|
87
123
|
const { y: dataY, z: dataZ } = _data;
|
|
88
124
|
const {
|
|
89
125
|
stacks,
|
|
90
|
-
series: {
|
|
126
|
+
series: { z: seriesZ,y: seriesY },
|
|
91
127
|
} = _series;
|
|
92
128
|
resetStackData(seriesY);
|
|
93
129
|
resetStackData(seriesZ);
|
|
@@ -95,7 +131,9 @@ export default ({ data, series }) => {
|
|
|
95
131
|
setStackData(dataZ, seriesZ, stacks);
|
|
96
132
|
return {
|
|
97
133
|
bandLength: stacks.filter((item) => item.type == 'band').length,
|
|
134
|
+
// series: mergeDataAndSeries(data,Array.from(series.values())),
|
|
98
135
|
series: [...seriesY.values(), ...seriesZ.values()],
|
|
136
|
+
seriesdata:seriesdata
|
|
99
137
|
};
|
|
100
138
|
}, [_data, _series]);
|
|
101
139
|
return tmp;
|