onesight-charts 1.4.5 → 1.4.6
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/dist/onesight-charts.min.js +1 -1
- package/es/components/custom-line/index.js +14 -11
- package/es/components/custom-line/tooltipConfig.js +8 -3
- package/es/components/line/index.js +14 -11
- package/es/components/line/tooltipConfig.js +8 -3
- package/es/components/standard-custom-line/index.js +14 -4
- package/es/components/standard-custom-line/tooltipConfig.js +8 -3
- package/es/components/standard-line/index.js +14 -11
- package/es/components/standard-line/tooltipConfig.js +8 -3
- package/es/utils/chartUtils.js +79 -1
- package/lib/components/custom-line/index.js +14 -11
- package/lib/components/custom-line/tooltipConfig.js +11 -2
- package/lib/components/line/index.js +14 -11
- package/lib/components/line/tooltipConfig.js +11 -2
- package/lib/components/standard-custom-line/index.js +18 -4
- package/lib/components/standard-custom-line/tooltipConfig.js +11 -2
- package/lib/components/standard-line/index.js +14 -11
- package/lib/components/standard-line/tooltipConfig.js +11 -2
- package/lib/utils/chartUtils.js +71 -0
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
13
13
|
import * as echarts from 'echarts';
|
|
14
14
|
import moment from 'moment';
|
|
15
15
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
16
|
-
import { calculateSeriesTotal, convertSeriesData, dealPath, isZH, numberFormatMust, numberFormatNull } from "../../utils/chartUtils";
|
|
16
|
+
import { calculateSeriesTotal, canvasEllipsisMiddle, convertSeriesData, dealPath, isZH, numberFormatMust, numberFormatNull } from "../../utils/chartUtils";
|
|
17
17
|
import { defaultChartColors } from "../../utils/colors";
|
|
18
18
|
import { createCustomTooltip } from "./tooltipConfig";
|
|
19
19
|
import "./style.scss";
|
|
@@ -50,7 +50,11 @@ function CustomLine(props) {
|
|
|
50
50
|
_props$legendDropdown = props.legendDropdownRight,
|
|
51
51
|
legendDropdownRight = _props$legendDropdown === void 0 ? -98 : _props$legendDropdown,
|
|
52
52
|
_props$showAllLegends = props.showAllLegends,
|
|
53
|
-
showAllLegends = _props$showAllLegends === void 0 ? false : _props$showAllLegends
|
|
53
|
+
showAllLegends = _props$showAllLegends === void 0 ? false : _props$showAllLegends,
|
|
54
|
+
_props$legendNameMaxW = props.legendNameMaxWidth,
|
|
55
|
+
legendNameMaxWidth = _props$legendNameMaxW === void 0 ? 120 : _props$legendNameMaxW,
|
|
56
|
+
_props$tooltipNameMax = props.tooltipNameMaxWidth,
|
|
57
|
+
tooltipNameMaxWidth = _props$tooltipNameMax === void 0 ? 140 : _props$tooltipNameMax;
|
|
54
58
|
var chartRef = useRef(null);
|
|
55
59
|
// 存储上一次的依赖项值,用于深度比较
|
|
56
60
|
var prevDepsRef = useRef(null);
|
|
@@ -259,7 +263,9 @@ function CustomLine(props) {
|
|
|
259
263
|
isTotalShow: isTotalShow,
|
|
260
264
|
xAxis: xAxis,
|
|
261
265
|
// 传入原始 xAxis 数据
|
|
262
|
-
tooltipYOffset: tooltipYOffset
|
|
266
|
+
tooltipYOffset: tooltipYOffset,
|
|
267
|
+
// y 方向偏移量
|
|
268
|
+
tooltipNameMaxWidth: tooltipNameMaxWidth // tooltip 名称最大宽度
|
|
263
269
|
});
|
|
264
270
|
var option = {
|
|
265
271
|
legend: {
|
|
@@ -275,14 +281,11 @@ function CustomLine(props) {
|
|
|
275
281
|
itemGap: 8,
|
|
276
282
|
formatter: function formatter(name) {
|
|
277
283
|
var value = legendValue ? numberFormatMust(seriesTotal[name] || 0) : 0;
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return legendValue ? "{labelName|".concat(showName, "}\n{labelMark|").concat(value, "}") : "{labelName|".concat(showName, "}");
|
|
284
|
+
var ellipsisName = canvasEllipsisMiddle(name, legendNameMaxWidth, {
|
|
285
|
+
fontSize: 12,
|
|
286
|
+
fontWeight: 500
|
|
287
|
+
});
|
|
288
|
+
return legendValue ? "{labelName|".concat(ellipsisName, "}\n{labelMark|").concat(value, "}") : "{labelName|".concat(ellipsisName, "}");
|
|
286
289
|
},
|
|
287
290
|
textStyle: {
|
|
288
291
|
fontWeight: 500,
|
|
@@ -6,7 +6,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
6
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
7
|
import moment from 'moment';
|
|
8
8
|
import 'moment/locale/zh-cn';
|
|
9
|
-
import { changeDataTypeEn, computeFloatNull, computePos, isZH } from "../../utils/chartUtils";
|
|
9
|
+
import { canvasEllipsisMiddle, changeDataTypeEn, computeFloatNull, computePos, isZH } from "../../utils/chartUtils";
|
|
10
10
|
var formatToolTipDate = function formatToolTipDate(value) {
|
|
11
11
|
// 根据语言环境设置 moment 的 locale
|
|
12
12
|
var locale = isZH() ? 'zh-cn' : 'en';
|
|
@@ -29,7 +29,9 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
29
29
|
isTotalShow = _ref.isTotalShow,
|
|
30
30
|
xAxis = _ref.xAxis,
|
|
31
31
|
_ref$tooltipYOffset = _ref.tooltipYOffset,
|
|
32
|
-
tooltipYOffset = _ref$tooltipYOffset === void 0 ? -4 : _ref$tooltipYOffset
|
|
32
|
+
tooltipYOffset = _ref$tooltipYOffset === void 0 ? -4 : _ref$tooltipYOffset,
|
|
33
|
+
_ref$tooltipNameMaxWi = _ref.tooltipNameMaxWidth,
|
|
34
|
+
tooltipNameMaxWidth = _ref$tooltipNameMaxWi === void 0 ? 140 : _ref$tooltipNameMaxWi;
|
|
33
35
|
return {
|
|
34
36
|
className: "onesight-line-tooltip ".concat(tooltipClassName),
|
|
35
37
|
trigger: 'axis',
|
|
@@ -106,7 +108,10 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
106
108
|
marginRight = 3;
|
|
107
109
|
}
|
|
108
110
|
return "\n <div class='tooltip-wrap'>\n <div class='tooltip-head'>\n ".concat(formatToolTipDate(originalDate), "\n </div>\n <div class='tooltip-body' style=\"margin-right:").concat(marginRight, "px\">\n ").concat(dataArr.length > 1 && isTotalShow ? "\n <div class='total'>\n <div class='l'>\n ".concat(tooltipTotalName, "\n </div>\n <div class='r'>\n ").concat(changeDataTypeEn(total), "\n </div>\n </div>\n ") : '', "\n ").concat(dataArr.map(function (item) {
|
|
109
|
-
return "\n <div class='item' data-series-item='".concat(JSON.stringify(item), "' key='").concat(item.seriesName, "'>\n <div class='l'>\n <span class='l-color' style=\"background-color:").concat(item.color, "\"></span>\n <span>\n ").concat(item.seriesName,
|
|
111
|
+
return "\n <div class='item' data-series-item='".concat(JSON.stringify(item), "' key='").concat(item.seriesName, "'>\n <div class='l'>\n <span class='l-color' style=\"background-color:").concat(item.color, "\"></span>\n <span>\n ").concat(canvasEllipsisMiddle(item.seriesName, tooltipNameMaxWidth, {
|
|
112
|
+
fontSize: 14,
|
|
113
|
+
fontWeight: 400
|
|
114
|
+
}), "\n </span>\n </div>\n <div class='r'>\n ").concat(dataArr.length > 1 && showRate ? "<span class='rate'>(".concat(computeFloatNull(item.proportion), ")</span>") : '', "\n <span class='num'>\n ").concat(changeDataTypeEn(item.value), "\n </span>\n </div> \n </div>\n ");
|
|
110
115
|
}).join(''), "\n </div>\n ").concat(tooltipPosition ? '<div class="triangle-down"></div>' : '', "\n </div>\n ");
|
|
111
116
|
}
|
|
112
117
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as echarts from 'echarts';
|
|
2
2
|
import moment from 'moment';
|
|
3
3
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
4
|
-
import { calculateSeriesTotal, convertSeriesData, dealPath, isZH, numberFormatMust, numberFormatNull, toggleAxisPointer } from "../../utils/chartUtils";
|
|
4
|
+
import { calculateSeriesTotal, canvasEllipsisMiddle, convertSeriesData, dealPath, isZH, numberFormatMust, numberFormatNull, toggleAxisPointer } from "../../utils/chartUtils";
|
|
5
5
|
import { defaultChartColors } from "../../utils/colors";
|
|
6
6
|
import { createCustomTooltip } from "./tooltipConfig";
|
|
7
7
|
import "./style.scss";
|
|
@@ -39,7 +39,11 @@ function Line(props) {
|
|
|
39
39
|
_props$yAxisScale = props.yAxisScale,
|
|
40
40
|
yAxisScale = _props$yAxisScale === void 0 ? true : _props$yAxisScale,
|
|
41
41
|
_props$showAllLegends = props.showAllLegends,
|
|
42
|
-
showAllLegends = _props$showAllLegends === void 0 ? false : _props$showAllLegends
|
|
42
|
+
showAllLegends = _props$showAllLegends === void 0 ? false : _props$showAllLegends,
|
|
43
|
+
_props$legendNameMaxW = props.legendNameMaxWidth,
|
|
44
|
+
legendNameMaxWidth = _props$legendNameMaxW === void 0 ? 120 : _props$legendNameMaxW,
|
|
45
|
+
_props$tooltipNameMax = props.tooltipNameMaxWidth,
|
|
46
|
+
tooltipNameMaxWidth = _props$tooltipNameMax === void 0 ? 140 : _props$tooltipNameMax;
|
|
43
47
|
var chartRef = useRef(null);
|
|
44
48
|
// 存储上一次的依赖项值,用于深度比较
|
|
45
49
|
var prevDepsRef = useRef(null);
|
|
@@ -194,7 +198,9 @@ function Line(props) {
|
|
|
194
198
|
isTotalShow: isTotalShow,
|
|
195
199
|
xAxis: xAxis,
|
|
196
200
|
// 传入原始 xAxis 数据
|
|
197
|
-
tooltipYOffset: tooltipYOffset
|
|
201
|
+
tooltipYOffset: tooltipYOffset,
|
|
202
|
+
// y 方向偏移量
|
|
203
|
+
tooltipNameMaxWidth: tooltipNameMaxWidth // tooltip 名称最大宽度
|
|
198
204
|
});
|
|
199
205
|
var series = convertSeriesData(seriesData);
|
|
200
206
|
var legendData = Object.keys(seriesData).map(function (item) {
|
|
@@ -219,17 +225,14 @@ function Line(props) {
|
|
|
219
225
|
itemGap: 8,
|
|
220
226
|
formatter: function formatter(name) {
|
|
221
227
|
var value = legendValue ? numberFormatMust(seriesTotal[name] || 0) : 0;
|
|
222
|
-
var showName = name;
|
|
223
|
-
if (seriesData.length >= 4) {
|
|
224
|
-
var strLen = 15;
|
|
225
|
-
if (name.length > strLen) {
|
|
226
|
-
showName = name.substring(0, strLen) + '...';
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
228
|
if (sumData) {
|
|
230
229
|
value = numberFormatMust(sumData);
|
|
231
230
|
}
|
|
232
|
-
|
|
231
|
+
var ellipsisName = canvasEllipsisMiddle(name, legendNameMaxWidth, {
|
|
232
|
+
fontSize: 12,
|
|
233
|
+
fontWeight: 500
|
|
234
|
+
});
|
|
235
|
+
return legendValue ? "{labelName|".concat(ellipsisName, "}\n{labelMark|").concat(value, "}") : "{labelName|".concat(ellipsisName, "}");
|
|
233
236
|
},
|
|
234
237
|
textStyle: {
|
|
235
238
|
fontWeight: 500,
|
|
@@ -6,7 +6,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
6
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
7
|
import moment from 'moment';
|
|
8
8
|
import 'moment/locale/zh-cn';
|
|
9
|
-
import { changeDataTypeEn, computeFloatNull, computePos, isZH } from "../../utils/chartUtils";
|
|
9
|
+
import { canvasEllipsisMiddle, changeDataTypeEn, computeFloatNull, computePos, isZH } from "../../utils/chartUtils";
|
|
10
10
|
var formatToolTipDate = function formatToolTipDate(value) {
|
|
11
11
|
// 根据语言环境设置 moment 的 locale
|
|
12
12
|
var locale = isZH() ? 'zh-cn' : 'en';
|
|
@@ -30,7 +30,9 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
30
30
|
isTotalShow = _ref.isTotalShow,
|
|
31
31
|
xAxis = _ref.xAxis,
|
|
32
32
|
_ref$tooltipYOffset = _ref.tooltipYOffset,
|
|
33
|
-
tooltipYOffset = _ref$tooltipYOffset === void 0 ? -4 : _ref$tooltipYOffset
|
|
33
|
+
tooltipYOffset = _ref$tooltipYOffset === void 0 ? -4 : _ref$tooltipYOffset,
|
|
34
|
+
_ref$tooltipNameMaxWi = _ref.tooltipNameMaxWidth,
|
|
35
|
+
tooltipNameMaxWidth = _ref$tooltipNameMaxWi === void 0 ? 140 : _ref$tooltipNameMaxWi;
|
|
34
36
|
return {
|
|
35
37
|
className: "onesight-line-tooltip ".concat(tooltipClassName, " ").concat(id),
|
|
36
38
|
trigger: 'axis',
|
|
@@ -109,7 +111,10 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
109
111
|
marginRight = 3;
|
|
110
112
|
}
|
|
111
113
|
return "\n <div class='tooltip-wrap'>\n <div class='tooltip-head'>\n ".concat(formatToolTipDate(originalDate), "\n </div>\n <div class='tooltip-body' style=\"margin-right:").concat(marginRight, "px\">\n ").concat(dataArr.length > 1 && isTotalShow ? "\n <div class='total'>\n <div class='l'>\n ".concat(tooltipTotalName, "\n </div>\n <div class='r'>\n ").concat(changeDataTypeEn(total), "\n </div>\n </div>\n ") : '', "\n ").concat(dataArr.map(function (item) {
|
|
112
|
-
return "\n <div class='item' data-series-item='".concat(JSON.stringify(item), "' key='").concat(item.seriesName, "'>\n <div class='l'>\n <span class='l-color' style=\"background-color:").concat(item.color, "\"></span>\n <span>\n ").concat(item.seriesName,
|
|
114
|
+
return "\n <div class='item' data-series-item='".concat(JSON.stringify(item), "' key='").concat(item.seriesName, "'>\n <div class='l'>\n <span class='l-color' style=\"background-color:").concat(item.color, "\"></span>\n <span>\n ").concat(canvasEllipsisMiddle(item.seriesName, tooltipNameMaxWidth, {
|
|
115
|
+
fontSize: 14,
|
|
116
|
+
fontWeight: 400
|
|
117
|
+
}), "\n </span>\n </div>\n <div class='r'>\n ").concat(dataArr.length > 1 && showRate ? "<span class='rate'>(".concat(computeFloatNull(item.proportion), ")</span>") : '', "\n <span class='num'>\n ").concat(changeDataTypeEn(item.value), "\n </span>\n </div>\n </div>\n ");
|
|
113
118
|
}).join(''), "\n </div>\n ").concat(tooltipPosition ? '<div class="triangle-down"></div>' : '', "\n </div>\n ");
|
|
114
119
|
}
|
|
115
120
|
};
|
|
@@ -13,7 +13,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
13
13
|
import * as echarts from 'echarts';
|
|
14
14
|
import moment from 'moment';
|
|
15
15
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
16
|
-
import { calculateSeriesTotal, convertSeriesData, dealPath, isZH, numberFormatMust, numberFormatNull } from "../../utils/chartUtils";
|
|
16
|
+
import { calculateSeriesTotal, canvasEllipsisMiddle, convertSeriesData, dealPath, isZH, numberFormatMust, numberFormatNull } from "../../utils/chartUtils";
|
|
17
17
|
import { defaultChartColors } from "../../utils/colors";
|
|
18
18
|
import { createCustomTooltip } from "./tooltipConfig";
|
|
19
19
|
import "./style.scss";
|
|
@@ -54,7 +54,11 @@ function StandardCustomLine(props) {
|
|
|
54
54
|
_props$legendDropdown = props.legendDropdownRight,
|
|
55
55
|
legendDropdownRight = _props$legendDropdown === void 0 ? -98 : _props$legendDropdown,
|
|
56
56
|
_props$showAllLegends = props.showAllLegends,
|
|
57
|
-
showAllLegends = _props$showAllLegends === void 0 ? false : _props$showAllLegends
|
|
57
|
+
showAllLegends = _props$showAllLegends === void 0 ? false : _props$showAllLegends,
|
|
58
|
+
_props$legendNameMaxW = props.legendNameMaxWidth,
|
|
59
|
+
legendNameMaxWidth = _props$legendNameMaxW === void 0 ? 120 : _props$legendNameMaxW,
|
|
60
|
+
_props$tooltipNameMax = props.tooltipNameMaxWidth,
|
|
61
|
+
tooltipNameMaxWidth = _props$tooltipNameMax === void 0 ? 140 : _props$tooltipNameMax;
|
|
58
62
|
var chartRef = useRef(null);
|
|
59
63
|
// 存储上一次的依赖项值,用于深度比较
|
|
60
64
|
var prevDepsRef = useRef(null);
|
|
@@ -328,7 +332,9 @@ function StandardCustomLine(props) {
|
|
|
328
332
|
// 传入映射,使 tooltip 显示原始 name
|
|
329
333
|
xAxis: xAxis,
|
|
330
334
|
// 传入原始 xAxis 数据
|
|
331
|
-
tooltipYOffset: tooltipYOffset
|
|
335
|
+
tooltipYOffset: tooltipYOffset,
|
|
336
|
+
// y 方向偏移量
|
|
337
|
+
tooltipNameMaxWidth: tooltipNameMaxWidth // tooltip 名称最大宽度
|
|
332
338
|
});
|
|
333
339
|
|
|
334
340
|
// 创建 uniqueKey 到索引的映射,用于生成安全的图标键名
|
|
@@ -410,7 +416,11 @@ function StandardCustomLine(props) {
|
|
|
410
416
|
var index = nameToIndexMap[name];
|
|
411
417
|
var iconKey = platformIcon && index !== undefined ? "icon".concat(index) : '';
|
|
412
418
|
var iconPrefix = iconKey ? "{".concat(iconKey, "|} ") : '';
|
|
413
|
-
|
|
419
|
+
var ellipsisName = canvasEllipsisMiddle(showName, legendNameMaxWidth, {
|
|
420
|
+
fontSize: 12,
|
|
421
|
+
fontWeight: 500
|
|
422
|
+
});
|
|
423
|
+
return legendValue ? "".concat(iconPrefix, "{labelName|").concat(ellipsisName, "}\n{labelMark|").concat(value, "}") : "".concat(iconPrefix, "{labelName|").concat(ellipsisName, "}");
|
|
414
424
|
},
|
|
415
425
|
textStyle: {
|
|
416
426
|
fontWeight: 500,
|
|
@@ -6,7 +6,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
6
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
7
|
import moment from 'moment';
|
|
8
8
|
import 'moment/locale/zh-cn';
|
|
9
|
-
import { changeDataTypeEn, computeFloatNull, computePos, isZH } from "../../utils/chartUtils";
|
|
9
|
+
import { canvasEllipsisMiddle, changeDataTypeEn, computeFloatNull, computePos, isZH } from "../../utils/chartUtils";
|
|
10
10
|
var formatToolTipDate = function formatToolTipDate(value) {
|
|
11
11
|
// 根据语言环境设置 moment 的 locale
|
|
12
12
|
var locale = isZH() ? 'zh-cn' : 'en';
|
|
@@ -30,7 +30,9 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
30
30
|
keyToNameMap = _ref.keyToNameMap,
|
|
31
31
|
xAxis = _ref.xAxis,
|
|
32
32
|
_ref$tooltipYOffset = _ref.tooltipYOffset,
|
|
33
|
-
tooltipYOffset = _ref$tooltipYOffset === void 0 ? -4 : _ref$tooltipYOffset
|
|
33
|
+
tooltipYOffset = _ref$tooltipYOffset === void 0 ? -4 : _ref$tooltipYOffset,
|
|
34
|
+
_ref$tooltipNameMaxWi = _ref.tooltipNameMaxWidth,
|
|
35
|
+
tooltipNameMaxWidth = _ref$tooltipNameMaxWi === void 0 ? 140 : _ref$tooltipNameMaxWi;
|
|
34
36
|
return {
|
|
35
37
|
className: "onesight-line-tooltip ".concat(tooltipClassName),
|
|
36
38
|
trigger: 'axis',
|
|
@@ -114,7 +116,10 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
114
116
|
marginRight = 3;
|
|
115
117
|
}
|
|
116
118
|
return "\n <div class='tooltip-wrap'>\n <div class='tooltip-head'>\n ".concat(formatToolTipDate(originalDate), "\n </div>\n <div class='tooltip-body' style=\"margin-right:").concat(marginRight, "px\">\n ").concat(dataArr.length > 1 && isTotalShow ? "\n <div class='total'>\n <div class='l'>\n ".concat(tooltipTotalName, "\n </div>\n <div class='r'>\n ").concat(changeDataTypeEn(total), "\n </div>\n </div>\n ") : '', "\n ").concat(dataArr.map(function (item) {
|
|
117
|
-
return "\n <div class='item' data-series-item='".concat(JSON.stringify(item), "' key='").concat(item.seriesName, "'>\n <div class='l'>\n <span class='l-color' style=\"background-color:").concat(item.color, "\"></span>\n <span>\n ").concat(item.seriesName,
|
|
119
|
+
return "\n <div class='item' data-series-item='".concat(JSON.stringify(item), "' key='").concat(item.seriesName, "'>\n <div class='l'>\n <span class='l-color' style=\"background-color:").concat(item.color, "\"></span>\n <span>\n ").concat(canvasEllipsisMiddle(item.seriesName, tooltipNameMaxWidth, {
|
|
120
|
+
fontSize: 14,
|
|
121
|
+
fontWeight: 400
|
|
122
|
+
}), "\n </span>\n </div>\n <div class='r'>\n ").concat(dataArr.length > 1 && showRate ? "<span class='rate'>(".concat(computeFloatNull(item.proportion), ")</span>") : '', "\n <span class='num'>\n ").concat(changeDataTypeEn(item.value), "\n </span>\n </div> \n </div>\n ");
|
|
118
123
|
}).join(''), "\n </div>\n ").concat(tooltipPosition ? '<div class="triangle-down"></div>' : '', "\n </div>\n ");
|
|
119
124
|
}
|
|
120
125
|
};
|
|
@@ -13,7 +13,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
13
13
|
import * as echarts from 'echarts';
|
|
14
14
|
import moment from 'moment';
|
|
15
15
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
16
|
-
import { calculateSeriesTotal, convertSeriesData, dealPath, isZH, numberFormatMust, numberFormatNull } from "../../utils/chartUtils";
|
|
16
|
+
import { calculateSeriesTotal, canvasEllipsisMiddle, convertSeriesData, dealPath, isZH, numberFormatMust, numberFormatNull } from "../../utils/chartUtils";
|
|
17
17
|
import { defaultChartColors } from "../../utils/colors";
|
|
18
18
|
import { createCustomTooltip } from "./tooltipConfig";
|
|
19
19
|
import "./style.scss";
|
|
@@ -54,7 +54,11 @@ function StandardLine(props) {
|
|
|
54
54
|
_props$legendDropdown = props.legendDropdownRight,
|
|
55
55
|
legendDropdownRight = _props$legendDropdown === void 0 ? -98 : _props$legendDropdown,
|
|
56
56
|
_props$showAllLegends = props.showAllLegends,
|
|
57
|
-
showAllLegends = _props$showAllLegends === void 0 ? false : _props$showAllLegends
|
|
57
|
+
showAllLegends = _props$showAllLegends === void 0 ? false : _props$showAllLegends,
|
|
58
|
+
_props$legendNameMaxW = props.legendNameMaxWidth,
|
|
59
|
+
legendNameMaxWidth = _props$legendNameMaxW === void 0 ? 120 : _props$legendNameMaxW,
|
|
60
|
+
_props$tooltipNameMax = props.tooltipNameMaxWidth,
|
|
61
|
+
tooltipNameMaxWidth = _props$tooltipNameMax === void 0 ? 140 : _props$tooltipNameMax;
|
|
58
62
|
var chartRef = useRef(null);
|
|
59
63
|
var legendMoreBtnRef = useRef(null);
|
|
60
64
|
var legendDropdownRef = useRef(null);
|
|
@@ -267,7 +271,9 @@ function StandardLine(props) {
|
|
|
267
271
|
isTotalShow: isTotalShow,
|
|
268
272
|
xAxis: xAxis,
|
|
269
273
|
// 传入原始 xAxis 数据
|
|
270
|
-
tooltipYOffset: tooltipYOffset
|
|
274
|
+
tooltipYOffset: tooltipYOffset,
|
|
275
|
+
// y 方向偏移量
|
|
276
|
+
tooltipNameMaxWidth: tooltipNameMaxWidth // tooltip 名称最大宽度
|
|
271
277
|
});
|
|
272
278
|
var option = {
|
|
273
279
|
legend: {
|
|
@@ -289,14 +295,11 @@ function StandardLine(props) {
|
|
|
289
295
|
} else if (sumData) {
|
|
290
296
|
value = numberFormatMust(sumData);
|
|
291
297
|
}
|
|
292
|
-
var
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return legendValue ? "{labelName|".concat(showName, "}\n{labelMark|").concat(value, "}") : "{labelName|".concat(showName, "}");
|
|
298
|
+
var ellipsisName = canvasEllipsisMiddle(name, legendNameMaxWidth, {
|
|
299
|
+
fontSize: 12,
|
|
300
|
+
fontWeight: 500
|
|
301
|
+
});
|
|
302
|
+
return legendValue ? "{labelName|".concat(ellipsisName, "}\n{labelMark|").concat(value, "}") : "{labelName|".concat(ellipsisName, "}");
|
|
300
303
|
},
|
|
301
304
|
textStyle: {
|
|
302
305
|
fontWeight: 500,
|
|
@@ -6,7 +6,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
6
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
7
|
import moment from 'moment';
|
|
8
8
|
import 'moment/locale/zh-cn';
|
|
9
|
-
import { changeDataTypeEn, computeFloatNull, computePos, isZH } from "../../utils/chartUtils";
|
|
9
|
+
import { canvasEllipsisMiddle, changeDataTypeEn, computeFloatNull, computePos, isZH } from "../../utils/chartUtils";
|
|
10
10
|
var formatToolTipDate = function formatToolTipDate(value) {
|
|
11
11
|
// 根据语言环境设置 moment 的 locale
|
|
12
12
|
var locale = isZH() ? 'zh-cn' : 'en';
|
|
@@ -29,7 +29,9 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
29
29
|
isTotalShow = _ref.isTotalShow,
|
|
30
30
|
xAxis = _ref.xAxis,
|
|
31
31
|
_ref$tooltipYOffset = _ref.tooltipYOffset,
|
|
32
|
-
tooltipYOffset = _ref$tooltipYOffset === void 0 ? -4 : _ref$tooltipYOffset
|
|
32
|
+
tooltipYOffset = _ref$tooltipYOffset === void 0 ? -4 : _ref$tooltipYOffset,
|
|
33
|
+
_ref$tooltipNameMaxWi = _ref.tooltipNameMaxWidth,
|
|
34
|
+
tooltipNameMaxWidth = _ref$tooltipNameMaxWi === void 0 ? 140 : _ref$tooltipNameMaxWi;
|
|
33
35
|
return {
|
|
34
36
|
className: "onesight-line-tooltip ".concat(tooltipClassName),
|
|
35
37
|
trigger: 'axis',
|
|
@@ -108,7 +110,10 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
108
110
|
marginRight = 3;
|
|
109
111
|
}
|
|
110
112
|
return "\n <div class='tooltip-wrap'>\n <div class='tooltip-head'>\n ".concat(formatToolTipDate(originalDate), "\n </div>\n <div class='tooltip-body' style=\"margin-right:").concat(marginRight, "px\">\n ").concat(dataArr.length > 1 && isTotalShow ? "\n <div class='total'>\n <div class='l'>\n ".concat(tooltipTotalName, "\n </div>\n <div class='r'>\n ").concat(changeDataTypeEn(total), "\n </div>\n </div>\n ") : '', "\n ").concat(dataArr.map(function (item) {
|
|
111
|
-
return "\n <div class='item' data-series-item='".concat(JSON.stringify(item), "' key='").concat(item.seriesName, "'>\n <div class='l'>\n <span class='l-color' style=\"background-color:").concat(item.color, "\"></span>\n <span>\n ").concat(item.seriesName,
|
|
113
|
+
return "\n <div class='item' data-series-item='".concat(JSON.stringify(item), "' key='").concat(item.seriesName, "'>\n <div class='l'>\n <span class='l-color' style=\"background-color:").concat(item.color, "\"></span>\n <span>\n ").concat(canvasEllipsisMiddle(item.seriesName, tooltipNameMaxWidth, {
|
|
114
|
+
fontSize: 14,
|
|
115
|
+
fontWeight: 400
|
|
116
|
+
}), "\n </span>\n </div>\n <div class='r'>\n ").concat(dataArr.length > 1 && showRate ? "<span class='rate'>(".concat(computeFloatNull(item.proportion), ")</span>") : '', "\n <span class='num'>\n ").concat(changeDataTypeEn(item.value), "\n </span>\n </div> \n </div>\n ");
|
|
112
117
|
}).join(''), "\n </div>\n ").concat(tooltipPosition ? '<div class="triangle-down"></div>' : '', "\n </div>\n ");
|
|
113
118
|
}
|
|
114
119
|
};
|
package/es/utils/chartUtils.js
CHANGED
|
@@ -3544,4 +3544,82 @@ function numberFormat(num) {
|
|
|
3544
3544
|
var fixedNum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
3545
3545
|
return numberFormatMust(num, fixedNum);
|
|
3546
3546
|
}
|
|
3547
|
-
|
|
3547
|
+
function canvasGetTextWidth(str) {
|
|
3548
|
+
var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3549
|
+
if (!str) return 0;
|
|
3550
|
+
var _style$fontSize = style.fontSize,
|
|
3551
|
+
fontSize = _style$fontSize === void 0 ? 12 : _style$fontSize,
|
|
3552
|
+
_style$fontWeight = style.fontWeight,
|
|
3553
|
+
fontWeight = _style$fontWeight === void 0 ? 500 : _style$fontWeight,
|
|
3554
|
+
_style$fontFamily = style.fontFamily,
|
|
3555
|
+
fontFamily = _style$fontFamily === void 0 ? 'sans-serif' : _style$fontFamily;
|
|
3556
|
+
var canvas = document.createElement('canvas');
|
|
3557
|
+
var ctx = canvas.getContext('2d');
|
|
3558
|
+
ctx.font = "".concat(fontWeight, " ").concat(fontSize, "px ").concat(fontFamily);
|
|
3559
|
+
return Math.ceil(ctx.measureText(str).width);
|
|
3560
|
+
}
|
|
3561
|
+
function canvasEllipsisMiddle(str, maxWidth) {
|
|
3562
|
+
var style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
3563
|
+
if (!str) return '';
|
|
3564
|
+
if (canvasGetTextWidth(str, style) <= maxWidth) return str;
|
|
3565
|
+
var ellipsis = '...';
|
|
3566
|
+
var left = 1;
|
|
3567
|
+
var testWidth = 0;
|
|
3568
|
+
var arr = [];
|
|
3569
|
+
// 分别从两端开始拼接,保证总宽度 <= maxWidth
|
|
3570
|
+
while (testWidth < maxWidth) {
|
|
3571
|
+
var leftPart = str.slice(0, left);
|
|
3572
|
+
var rightPart = str.slice(-left);
|
|
3573
|
+
var testStr = leftPart + ellipsis + rightPart;
|
|
3574
|
+
testWidth = canvasGetTextWidth(testStr, style);
|
|
3575
|
+
arr.push({
|
|
3576
|
+
left: left,
|
|
3577
|
+
testWidth: testWidth
|
|
3578
|
+
});
|
|
3579
|
+
left++;
|
|
3580
|
+
}
|
|
3581
|
+
var T = 0;
|
|
3582
|
+
for (var i = arr.length - 1; i >= 0; i--) {
|
|
3583
|
+
if (arr[i].testWidth < maxWidth) {
|
|
3584
|
+
T = arr[i].left;
|
|
3585
|
+
break;
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
if (T) {
|
|
3589
|
+
return "".concat(str.slice(0, T)).concat(ellipsis).concat(str.slice(-T));
|
|
3590
|
+
} else {
|
|
3591
|
+
return '';
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
var TextMeasure = function () {
|
|
3595
|
+
// 创建一个私有隐藏元素用于测量
|
|
3596
|
+
var span = document.createElement('span');
|
|
3597
|
+
span.style.position = 'fixed';
|
|
3598
|
+
span.style.visibility = 'hidden';
|
|
3599
|
+
span.style.whiteSpace = 'nowrap';
|
|
3600
|
+
span.style.pointerEvents = 'none';
|
|
3601
|
+
span.style.left = '-9999px';
|
|
3602
|
+
document.body.appendChild(span);
|
|
3603
|
+
function getWidth(str) {
|
|
3604
|
+
var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3605
|
+
if (!str) return 0;
|
|
3606
|
+
var _style$fontSize2 = style.fontSize,
|
|
3607
|
+
fontSize = _style$fontSize2 === void 0 ? 14 : _style$fontSize2,
|
|
3608
|
+
_style$fontWeight2 = style.fontWeight,
|
|
3609
|
+
fontWeight = _style$fontWeight2 === void 0 ? 'normal' : _style$fontWeight2,
|
|
3610
|
+
_style$fontFamily2 = style.fontFamily,
|
|
3611
|
+
fontFamily = _style$fontFamily2 === void 0 ? '"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"' : _style$fontFamily2,
|
|
3612
|
+
_style$letterSpacing = style.letterSpacing,
|
|
3613
|
+
letterSpacing = _style$letterSpacing === void 0 ? 0 : _style$letterSpacing;
|
|
3614
|
+
span.style.fontSize = fontSize + 'px';
|
|
3615
|
+
span.style.fontWeight = fontWeight;
|
|
3616
|
+
span.style.letterSpacing = letterSpacing + 'px';
|
|
3617
|
+
span.style.fontFamily = fontFamily;
|
|
3618
|
+
span.textContent = str;
|
|
3619
|
+
return Math.ceil(span.offsetWidth) + 2;
|
|
3620
|
+
}
|
|
3621
|
+
return {
|
|
3622
|
+
getWidth: getWidth
|
|
3623
|
+
};
|
|
3624
|
+
}();
|
|
3625
|
+
export { calculateSeriesTotal, canvasEllipsisMiddle, changeDataTypeEn, computeFloat, computeFloatNull, computePos, convertSeriesData, dealBarPath, dealPath, dealSort, isZH, mapEchartsDict, numberFormat, numberFormatMust, numberFormatNull, sumValues, toggleAxisPointer, transformedSeriesData };
|
|
@@ -60,8 +60,12 @@ function CustomLine(props) {
|
|
|
60
60
|
xType,
|
|
61
61
|
rightSpacing,
|
|
62
62
|
legendDropdownRight = -98,
|
|
63
|
-
showAllLegends = false
|
|
63
|
+
showAllLegends = false,
|
|
64
64
|
// 是否显示所有图例
|
|
65
|
+
legendNameMaxWidth = 120,
|
|
66
|
+
// legend 名称最大宽度(像素值),用于文本截断
|
|
67
|
+
tooltipNameMaxWidth = 140
|
|
68
|
+
// tooltip 名称最大宽度(像素值),用于文本截断
|
|
65
69
|
} = props;
|
|
66
70
|
const chartRef = (0, import_react.useRef)(null);
|
|
67
71
|
const prevDepsRef = (0, import_react.useRef)(null);
|
|
@@ -240,8 +244,10 @@ function CustomLine(props) {
|
|
|
240
244
|
isTotalShow,
|
|
241
245
|
xAxis,
|
|
242
246
|
// 传入原始 xAxis 数据
|
|
243
|
-
tooltipYOffset
|
|
247
|
+
tooltipYOffset,
|
|
244
248
|
// y 方向偏移量
|
|
249
|
+
tooltipNameMaxWidth
|
|
250
|
+
// tooltip 名称最大宽度
|
|
245
251
|
});
|
|
246
252
|
let option = {
|
|
247
253
|
legend: {
|
|
@@ -257,15 +263,12 @@ function CustomLine(props) {
|
|
|
257
263
|
itemGap: 8,
|
|
258
264
|
formatter: function(name) {
|
|
259
265
|
const value = legendValue ? (0, import_chartUtils.numberFormatMust)(seriesTotal[name] || 0) : 0;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
return legendValue ? `{labelName|${showName}}
|
|
268
|
-
{labelMark|${value}}` : `{labelName|${showName}}`;
|
|
266
|
+
const ellipsisName = (0, import_chartUtils.canvasEllipsisMiddle)(name, legendNameMaxWidth, {
|
|
267
|
+
fontSize: 12,
|
|
268
|
+
fontWeight: 500
|
|
269
|
+
});
|
|
270
|
+
return legendValue ? `{labelName|${ellipsisName}}
|
|
271
|
+
{labelMark|${value}}` : `{labelName|${ellipsisName}}`;
|
|
269
272
|
},
|
|
270
273
|
textStyle: {
|
|
271
274
|
fontWeight: 500,
|
|
@@ -58,8 +58,10 @@ var createCustomTooltip = ({
|
|
|
58
58
|
isTotalShow,
|
|
59
59
|
xAxis,
|
|
60
60
|
// 新增:原始的 xAxis 数据
|
|
61
|
-
tooltipYOffset = -4
|
|
61
|
+
tooltipYOffset = -4,
|
|
62
62
|
// y 方向偏移量,默认 14px
|
|
63
|
+
tooltipNameMaxWidth = 140
|
|
64
|
+
// tooltip 名称最大宽度(像素值),用于文本截断
|
|
63
65
|
}) => ({
|
|
64
66
|
className: `onesight-line-tooltip ${tooltipClassName}`,
|
|
65
67
|
trigger: "axis",
|
|
@@ -151,7 +153,14 @@ var createCustomTooltip = ({
|
|
|
151
153
|
<div class='l'>
|
|
152
154
|
<span class='l-color' style="background-color:${item.color}"></span>
|
|
153
155
|
<span>
|
|
154
|
-
${
|
|
156
|
+
${(0, import_chartUtils.canvasEllipsisMiddle)(
|
|
157
|
+
item.seriesName,
|
|
158
|
+
tooltipNameMaxWidth,
|
|
159
|
+
{
|
|
160
|
+
fontSize: 14,
|
|
161
|
+
fontWeight: 400
|
|
162
|
+
}
|
|
163
|
+
)}
|
|
155
164
|
</span>
|
|
156
165
|
</div>
|
|
157
166
|
<div class='r'>
|
|
@@ -63,8 +63,12 @@ function Line(props) {
|
|
|
63
63
|
sumData = 0,
|
|
64
64
|
yAxisScale = true,
|
|
65
65
|
// Y轴是否不从0开始,根据数据范围自动调整
|
|
66
|
-
showAllLegends = false
|
|
66
|
+
showAllLegends = false,
|
|
67
67
|
// 是否显示所有图例(line组件默认显示所有,此参数用于触发动态调整grid.bottom)
|
|
68
|
+
legendNameMaxWidth = 120,
|
|
69
|
+
// legend 名称最大宽度(像素值),用于文本截断
|
|
70
|
+
tooltipNameMaxWidth = 140
|
|
71
|
+
// tooltip 名称最大宽度(像素值),用于文本截断
|
|
68
72
|
} = props;
|
|
69
73
|
const chartRef = (0, import_react.useRef)(null);
|
|
70
74
|
const prevDepsRef = (0, import_react.useRef)(null);
|
|
@@ -205,8 +209,10 @@ function Line(props) {
|
|
|
205
209
|
isTotalShow,
|
|
206
210
|
xAxis,
|
|
207
211
|
// 传入原始 xAxis 数据
|
|
208
|
-
tooltipYOffset
|
|
212
|
+
tooltipYOffset,
|
|
209
213
|
// y 方向偏移量
|
|
214
|
+
tooltipNameMaxWidth
|
|
215
|
+
// tooltip 名称最大宽度
|
|
210
216
|
});
|
|
211
217
|
const series = (0, import_chartUtils.convertSeriesData)(seriesData);
|
|
212
218
|
const legendData = Object.keys(seriesData).map((item) => ({
|
|
@@ -227,18 +233,15 @@ function Line(props) {
|
|
|
227
233
|
itemGap: 8,
|
|
228
234
|
formatter: function(name) {
|
|
229
235
|
let value = legendValue ? (0, import_chartUtils.numberFormatMust)(seriesTotal[name] || 0) : 0;
|
|
230
|
-
let showName = name;
|
|
231
|
-
if (seriesData.length >= 4) {
|
|
232
|
-
const strLen = 15;
|
|
233
|
-
if (name.length > strLen) {
|
|
234
|
-
showName = name.substring(0, strLen) + "...";
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
236
|
if (sumData) {
|
|
238
237
|
value = (0, import_chartUtils.numberFormatMust)(sumData);
|
|
239
238
|
}
|
|
240
|
-
|
|
241
|
-
|
|
239
|
+
const ellipsisName = (0, import_chartUtils.canvasEllipsisMiddle)(name, legendNameMaxWidth, {
|
|
240
|
+
fontSize: 12,
|
|
241
|
+
fontWeight: 500
|
|
242
|
+
});
|
|
243
|
+
return legendValue ? `{labelName|${ellipsisName}}
|
|
244
|
+
{labelMark|${value}}` : `{labelName|${ellipsisName}}`;
|
|
242
245
|
},
|
|
243
246
|
textStyle: {
|
|
244
247
|
fontWeight: 500,
|
|
@@ -59,8 +59,10 @@ var createCustomTooltip = ({
|
|
|
59
59
|
isTotalShow,
|
|
60
60
|
xAxis,
|
|
61
61
|
// 新增:原始的 xAxis 数据
|
|
62
|
-
tooltipYOffset = -4
|
|
62
|
+
tooltipYOffset = -4,
|
|
63
63
|
// y 方向偏移量,默认 14px
|
|
64
|
+
tooltipNameMaxWidth = 140
|
|
65
|
+
// tooltip 名称最大宽度(像素值),用于文本截断
|
|
64
66
|
}) => ({
|
|
65
67
|
className: `onesight-line-tooltip ${tooltipClassName} ${id}`,
|
|
66
68
|
trigger: "axis",
|
|
@@ -154,7 +156,14 @@ var createCustomTooltip = ({
|
|
|
154
156
|
<div class='l'>
|
|
155
157
|
<span class='l-color' style="background-color:${item.color}"></span>
|
|
156
158
|
<span>
|
|
157
|
-
${
|
|
159
|
+
${(0, import_chartUtils.canvasEllipsisMiddle)(
|
|
160
|
+
item.seriesName,
|
|
161
|
+
tooltipNameMaxWidth,
|
|
162
|
+
{
|
|
163
|
+
fontSize: 14,
|
|
164
|
+
fontWeight: 400
|
|
165
|
+
}
|
|
166
|
+
)}
|
|
158
167
|
</span>
|
|
159
168
|
</div>
|
|
160
169
|
<div class='r'>
|