@easyv/charts 1.8.13 → 1.8.15
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/Band.js +356 -356
- package/lib/components/Label.js +356 -356
- package/lib/components/Legend.js +312 -312
- package/lib/components/PieChart.js +12 -4
- package/lib/components/pieTooltip.js +202 -202
- package/lib/utils/index.js +822 -822
- package/package.json +1 -1
- package/src/components/Carousel.tsx +72 -55
- package/src/components/PieChart.js +6 -3
package/lib/components/Legend.js
CHANGED
|
@@ -1,315 +1,315 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
14
|
-
var _utils = require("../utils");
|
|
15
|
-
var _TextOverflow = _interopRequireDefault(require("./TextOverflow"));
|
|
16
|
-
var _excluded = ["italic", "bold"];
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
14
|
+
var _utils = require("../utils");
|
|
15
|
+
var _TextOverflow = _interopRequireDefault(require("./TextOverflow"));
|
|
16
|
+
var _excluded = ["italic", "bold"];
|
|
17
17
|
/**
|
|
18
18
|
* 图例
|
|
19
|
-
*/
|
|
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
|
-
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 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
|
-
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
|
-
var defaultFont = {
|
|
25
|
-
fontStyle: 'normal',
|
|
26
|
-
fontWeight: 'normal'
|
|
27
|
-
};
|
|
28
|
-
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
29
|
-
var _config$value, _config$percent, _config$value2, _config$value3, _config$name;
|
|
30
|
-
var series = _ref.series,
|
|
31
|
-
height = _ref.height,
|
|
32
|
-
config = _ref.config,
|
|
33
|
-
_ref$config = _ref.config,
|
|
34
|
-
show = _ref$config.show,
|
|
35
|
-
_ref$config$order = _ref$config.order,
|
|
36
|
-
order = _ref$config$order === void 0 ? '' : _ref$config$order,
|
|
37
|
-
interactive = _ref$config.interactive,
|
|
38
|
-
LegendType = _ref$config.LegendType,
|
|
39
|
-
maxWidth = _ref$config.maxWidth,
|
|
40
|
-
textOverflow = _ref$config.textOverflow,
|
|
41
|
-
speed = _ref$config.speed,
|
|
42
|
-
_ref$config$layout = _ref$config.layout,
|
|
43
|
-
_ref$config$layout$al = _ref$config$layout.alignment,
|
|
44
|
-
alignment = _ref$config$layout$al === void 0 ? 'right center' : _ref$config$layout$al,
|
|
45
|
-
gridTemplateColumns = _ref$config$layout.gridTemplateColumns,
|
|
46
|
-
_ref$config$layout$gr = _ref$config$layout.gridGap,
|
|
47
|
-
gridColumnGap = _ref$config$layout$gr.gridColumnGap,
|
|
48
|
-
gridRowGap = _ref$config$layout$gr.gridRowGap,
|
|
49
|
-
_ref$config$layout$tr = _ref$config$layout.translate,
|
|
50
|
-
x = _ref$config$layout$tr.x,
|
|
51
|
-
y = _ref$config$layout$tr.y,
|
|
52
|
-
_ref$config$loop = _ref$config.loop,
|
|
53
|
-
loop = _ref$config$loop === void 0 ? {} : _ref$config$loop,
|
|
54
|
-
_ref$config$font = _ref$config.font,
|
|
55
|
-
_ref$config$font2 = _ref$config$font === void 0 ? defaultFont : _ref$config$font,
|
|
56
|
-
italic = _ref$config$font2.italic,
|
|
57
|
-
bold = _ref$config$font2.bold,
|
|
58
|
-
font = (0, _objectWithoutProperties2["default"])(_ref$config$font2, _excluded),
|
|
59
|
-
_ref$config$unselect = _ref$config.unselect,
|
|
60
|
-
_ref$config$unselect2 = _ref$config$unselect === void 0 ? {} : _ref$config$unselect,
|
|
61
|
-
_ref$config$unselect3 = _ref$config$unselect2.opacity,
|
|
62
|
-
opacity = _ref$config$unselect3 === void 0 ? 1 : _ref$config$unselect3,
|
|
63
|
-
filterData = _ref.filterData,
|
|
64
|
-
formatter = _ref.formatter,
|
|
65
|
-
judge = _ref.judge;
|
|
66
|
-
if (!show) return null;
|
|
67
|
-
var ref_container = (0, _react.useRef)(null); // 滚动容器
|
|
68
|
-
var ref_scrollTop = (0, _react.useRef)(0); // 当前滚动距离
|
|
69
|
-
|
|
70
|
-
var _useState = (0, _react.useState)(0),
|
|
71
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
72
|
-
scrollStep = _useState2[0],
|
|
73
|
-
setScrollStep = _useState2[1]; // 行高度
|
|
74
|
-
|
|
75
|
-
// 初始化行高
|
|
76
|
-
(0, _react.useEffect)(function () {
|
|
77
|
-
if (ref_container.current) {
|
|
78
|
-
var rowHeight = ref_container.current.querySelector('li').clientHeight + gridRowGap;
|
|
79
|
-
setScrollStep(rowHeight);
|
|
80
|
-
}
|
|
81
|
-
}, [gridRowGap]);
|
|
82
|
-
|
|
83
|
-
// 启动自动滚动定时器
|
|
84
|
-
(0, _react.useEffect)(function () {
|
|
85
|
-
if (!loop.show) return;
|
|
86
|
-
ref_scrollTop.current = 0;
|
|
87
|
-
var timer = setInterval(function () {
|
|
88
|
-
handleAutoScroll();
|
|
89
|
-
}, loop.interval * 1000); // 每隔3秒滚动一次
|
|
90
|
-
|
|
91
|
-
// 清除定时器
|
|
92
|
-
return function () {
|
|
93
|
-
return clearInterval(timer);
|
|
94
|
-
};
|
|
95
|
-
}, [scrollStep, loop.show, loop.interval]);
|
|
96
|
-
var handleAutoScroll = function handleAutoScroll() {
|
|
97
|
-
var table = ref_container.current;
|
|
98
|
-
if (!table) return;
|
|
99
|
-
|
|
100
|
-
// 如果已经滚动到了底部,则返回顶部
|
|
101
|
-
if (ref_scrollTop.current + table.clientHeight >= table.scrollHeight) {
|
|
102
|
-
ref_scrollTop.current = 0;
|
|
103
|
-
} else {
|
|
104
|
-
// 否则,滚动一行的高度
|
|
105
|
-
ref_scrollTop.current += scrollStep;
|
|
106
|
-
}
|
|
107
|
-
table.scrollTo({
|
|
108
|
-
top: ref_scrollTop.current,
|
|
109
|
-
behavior: 'smooth'
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
var _series = (0, _utils.sortPie)(series, order);
|
|
113
|
-
var _alignment$split = alignment.split(' '),
|
|
114
|
-
_alignment$split2 = (0, _slicedToArray2["default"])(_alignment$split, 2),
|
|
115
|
-
_alignment = _alignment$split2[0],
|
|
116
|
-
position = _alignment$split2[1];
|
|
117
|
-
var length = _series.length;
|
|
118
|
-
var onClick = (0, _react.useCallback)(function (e) {
|
|
119
|
-
var dataset = e.currentTarget.dataset;
|
|
120
|
-
var name = dataset.name;
|
|
121
|
-
filterData && interactive && filterData(name);
|
|
122
|
-
}, [interactive, filterData]);
|
|
123
|
-
if (judge == 0) {
|
|
124
|
-
_series.forEach(function (d) {
|
|
125
|
-
d.percent = 0;
|
|
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;
|
|
151
|
-
var stylePieOrAxis = formatter ? _objectSpread(_objectSpread({
|
|
152
|
-
display: 'flex',
|
|
153
|
-
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",
|
|
154
|
-
flexDirection: "column",
|
|
155
|
-
position: 'absolute'
|
|
156
|
-
}, getPosition(position, _alignment, x, y)), {}, {
|
|
157
|
-
height: loop.show ? height : 'auto',
|
|
158
|
-
overflowY: loop.show ? 'scroll' : 'auto'
|
|
159
|
-
}) : _objectSpread(_objectSpread({
|
|
160
|
-
display: 'flex',
|
|
161
|
-
flexWrap: "wrap",
|
|
162
|
-
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",
|
|
163
|
-
flexDirection: "column",
|
|
164
|
-
position: 'absolute'
|
|
165
|
-
}, getPosition(position, _alignment, x, y)), {}, {
|
|
166
|
-
height: loop.show ? height : 'auto',
|
|
167
|
-
overflowY: loop.show ? 'scroll' : 'auto'
|
|
168
|
-
});
|
|
169
|
-
return LegendType == "FixedWidth" ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
170
|
-
className: "__easyv-legend-wrapper",
|
|
171
|
-
style: _objectSpread(_objectSpread({
|
|
172
|
-
position: 'absolute',
|
|
173
|
-
display: 'flex'
|
|
174
|
-
}, getPosition(position, _alignment, x, y)), {}, {
|
|
175
|
-
height: loop.show ? height : 'auto',
|
|
176
|
-
overflowY: loop.show ? 'scroll' : 'auto'
|
|
177
|
-
}),
|
|
178
|
-
ref: ref_container
|
|
179
|
-
}, /*#__PURE__*/_react["default"].createElement("ul", {
|
|
180
|
-
style: {
|
|
181
|
-
display: 'grid',
|
|
182
|
-
gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
|
|
183
|
-
gridTemplateColumns: formatter ? "".concat(nameMaxWidth, "px ").concat(valueMaxWidth, "px ").concat(percentMaxWidth, "px") : 'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)' //饼图或者柱状图配合不同的图例显示格式
|
|
184
|
-
}
|
|
185
|
-
}, _series.map(function (series, index) {
|
|
186
|
-
var _series$config;
|
|
187
|
-
var type = series.type,
|
|
188
|
-
name = series.name,
|
|
189
|
-
displayName = series.displayName,
|
|
190
|
-
icon = series.icon,
|
|
191
|
-
selected = series.selected;
|
|
192
|
-
var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config = series.config) === null || _series$config === void 0 || (_series$config = _series$config.line) === null || _series$config === void 0 ? void 0 : _series$config.type);
|
|
193
|
-
return /*#__PURE__*/_react["default"].createElement("li", {
|
|
194
|
-
key: index,
|
|
195
|
-
onClick: onClick,
|
|
196
|
-
"data-name": name,
|
|
197
|
-
style: {
|
|
198
|
-
display: 'flex',
|
|
199
|
-
opacity: selected === false ? opacity / 100 : 1,
|
|
200
|
-
alignItems: 'center',
|
|
201
|
-
cursor: "pointer",
|
|
202
|
-
gap: _icon.gap
|
|
203
|
-
}
|
|
204
|
-
}, formatter ? formatter(series, _objectSpread(_objectSpread({}, config), {}, {
|
|
205
|
-
valueMaxWidth: valueMaxWidth,
|
|
206
|
-
percentMaxWidth: percentMaxWidth,
|
|
207
|
-
nameMaxWidth: nameMaxWidth
|
|
208
|
-
})) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
209
|
-
style: _icon
|
|
210
|
-
}), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
|
|
211
|
-
type: textOverflow,
|
|
212
|
-
value: displayName || name,
|
|
213
|
-
style: _objectSpread(_objectSpread({}, font), {}, {
|
|
214
|
-
width: maxWidth,
|
|
215
|
-
fontStyle: italic ? 'italic' : 'normal',
|
|
216
|
-
fontWeight: bold ? 'bold' : 'normal'
|
|
217
|
-
}),
|
|
218
|
-
speed: speed
|
|
219
|
-
})));
|
|
220
|
-
}))) : /*#__PURE__*/_react["default"].createElement("div", {
|
|
221
|
-
className: "__easyv-legend-wrapper",
|
|
222
|
-
style: stylePieOrAxis,
|
|
223
|
-
ref: ref_container
|
|
224
|
-
}, (0, _toConsumableArray2["default"])(Array(Math.ceil(series.length / gridTemplateColumns))).map(function (_, indexs) {
|
|
225
|
-
return /*#__PURE__*/_react["default"].createElement("ul", {
|
|
226
|
-
key: indexs,
|
|
227
|
-
style: (0, _defineProperty2["default"])({
|
|
228
|
-
display: 'flex',
|
|
229
|
-
width: 'fit-content',
|
|
230
|
-
justifyContent: alignment.split(" ")[0] == "left" ? "flex-start" : alignment.split(" ")[0] == "center" ? "center" : "flex-end",
|
|
231
|
-
marginBottom: "0px",
|
|
232
|
-
gap: "".concat(gridRowGap, "px ").concat(gridColumnGap, "px")
|
|
233
|
-
}, "marginBottom", gridRowGap + "px")
|
|
234
|
-
}, _series.map(function (series, index) {
|
|
235
|
-
if (Math.floor(index / gridTemplateColumns) == indexs) {
|
|
236
|
-
var _series$config2;
|
|
237
|
-
var type = series.type,
|
|
238
|
-
name = series.name,
|
|
239
|
-
displayName = series.displayName,
|
|
240
|
-
icon = series.icon,
|
|
241
|
-
selected = series.selected;
|
|
242
|
-
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);
|
|
243
|
-
return /*#__PURE__*/_react["default"].createElement("li", {
|
|
244
|
-
key: index,
|
|
245
|
-
onClick: onClick,
|
|
246
|
-
"data-name": name,
|
|
247
|
-
style: {
|
|
248
|
-
display: 'flex',
|
|
249
|
-
opacity: selected === false ? opacity / 100 : 1,
|
|
250
|
-
alignItems: 'center',
|
|
251
|
-
cursor: "pointer",
|
|
252
|
-
gap: _icon.gap
|
|
253
|
-
}
|
|
254
|
-
}, formatter ? formatter(series, _objectSpread(_objectSpread({}, config), {}, {
|
|
255
|
-
valueMaxWidth: valueMaxWidth,
|
|
256
|
-
percentMaxWidth: percentMaxWidth,
|
|
257
|
-
nameMaxWidth: nameMaxWidth
|
|
258
|
-
})) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
259
|
-
style: _icon
|
|
260
|
-
}), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
|
|
261
|
-
ShowType: LegendType,
|
|
262
|
-
type: "ellipsis",
|
|
263
|
-
value: displayName || name,
|
|
264
|
-
style: _objectSpread(_objectSpread({}, font), {}, {
|
|
265
|
-
fontStyle: italic ? 'italic' : 'normal',
|
|
266
|
-
fontWeight: bold ? 'bold' : 'normal',
|
|
267
|
-
minWidth: getCanvasTextWidth(displayName ? displayName.substring(0, 5) || name.substring(0, 5) : "", font.letterSpacing, "".concat(font.fontSize, "px ").concat(font.fontFamily))
|
|
268
|
-
}),
|
|
269
|
-
speed: speed
|
|
270
|
-
})));
|
|
271
|
-
}
|
|
272
|
-
}));
|
|
273
|
-
}));
|
|
274
|
-
});
|
|
275
|
-
var getPosition = function getPosition(position, alignment) {
|
|
276
|
-
var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
277
|
-
var y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
278
|
-
switch (position) {
|
|
279
|
-
case 'top':
|
|
280
|
-
return {
|
|
281
|
-
left: alignment == 'left' ? 5 : alignment == 'center' ? '50%' : '',
|
|
282
|
-
right: alignment == 'right' ? 10 : '',
|
|
283
|
-
top: 5,
|
|
284
|
-
transform: "translate3d(calc(".concat(alignment == 'center' ? '-50%' : '0px', " + ").concat(x, "px), ").concat(y, "px, 0px)")
|
|
285
|
-
};
|
|
286
|
-
case 'right':
|
|
287
|
-
return {
|
|
288
|
-
top: '50%',
|
|
289
|
-
right: 10,
|
|
290
|
-
transform: "translate3d(".concat(x, "px, calc(-50% + ").concat(y, "px), 0px)")
|
|
291
|
-
};
|
|
292
|
-
case 'left':
|
|
293
|
-
return {
|
|
294
|
-
top: '50%',
|
|
295
|
-
left: 5,
|
|
296
|
-
transform: "translate3d(".concat(x, "px, calc(-50% + ").concat(y, "px), 0px)")
|
|
297
|
-
};
|
|
298
|
-
default:
|
|
299
|
-
// bottom
|
|
300
|
-
return {
|
|
301
|
-
left: alignment == 'left' ? 5 : alignment == 'center' ? '50%' : '',
|
|
302
|
-
right: alignment == 'right' ? 10 : '',
|
|
303
|
-
bottom: 5,
|
|
304
|
-
transform: "translate3d(calc(".concat(alignment == 'center' ? '-50%' : '0px', " + ").concat(x, "px), ").concat(y, "px, 0px)")
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
var getCanvasTextWidth = function getCanvasTextWidth(text, letterSpacing) {
|
|
309
|
-
var font = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '16px Arial';
|
|
310
|
-
var canvas = document.createElement('canvas');
|
|
311
|
-
var ctx = canvas.getContext('2d');
|
|
312
|
-
ctx.font = font;
|
|
313
|
-
return ctx.measureText(text).width + text.length * letterSpacing + "px";
|
|
314
|
-
// return ctx.measureText(text).width+(text.length-1)*letterSpacing+"px";//-1有bug
|
|
19
|
+
*/
|
|
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
|
+
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 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
|
+
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
|
+
var defaultFont = {
|
|
25
|
+
fontStyle: 'normal',
|
|
26
|
+
fontWeight: 'normal'
|
|
27
|
+
};
|
|
28
|
+
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
29
|
+
var _config$value, _config$percent, _config$value2, _config$value3, _config$name;
|
|
30
|
+
var series = _ref.series,
|
|
31
|
+
height = _ref.height,
|
|
32
|
+
config = _ref.config,
|
|
33
|
+
_ref$config = _ref.config,
|
|
34
|
+
show = _ref$config.show,
|
|
35
|
+
_ref$config$order = _ref$config.order,
|
|
36
|
+
order = _ref$config$order === void 0 ? '' : _ref$config$order,
|
|
37
|
+
interactive = _ref$config.interactive,
|
|
38
|
+
LegendType = _ref$config.LegendType,
|
|
39
|
+
maxWidth = _ref$config.maxWidth,
|
|
40
|
+
textOverflow = _ref$config.textOverflow,
|
|
41
|
+
speed = _ref$config.speed,
|
|
42
|
+
_ref$config$layout = _ref$config.layout,
|
|
43
|
+
_ref$config$layout$al = _ref$config$layout.alignment,
|
|
44
|
+
alignment = _ref$config$layout$al === void 0 ? 'right center' : _ref$config$layout$al,
|
|
45
|
+
gridTemplateColumns = _ref$config$layout.gridTemplateColumns,
|
|
46
|
+
_ref$config$layout$gr = _ref$config$layout.gridGap,
|
|
47
|
+
gridColumnGap = _ref$config$layout$gr.gridColumnGap,
|
|
48
|
+
gridRowGap = _ref$config$layout$gr.gridRowGap,
|
|
49
|
+
_ref$config$layout$tr = _ref$config$layout.translate,
|
|
50
|
+
x = _ref$config$layout$tr.x,
|
|
51
|
+
y = _ref$config$layout$tr.y,
|
|
52
|
+
_ref$config$loop = _ref$config.loop,
|
|
53
|
+
loop = _ref$config$loop === void 0 ? {} : _ref$config$loop,
|
|
54
|
+
_ref$config$font = _ref$config.font,
|
|
55
|
+
_ref$config$font2 = _ref$config$font === void 0 ? defaultFont : _ref$config$font,
|
|
56
|
+
italic = _ref$config$font2.italic,
|
|
57
|
+
bold = _ref$config$font2.bold,
|
|
58
|
+
font = (0, _objectWithoutProperties2["default"])(_ref$config$font2, _excluded),
|
|
59
|
+
_ref$config$unselect = _ref$config.unselect,
|
|
60
|
+
_ref$config$unselect2 = _ref$config$unselect === void 0 ? {} : _ref$config$unselect,
|
|
61
|
+
_ref$config$unselect3 = _ref$config$unselect2.opacity,
|
|
62
|
+
opacity = _ref$config$unselect3 === void 0 ? 1 : _ref$config$unselect3,
|
|
63
|
+
filterData = _ref.filterData,
|
|
64
|
+
formatter = _ref.formatter,
|
|
65
|
+
judge = _ref.judge;
|
|
66
|
+
if (!show) return null;
|
|
67
|
+
var ref_container = (0, _react.useRef)(null); // 滚动容器
|
|
68
|
+
var ref_scrollTop = (0, _react.useRef)(0); // 当前滚动距离
|
|
69
|
+
|
|
70
|
+
var _useState = (0, _react.useState)(0),
|
|
71
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
72
|
+
scrollStep = _useState2[0],
|
|
73
|
+
setScrollStep = _useState2[1]; // 行高度
|
|
74
|
+
|
|
75
|
+
// 初始化行高
|
|
76
|
+
(0, _react.useEffect)(function () {
|
|
77
|
+
if (ref_container.current) {
|
|
78
|
+
var rowHeight = ref_container.current.querySelector('li').clientHeight + gridRowGap;
|
|
79
|
+
setScrollStep(rowHeight);
|
|
80
|
+
}
|
|
81
|
+
}, [gridRowGap]);
|
|
82
|
+
|
|
83
|
+
// 启动自动滚动定时器
|
|
84
|
+
(0, _react.useEffect)(function () {
|
|
85
|
+
if (!loop.show) return;
|
|
86
|
+
ref_scrollTop.current = 0;
|
|
87
|
+
var timer = setInterval(function () {
|
|
88
|
+
handleAutoScroll();
|
|
89
|
+
}, loop.interval * 1000); // 每隔3秒滚动一次
|
|
90
|
+
|
|
91
|
+
// 清除定时器
|
|
92
|
+
return function () {
|
|
93
|
+
return clearInterval(timer);
|
|
94
|
+
};
|
|
95
|
+
}, [scrollStep, loop.show, loop.interval]);
|
|
96
|
+
var handleAutoScroll = function handleAutoScroll() {
|
|
97
|
+
var table = ref_container.current;
|
|
98
|
+
if (!table) return;
|
|
99
|
+
|
|
100
|
+
// 如果已经滚动到了底部,则返回顶部
|
|
101
|
+
if (ref_scrollTop.current + table.clientHeight >= table.scrollHeight) {
|
|
102
|
+
ref_scrollTop.current = 0;
|
|
103
|
+
} else {
|
|
104
|
+
// 否则,滚动一行的高度
|
|
105
|
+
ref_scrollTop.current += scrollStep;
|
|
106
|
+
}
|
|
107
|
+
table.scrollTo({
|
|
108
|
+
top: ref_scrollTop.current,
|
|
109
|
+
behavior: 'smooth'
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
var _series = (0, _utils.sortPie)(series, order);
|
|
113
|
+
var _alignment$split = alignment.split(' '),
|
|
114
|
+
_alignment$split2 = (0, _slicedToArray2["default"])(_alignment$split, 2),
|
|
115
|
+
_alignment = _alignment$split2[0],
|
|
116
|
+
position = _alignment$split2[1];
|
|
117
|
+
var length = _series.length;
|
|
118
|
+
var onClick = (0, _react.useCallback)(function (e) {
|
|
119
|
+
var dataset = e.currentTarget.dataset;
|
|
120
|
+
var name = dataset.name;
|
|
121
|
+
filterData && interactive && filterData(name);
|
|
122
|
+
}, [interactive, filterData]);
|
|
123
|
+
if (judge == 0) {
|
|
124
|
+
_series.forEach(function (d) {
|
|
125
|
+
d.percent = 0;
|
|
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;
|
|
151
|
+
var stylePieOrAxis = formatter ? _objectSpread(_objectSpread({
|
|
152
|
+
display: 'flex',
|
|
153
|
+
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",
|
|
154
|
+
flexDirection: "column",
|
|
155
|
+
position: 'absolute'
|
|
156
|
+
}, getPosition(position, _alignment, x, y)), {}, {
|
|
157
|
+
height: loop.show ? height : 'auto',
|
|
158
|
+
overflowY: loop.show ? 'scroll' : 'auto'
|
|
159
|
+
}) : _objectSpread(_objectSpread({
|
|
160
|
+
display: 'flex',
|
|
161
|
+
flexWrap: "wrap",
|
|
162
|
+
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",
|
|
163
|
+
flexDirection: "column",
|
|
164
|
+
position: 'absolute'
|
|
165
|
+
}, getPosition(position, _alignment, x, y)), {}, {
|
|
166
|
+
height: loop.show ? height : 'auto',
|
|
167
|
+
overflowY: loop.show ? 'scroll' : 'auto'
|
|
168
|
+
});
|
|
169
|
+
return LegendType == "FixedWidth" ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
170
|
+
className: "__easyv-legend-wrapper",
|
|
171
|
+
style: _objectSpread(_objectSpread({
|
|
172
|
+
position: 'absolute',
|
|
173
|
+
display: 'flex'
|
|
174
|
+
}, getPosition(position, _alignment, x, y)), {}, {
|
|
175
|
+
height: loop.show ? height : 'auto',
|
|
176
|
+
overflowY: loop.show ? 'scroll' : 'auto'
|
|
177
|
+
}),
|
|
178
|
+
ref: ref_container
|
|
179
|
+
}, /*#__PURE__*/_react["default"].createElement("ul", {
|
|
180
|
+
style: {
|
|
181
|
+
display: 'grid',
|
|
182
|
+
gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
|
|
183
|
+
gridTemplateColumns: formatter ? "".concat(nameMaxWidth, "px ").concat(valueMaxWidth, "px ").concat(percentMaxWidth, "px") : 'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)' //饼图或者柱状图配合不同的图例显示格式
|
|
184
|
+
}
|
|
185
|
+
}, _series.map(function (series, index) {
|
|
186
|
+
var _series$config;
|
|
187
|
+
var type = series.type,
|
|
188
|
+
name = series.name,
|
|
189
|
+
displayName = series.displayName,
|
|
190
|
+
icon = series.icon,
|
|
191
|
+
selected = series.selected;
|
|
192
|
+
var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config = series.config) === null || _series$config === void 0 || (_series$config = _series$config.line) === null || _series$config === void 0 ? void 0 : _series$config.type);
|
|
193
|
+
return /*#__PURE__*/_react["default"].createElement("li", {
|
|
194
|
+
key: index,
|
|
195
|
+
onClick: onClick,
|
|
196
|
+
"data-name": name,
|
|
197
|
+
style: {
|
|
198
|
+
display: 'flex',
|
|
199
|
+
opacity: selected === false ? opacity / 100 : 1,
|
|
200
|
+
alignItems: 'center',
|
|
201
|
+
cursor: "pointer",
|
|
202
|
+
gap: _icon.gap
|
|
203
|
+
}
|
|
204
|
+
}, formatter ? formatter(series, _objectSpread(_objectSpread({}, config), {}, {
|
|
205
|
+
valueMaxWidth: valueMaxWidth,
|
|
206
|
+
percentMaxWidth: percentMaxWidth,
|
|
207
|
+
nameMaxWidth: nameMaxWidth
|
|
208
|
+
})) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
209
|
+
style: _icon
|
|
210
|
+
}), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
|
|
211
|
+
type: textOverflow,
|
|
212
|
+
value: displayName || name,
|
|
213
|
+
style: _objectSpread(_objectSpread({}, font), {}, {
|
|
214
|
+
width: maxWidth,
|
|
215
|
+
fontStyle: italic ? 'italic' : 'normal',
|
|
216
|
+
fontWeight: bold ? 'bold' : 'normal'
|
|
217
|
+
}),
|
|
218
|
+
speed: speed
|
|
219
|
+
})));
|
|
220
|
+
}))) : /*#__PURE__*/_react["default"].createElement("div", {
|
|
221
|
+
className: "__easyv-legend-wrapper",
|
|
222
|
+
style: stylePieOrAxis,
|
|
223
|
+
ref: ref_container
|
|
224
|
+
}, (0, _toConsumableArray2["default"])(Array(Math.ceil(series.length / gridTemplateColumns))).map(function (_, indexs) {
|
|
225
|
+
return /*#__PURE__*/_react["default"].createElement("ul", {
|
|
226
|
+
key: indexs,
|
|
227
|
+
style: (0, _defineProperty2["default"])({
|
|
228
|
+
display: 'flex',
|
|
229
|
+
width: 'fit-content',
|
|
230
|
+
justifyContent: alignment.split(" ")[0] == "left" ? "flex-start" : alignment.split(" ")[0] == "center" ? "center" : "flex-end",
|
|
231
|
+
marginBottom: "0px",
|
|
232
|
+
gap: "".concat(gridRowGap, "px ").concat(gridColumnGap, "px")
|
|
233
|
+
}, "marginBottom", gridRowGap + "px")
|
|
234
|
+
}, _series.map(function (series, index) {
|
|
235
|
+
if (Math.floor(index / gridTemplateColumns) == indexs) {
|
|
236
|
+
var _series$config2;
|
|
237
|
+
var type = series.type,
|
|
238
|
+
name = series.name,
|
|
239
|
+
displayName = series.displayName,
|
|
240
|
+
icon = series.icon,
|
|
241
|
+
selected = series.selected;
|
|
242
|
+
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);
|
|
243
|
+
return /*#__PURE__*/_react["default"].createElement("li", {
|
|
244
|
+
key: index,
|
|
245
|
+
onClick: onClick,
|
|
246
|
+
"data-name": name,
|
|
247
|
+
style: {
|
|
248
|
+
display: 'flex',
|
|
249
|
+
opacity: selected === false ? opacity / 100 : 1,
|
|
250
|
+
alignItems: 'center',
|
|
251
|
+
cursor: "pointer",
|
|
252
|
+
gap: _icon.gap
|
|
253
|
+
}
|
|
254
|
+
}, formatter ? formatter(series, _objectSpread(_objectSpread({}, config), {}, {
|
|
255
|
+
valueMaxWidth: valueMaxWidth,
|
|
256
|
+
percentMaxWidth: percentMaxWidth,
|
|
257
|
+
nameMaxWidth: nameMaxWidth
|
|
258
|
+
})) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
259
|
+
style: _icon
|
|
260
|
+
}), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
|
|
261
|
+
ShowType: LegendType,
|
|
262
|
+
type: "ellipsis",
|
|
263
|
+
value: displayName || name,
|
|
264
|
+
style: _objectSpread(_objectSpread({}, font), {}, {
|
|
265
|
+
fontStyle: italic ? 'italic' : 'normal',
|
|
266
|
+
fontWeight: bold ? 'bold' : 'normal',
|
|
267
|
+
minWidth: getCanvasTextWidth(displayName ? displayName.substring(0, 5) || name.substring(0, 5) : "", font.letterSpacing, "".concat(font.fontSize, "px ").concat(font.fontFamily))
|
|
268
|
+
}),
|
|
269
|
+
speed: speed
|
|
270
|
+
})));
|
|
271
|
+
}
|
|
272
|
+
}));
|
|
273
|
+
}));
|
|
274
|
+
});
|
|
275
|
+
var getPosition = function getPosition(position, alignment) {
|
|
276
|
+
var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
277
|
+
var y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
278
|
+
switch (position) {
|
|
279
|
+
case 'top':
|
|
280
|
+
return {
|
|
281
|
+
left: alignment == 'left' ? 5 : alignment == 'center' ? '50%' : '',
|
|
282
|
+
right: alignment == 'right' ? 10 : '',
|
|
283
|
+
top: 5,
|
|
284
|
+
transform: "translate3d(calc(".concat(alignment == 'center' ? '-50%' : '0px', " + ").concat(x, "px), ").concat(y, "px, 0px)")
|
|
285
|
+
};
|
|
286
|
+
case 'right':
|
|
287
|
+
return {
|
|
288
|
+
top: '50%',
|
|
289
|
+
right: 10,
|
|
290
|
+
transform: "translate3d(".concat(x, "px, calc(-50% + ").concat(y, "px), 0px)")
|
|
291
|
+
};
|
|
292
|
+
case 'left':
|
|
293
|
+
return {
|
|
294
|
+
top: '50%',
|
|
295
|
+
left: 5,
|
|
296
|
+
transform: "translate3d(".concat(x, "px, calc(-50% + ").concat(y, "px), 0px)")
|
|
297
|
+
};
|
|
298
|
+
default:
|
|
299
|
+
// bottom
|
|
300
|
+
return {
|
|
301
|
+
left: alignment == 'left' ? 5 : alignment == 'center' ? '50%' : '',
|
|
302
|
+
right: alignment == 'right' ? 10 : '',
|
|
303
|
+
bottom: 5,
|
|
304
|
+
transform: "translate3d(calc(".concat(alignment == 'center' ? '-50%' : '0px', " + ").concat(x, "px), ").concat(y, "px, 0px)")
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
var getCanvasTextWidth = function getCanvasTextWidth(text, letterSpacing) {
|
|
309
|
+
var font = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '16px Arial';
|
|
310
|
+
var canvas = document.createElement('canvas');
|
|
311
|
+
var ctx = canvas.getContext('2d');
|
|
312
|
+
ctx.font = font;
|
|
313
|
+
return ctx.measureText(text).width + text.length * letterSpacing + "px";
|
|
314
|
+
// return ctx.measureText(text).width+(text.length-1)*letterSpacing+"px";//-1有bug
|
|
315
315
|
};
|