onesight-charts 0.0.1
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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/components/line/demo.js +13 -0
- package/dist/components/line/index.js +294 -0
- package/dist/components/line/style.scss +110 -0
- package/dist/components/line/tooltipConfig.js +93 -0
- package/dist/components/one-table/demo/line-chart.js +908 -0
- package/dist/components/one-table/index.js +128 -0
- package/dist/components/one-table/index.scss +5 -0
- package/dist/components/pie/index.js +94 -0
- package/dist/components/pie/index.scss +5 -0
- package/dist/components/tooltip/demo/line-chart.js +908 -0
- package/dist/components/tooltip/index.js +128 -0
- package/dist/components/tooltip/index.scss +5 -0
- package/dist/index.js +1 -0
- package/dist/umd/onesight-charts.min.css +1 -0
- package/dist/umd/onesight-charts.min.js +1 -0
- package/dist/utils/chartUtils.js +215 -0
- package/dist/utils/colors.js +26 -0
- package/lib/components/line/demo.js +42 -0
- package/lib/components/line/index.js +307 -0
- package/lib/components/line/style.scss +110 -0
- package/lib/components/line/tooltipConfig.js +144 -0
- package/lib/components/one-table/demo/line-chart.js +1020 -0
- package/lib/components/one-table/index.js +156 -0
- package/lib/components/one-table/index.scss +5 -0
- package/lib/components/pie/index.js +131 -0
- package/lib/components/pie/index.scss +5 -0
- package/lib/components/tooltip/demo/line-chart.js +1020 -0
- package/lib/components/tooltip/index.js +156 -0
- package/lib/components/tooltip/index.scss +5 -0
- package/lib/index.js +39 -0
- package/lib/utils/chartUtils.js +226 -0
- package/lib/utils/colors.js +71 -0
- package/package.json +82 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
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; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
function isZH() {
|
|
8
|
+
// return getLocale() === 'zh-CN';
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 判断是否为浮点数
|
|
13
|
+
function isFloat(n) {
|
|
14
|
+
return /^-?\d*\.\d+$/.test(n);
|
|
15
|
+
}
|
|
16
|
+
function changeDataTypeEn(s) {
|
|
17
|
+
var number = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
18
|
+
var n = number;
|
|
19
|
+
if (s === null) {
|
|
20
|
+
return '-';
|
|
21
|
+
}
|
|
22
|
+
if (!s && s !== 0 && s !== '0') {
|
|
23
|
+
return '0';
|
|
24
|
+
}
|
|
25
|
+
// 千位符 计算 s 是传入参数 n 是要保留的位数
|
|
26
|
+
var f = '';
|
|
27
|
+
if (Number(s) < 0) {
|
|
28
|
+
f = '-';
|
|
29
|
+
}
|
|
30
|
+
n = n >= 0 && n <= 20 ? n : 2;
|
|
31
|
+
s = parseFloat((s + '').replace(/[^\d\.]/g, ''));
|
|
32
|
+
var bese = Math.pow(10, n);
|
|
33
|
+
s = s * bese;
|
|
34
|
+
s = s.toFixed() / bese + '';
|
|
35
|
+
if (isFloat(s)) {
|
|
36
|
+
// start
|
|
37
|
+
var rs = s.indexOf('.');
|
|
38
|
+
if (rs < 0) {
|
|
39
|
+
rs = s.length;
|
|
40
|
+
s += '.';
|
|
41
|
+
}
|
|
42
|
+
while (s.length <= rs + n) {
|
|
43
|
+
s += '0';
|
|
44
|
+
}
|
|
45
|
+
// end
|
|
46
|
+
}
|
|
47
|
+
var l = s.split('.')[0].split('').reverse();
|
|
48
|
+
var r = s.split('.')[1];
|
|
49
|
+
var t = '';
|
|
50
|
+
for (var i = 0; i < l.length; i++) {
|
|
51
|
+
t += l[i] + ((i + 1) % 3 === 0 && i + 1 !== l.length ? ',' : '');
|
|
52
|
+
}
|
|
53
|
+
var sendStr = '';
|
|
54
|
+
if (n !== 0 && r) {
|
|
55
|
+
sendStr = t.split('').reverse().join('') + '.' + r;
|
|
56
|
+
} else {
|
|
57
|
+
sendStr = t.split('').reverse().join('');
|
|
58
|
+
}
|
|
59
|
+
return f + sendStr;
|
|
60
|
+
}
|
|
61
|
+
function numberFormatMust(num, fixed) {
|
|
62
|
+
var value = num;
|
|
63
|
+
var fixedNum = isZH() ? 2 : 1;
|
|
64
|
+
var originNum = num;
|
|
65
|
+
if (num < 0) {
|
|
66
|
+
num = Math.abs(num);
|
|
67
|
+
}
|
|
68
|
+
isZH() ? num >= 100000000 ? value = changeDataTypeEn(num / 100000000, fixedNum) + '亿' : num >= 10000 ? value = changeDataTypeEn(num / 10000, fixedNum) + '万' : value = changeDataTypeEn(num, fixedNum) : num >= 1000000000 ? value = changeDataTypeEn(num / 1000000000, fixedNum) + 'B' : num >= 1000000 ? value = changeDataTypeEn(num / 1000000, fixedNum) + 'M' : num >= 1000 ? value = changeDataTypeEn(num / 1000, fixedNum) + 'K' : value = changeDataTypeEn(num, fixedNum);
|
|
69
|
+
if (originNum < 0) {
|
|
70
|
+
return "-".concat(value);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 判断数值是否为空
|
|
76
|
+
function isNumNull(num) {
|
|
77
|
+
return num === null || num === undefined || isNaN(num);
|
|
78
|
+
}
|
|
79
|
+
function computeFloatNull(num) {
|
|
80
|
+
var per = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
|
|
81
|
+
var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '%';
|
|
82
|
+
if (isNumNull(num)) {
|
|
83
|
+
return '-';
|
|
84
|
+
} else if (num === 0) {
|
|
85
|
+
return '0' + unit;
|
|
86
|
+
} else {
|
|
87
|
+
return (num >= 0.00004 ? changeDataTypeEn(num * per, 2) : '<0.01') + unit;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 数值处理,null的话为-
|
|
92
|
+
function numberFormatNull(num, fixed) {
|
|
93
|
+
return isNumNull(num) ? '-' : numberFormatMust(num, fixed);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 处理图表图例模糊的问题
|
|
97
|
+
function dealPath(elementId) {
|
|
98
|
+
var sawtooth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
99
|
+
// 获取所有path元素
|
|
100
|
+
var paths = document.querySelectorAll('#' + elementId + ' path');
|
|
101
|
+
// 遍历每个path元素
|
|
102
|
+
paths.forEach(function (path) {
|
|
103
|
+
// 获取当前元素的transform属性
|
|
104
|
+
var transform = path.getAttribute('transform');
|
|
105
|
+
// 检查transform属性是否包含translate函数
|
|
106
|
+
if (transform && transform.includes('translate')) {
|
|
107
|
+
// 使用正则表达式提取translate中的数字
|
|
108
|
+
var matches = transform.match(/translate\(([^)]+)\)/);
|
|
109
|
+
if (matches && matches[1]) {
|
|
110
|
+
// 将提取的值分割成数组,并进行四舍五入
|
|
111
|
+
var values = matches[1].split(' ').map(function (value) {
|
|
112
|
+
return Math.round(parseFloat(value));
|
|
113
|
+
});
|
|
114
|
+
// 构造新的translate函数,并更新transform属性
|
|
115
|
+
var newTransform = 'translate(' + values.join(' ') + ')';
|
|
116
|
+
path.setAttribute('transform', newTransform);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
if (sawtooth) {
|
|
120
|
+
path.style.shapeRendering = 'crispEdges';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function modifyStyle(leftValue, currentWidth) {
|
|
126
|
+
var style = document.createElement('style');
|
|
127
|
+
style.innerHTML = "\n .onesight-line-tooltip .triangle-down {\n width: ".concat(currentWidth, "px !important;\n }\n .onesight-line-tooltip .triangle-down::after {\n left: ").concat(leftValue, " !important;\n }\n ");
|
|
128
|
+
document.head.appendChild(style);
|
|
129
|
+
}
|
|
130
|
+
function computePos(xPoint, currentWidth) {
|
|
131
|
+
if (currentWidth) {
|
|
132
|
+
var res = xPoint - currentWidth / 2;
|
|
133
|
+
var leftValue = 0;
|
|
134
|
+
if (currentWidth === 340) {
|
|
135
|
+
leftValue = 50;
|
|
136
|
+
} else {
|
|
137
|
+
leftValue = 30;
|
|
138
|
+
}
|
|
139
|
+
if (res < 35) {
|
|
140
|
+
res = xPoint - leftValue;
|
|
141
|
+
modifyStyle("".concat(leftValue, "px"), currentWidth);
|
|
142
|
+
} else if (res > 730) {
|
|
143
|
+
var val = currentWidth - leftValue;
|
|
144
|
+
res = xPoint - val;
|
|
145
|
+
modifyStyle("".concat(val, "px"), currentWidth);
|
|
146
|
+
} else {
|
|
147
|
+
modifyStyle('50%', currentWidth);
|
|
148
|
+
}
|
|
149
|
+
return res;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
var calculateSeriesTotal = function calculateSeriesTotal(data) {
|
|
153
|
+
return Object.entries(data).reduce(function (acc, _ref) {
|
|
154
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
155
|
+
key = _ref2[0],
|
|
156
|
+
values = _ref2[1];
|
|
157
|
+
acc[key] = values.reduce(function (sum, value) {
|
|
158
|
+
return sum + value;
|
|
159
|
+
}, 0);
|
|
160
|
+
return acc;
|
|
161
|
+
}, {});
|
|
162
|
+
};
|
|
163
|
+
var convertSeriesData = function convertSeriesData(seriesData) {
|
|
164
|
+
return Object.entries(seriesData).map(function (_ref3) {
|
|
165
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
166
|
+
name = _ref4[0],
|
|
167
|
+
data = _ref4[1];
|
|
168
|
+
return {
|
|
169
|
+
type: 'line',
|
|
170
|
+
symbol: 'emptyCircle',
|
|
171
|
+
symbolSize: 8,
|
|
172
|
+
showSymbol: false,
|
|
173
|
+
connectNulls: true,
|
|
174
|
+
lineStyle: {
|
|
175
|
+
width: 3
|
|
176
|
+
},
|
|
177
|
+
smooth: true,
|
|
178
|
+
triggerLineEvent: false,
|
|
179
|
+
emphasis: {
|
|
180
|
+
focus: 'series',
|
|
181
|
+
itemStyle: {
|
|
182
|
+
borderWidth: 2,
|
|
183
|
+
color: '#fff'
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
z: 2,
|
|
187
|
+
name: name,
|
|
188
|
+
data: data.map(function (value) {
|
|
189
|
+
return {
|
|
190
|
+
value: value,
|
|
191
|
+
itemStyle: {
|
|
192
|
+
opacity: 1
|
|
193
|
+
},
|
|
194
|
+
select: {
|
|
195
|
+
itemStyle: {
|
|
196
|
+
opacity: 1
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
})
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
function toggleAxisPointer(myChart, show) {
|
|
205
|
+
myChart.setOption({
|
|
206
|
+
tooltip: {
|
|
207
|
+
axisPointer: {
|
|
208
|
+
lineStyle: {
|
|
209
|
+
color: show ? 'rgba(0, 0, 0, 0.24)' : 'rgba(0, 0, 0, 0)'
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
export { calculateSeriesTotal, changeDataTypeEn, computeFloatNull, computePos, convertSeriesData, dealPath, numberFormatMust, numberFormatNull, toggleAxisPointer };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var defaultChartColors = ['#1DA9A0', '#5274E8', '#F8AF1D', '#D54CB6', '#51A6E6', '#CB3432', '#EE6666', '#6C5CCE', '#57C464', '#FFED49', '#8FE6D1', '#71B3D2', '#814F9E', '#E85D9F', '#78FA3C', '#F8C6A4', '#166364', '#E1A1FE', '#D0F52B', '#9ECCF6'];
|
|
2
|
+
|
|
3
|
+
// 在这里定义浅色主题的颜色
|
|
4
|
+
var lightThemeColors = [];
|
|
5
|
+
|
|
6
|
+
// 在这里定义深色主题的颜色
|
|
7
|
+
var darkThemeColors = [];
|
|
8
|
+
|
|
9
|
+
// 你也可以为特定类型的图表定义特殊的颜色方案
|
|
10
|
+
|
|
11
|
+
// 为饼图定义的特殊颜色方案
|
|
12
|
+
var pieChartColors = [];
|
|
13
|
+
|
|
14
|
+
// 可以导出一个函数来根据不同的图表类型或主题获取颜色
|
|
15
|
+
function getChartColors(chartType) {
|
|
16
|
+
var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'light';
|
|
17
|
+
switch (chartType) {
|
|
18
|
+
case 'pie':
|
|
19
|
+
return pieChartColors;
|
|
20
|
+
case 'line':
|
|
21
|
+
case 'bar':
|
|
22
|
+
default:
|
|
23
|
+
return theme === 'light' ? lightThemeColors : darkThemeColors;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export { darkThemeColors, defaultChartColors, getChartColors, lightThemeColors, pieChartColors };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/components/line/demo.jsx
|
|
30
|
+
var demo_exports = {};
|
|
31
|
+
__export(demo_exports, {
|
|
32
|
+
default: () => demo_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(demo_exports);
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import_index = __toESM(require("./index.jsx"));
|
|
37
|
+
var xAxis = ["07/25", "07/26", "07/27", "07/28", "07/29", "07/30", "07/31"];
|
|
38
|
+
var seriesData = {
|
|
39
|
+
Facebook: [1002, 831, 960, 750, 1451, 1717, 903],
|
|
40
|
+
X: [22094, 20075, 17410, 12374, 13413, 13904, 6895]
|
|
41
|
+
};
|
|
42
|
+
var demo_default = () => /* @__PURE__ */ import_react.default.createElement(import_index.default, { xAxis, seriesData });
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/components/line/index.jsx
|
|
30
|
+
var line_exports = {};
|
|
31
|
+
__export(line_exports, {
|
|
32
|
+
default: () => line_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(line_exports);
|
|
35
|
+
var echarts = __toESM(require("echarts"));
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_chartUtils = require("../../utils/chartUtils");
|
|
38
|
+
var import_colors = require("../../utils/colors");
|
|
39
|
+
var import_tooltipConfig = require("./tooltipConfig");
|
|
40
|
+
var import_style = require("./style.scss");
|
|
41
|
+
function Line(props) {
|
|
42
|
+
const {
|
|
43
|
+
id = "lineId",
|
|
44
|
+
width = "100%",
|
|
45
|
+
height = "400px",
|
|
46
|
+
color,
|
|
47
|
+
xAxis,
|
|
48
|
+
seriesData,
|
|
49
|
+
tooltipClassName,
|
|
50
|
+
legendValue = true,
|
|
51
|
+
showRate = true,
|
|
52
|
+
tooltipTotalName = "总计",
|
|
53
|
+
tooltipPosition = true
|
|
54
|
+
} = props;
|
|
55
|
+
const chartRef = (0, import_react.useRef)(null);
|
|
56
|
+
(0, import_react.useEffect)(() => {
|
|
57
|
+
ceartChart();
|
|
58
|
+
}, [seriesData]);
|
|
59
|
+
const seriesTotal = legendValue ? (0, import_chartUtils.calculateSeriesTotal)(seriesData) : {};
|
|
60
|
+
const ceartChart = () => {
|
|
61
|
+
const chartColor = color || import_colors.defaultChartColors;
|
|
62
|
+
let myChart = echarts.init(chartRef.current, null, {
|
|
63
|
+
renderer: "svg"
|
|
64
|
+
});
|
|
65
|
+
const tooltipConfig = (0, import_tooltipConfig.createCustomTooltip)({
|
|
66
|
+
id,
|
|
67
|
+
tooltipClassName,
|
|
68
|
+
myChart,
|
|
69
|
+
seriesData,
|
|
70
|
+
tooltipTotalName,
|
|
71
|
+
showRate,
|
|
72
|
+
tooltipPosition
|
|
73
|
+
});
|
|
74
|
+
const series = (0, import_chartUtils.convertSeriesData)(seriesData);
|
|
75
|
+
const legendData = Object.keys(seriesData).map((item) => ({
|
|
76
|
+
name: item
|
|
77
|
+
}));
|
|
78
|
+
let option = {
|
|
79
|
+
legend: {
|
|
80
|
+
data: legendData,
|
|
81
|
+
x: "center",
|
|
82
|
+
type: "plain",
|
|
83
|
+
bottom: 0,
|
|
84
|
+
padding: 0,
|
|
85
|
+
left: "center",
|
|
86
|
+
icon: "rect",
|
|
87
|
+
itemWidth: 16,
|
|
88
|
+
itemHeight: 4,
|
|
89
|
+
itemGap: 8,
|
|
90
|
+
formatter: function(name) {
|
|
91
|
+
const value = legendValue ? (0, import_chartUtils.numberFormatMust)(seriesTotal[name] || 0) : 0;
|
|
92
|
+
let showName = name;
|
|
93
|
+
if (seriesData.length >= 4) {
|
|
94
|
+
const strLen = 15;
|
|
95
|
+
if (name.length > strLen) {
|
|
96
|
+
showName = name.substring(0, strLen) + "...";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return legendValue ? `{labelName|${showName}}
|
|
100
|
+
{labelMark|${value}}` : `{labelName|${showName}}`;
|
|
101
|
+
},
|
|
102
|
+
textStyle: {
|
|
103
|
+
fontWeight: 500,
|
|
104
|
+
fontSize: 12,
|
|
105
|
+
color: "#364141",
|
|
106
|
+
lineHeight: 6,
|
|
107
|
+
rich: {
|
|
108
|
+
// 给labelName添加样式
|
|
109
|
+
labelName: {
|
|
110
|
+
fontWeight: 500,
|
|
111
|
+
fontSize: 12,
|
|
112
|
+
padding: [6, 6, 0, 0]
|
|
113
|
+
},
|
|
114
|
+
// 给labelMark添加样式
|
|
115
|
+
labelMark: {
|
|
116
|
+
color: "#7A8283",
|
|
117
|
+
fontSize: 12,
|
|
118
|
+
padding: [30, 0, 0, 0]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
tooltip: tooltipConfig,
|
|
124
|
+
color: chartColor,
|
|
125
|
+
animation: false,
|
|
126
|
+
grid: {
|
|
127
|
+
top: "24px",
|
|
128
|
+
bottom: 40,
|
|
129
|
+
left: 4,
|
|
130
|
+
containLabel: true
|
|
131
|
+
},
|
|
132
|
+
xAxis: {
|
|
133
|
+
type: "category",
|
|
134
|
+
axisLine: {
|
|
135
|
+
lineStyle: {
|
|
136
|
+
color: "#e5e5e5"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
axisTick: {
|
|
140
|
+
show: true,
|
|
141
|
+
alignWithLabel: true,
|
|
142
|
+
length: 5
|
|
143
|
+
},
|
|
144
|
+
axisLabel: {
|
|
145
|
+
interval: "auto",
|
|
146
|
+
margin: 12,
|
|
147
|
+
color: "#515E5F",
|
|
148
|
+
fontWeight: 500,
|
|
149
|
+
fontSize: 12,
|
|
150
|
+
lineHeight: 20
|
|
151
|
+
},
|
|
152
|
+
splitLine: {
|
|
153
|
+
show: false,
|
|
154
|
+
interval: 0
|
|
155
|
+
},
|
|
156
|
+
boundaryGap: false,
|
|
157
|
+
data: xAxis
|
|
158
|
+
},
|
|
159
|
+
yAxis: {
|
|
160
|
+
type: "value",
|
|
161
|
+
minInterval: 1,
|
|
162
|
+
axisLabel: {
|
|
163
|
+
formatter: function(value) {
|
|
164
|
+
let formatted = (0, import_chartUtils.numberFormatNull)(value);
|
|
165
|
+
if (formatted.length < 4) {
|
|
166
|
+
formatted = " " + formatted;
|
|
167
|
+
}
|
|
168
|
+
return formatted;
|
|
169
|
+
},
|
|
170
|
+
margin: 14,
|
|
171
|
+
color: "#515E5F",
|
|
172
|
+
fontSize: 12,
|
|
173
|
+
lineHeight: 20
|
|
174
|
+
},
|
|
175
|
+
splitLine: {
|
|
176
|
+
lineStyle: {
|
|
177
|
+
type: "dashed",
|
|
178
|
+
color: "#E5E5E5"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
series
|
|
183
|
+
};
|
|
184
|
+
myChart.off("mouseover");
|
|
185
|
+
myChart.on("mouseover", function(params) {
|
|
186
|
+
const updateOption = {
|
|
187
|
+
series: [],
|
|
188
|
+
legend: {
|
|
189
|
+
data: []
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
option.series.forEach((item) => {
|
|
193
|
+
if (params.seriesName === item.name) {
|
|
194
|
+
item.showSymbol = true;
|
|
195
|
+
item.data.forEach((val, index) => {
|
|
196
|
+
if (index === params.dataIndex) {
|
|
197
|
+
val.symbolSize = 12;
|
|
198
|
+
} else {
|
|
199
|
+
val.symbolSize = 0;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
option.legend.data.forEach((item) => {
|
|
205
|
+
if (params.seriesName !== item.name) {
|
|
206
|
+
item.textStyle = {};
|
|
207
|
+
item.itemStyle = {};
|
|
208
|
+
item.textStyle.opacity = 0.2;
|
|
209
|
+
item.itemStyle.opacity = 0.2;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
updateOption.series = option.series;
|
|
213
|
+
updateOption.legend.data = option.legend.data;
|
|
214
|
+
myChart.setOption(updateOption);
|
|
215
|
+
});
|
|
216
|
+
myChart.off("mouseout");
|
|
217
|
+
myChart.on("mouseout", function(params) {
|
|
218
|
+
const updateOption = {
|
|
219
|
+
series: [],
|
|
220
|
+
legend: {
|
|
221
|
+
data: []
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
option.series.forEach((item) => {
|
|
225
|
+
if (params.seriesName === item.name) {
|
|
226
|
+
item.showSymbol = false;
|
|
227
|
+
item.data.forEach((val) => {
|
|
228
|
+
val.symbolSize = 8;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
option.legend.data.forEach((item) => {
|
|
233
|
+
item.textStyle = {};
|
|
234
|
+
item.itemStyle = {};
|
|
235
|
+
item.textStyle.opacity = 1;
|
|
236
|
+
item.itemStyle.opacity = 1;
|
|
237
|
+
});
|
|
238
|
+
updateOption.series = option.series;
|
|
239
|
+
updateOption.legend.data = option.legend.data;
|
|
240
|
+
myChart.setOption(updateOption);
|
|
241
|
+
let flag = false;
|
|
242
|
+
let pixelPoint = myChart.convertToPixel(
|
|
243
|
+
{ seriesIndex: params.seriesIndex },
|
|
244
|
+
[params.dataIndex, params.value]
|
|
245
|
+
);
|
|
246
|
+
if (params && params.event && params.event.offsetX) {
|
|
247
|
+
if (params.dataIndex === 0 && params.event.offsetX >= pixelPoint[0]) {
|
|
248
|
+
flag = true;
|
|
249
|
+
} else if (params.dataIndex === xAxis.length - 1 && params.event.offsetX <= pixelPoint[0]) {
|
|
250
|
+
flag = true;
|
|
251
|
+
} else if (params.dataIndex !== 0 && params.dataIndex !== xAxis.length - 1) {
|
|
252
|
+
flag = true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (flag) {
|
|
256
|
+
myChart.dispatchAction({
|
|
257
|
+
type: "highlight",
|
|
258
|
+
dataIndex: params.dataIndex
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
let mouseoutFlag = true;
|
|
262
|
+
myChart.on("hideTip", function(event) {
|
|
263
|
+
if (mouseoutFlag) {
|
|
264
|
+
myChart.dispatchAction({
|
|
265
|
+
type: "downplay",
|
|
266
|
+
dataIndex: params.dataIndex
|
|
267
|
+
});
|
|
268
|
+
mouseoutFlag = false;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
let currentIndex = 0;
|
|
273
|
+
let flagIndex = 0;
|
|
274
|
+
myChart.off("showTip");
|
|
275
|
+
myChart.on("showTip", function(event) {
|
|
276
|
+
if (flagIndex !== event.dataIndex) {
|
|
277
|
+
(0, import_chartUtils.toggleAxisPointer)(myChart, true);
|
|
278
|
+
myChart.dispatchAction({
|
|
279
|
+
type: "highlight",
|
|
280
|
+
dataIndex: event.dataIndex
|
|
281
|
+
});
|
|
282
|
+
currentIndex = event.dataIndex;
|
|
283
|
+
flagIndex = event.dataIndex;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
myChart.setOption(option, true);
|
|
287
|
+
myChart.off("rendered");
|
|
288
|
+
myChart.on("rendered", () => {
|
|
289
|
+
(0, import_chartUtils.dealPath)(id);
|
|
290
|
+
});
|
|
291
|
+
const element = document.querySelector(`.${id}`);
|
|
292
|
+
if (element) {
|
|
293
|
+
element.addEventListener("mouseleave", function(event) {
|
|
294
|
+
if (event && element.offsetHeight && event.offsetY < element.offsetHeight - 2) {
|
|
295
|
+
(0, import_chartUtils.toggleAxisPointer)(myChart, false);
|
|
296
|
+
flagIndex = 0;
|
|
297
|
+
myChart.dispatchAction({
|
|
298
|
+
type: "downplay",
|
|
299
|
+
dataIndex: currentIndex
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
return /* @__PURE__ */ React.createElement("div", { ref: chartRef, id, style: { width, height } });
|
|
306
|
+
}
|
|
307
|
+
var line_default = Line;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
.onesight-line-tooltip {
|
|
2
|
+
min-width: 280px;
|
|
3
|
+
border-color: #dddddd;
|
|
4
|
+
box-shadow: 0 6px 20px 0 rgba(0, 0, 0, 0.13);
|
|
5
|
+
border-radius: 8px;
|
|
6
|
+
padding: 0;
|
|
7
|
+
.tooltip-wrap {
|
|
8
|
+
position: relative;
|
|
9
|
+
}
|
|
10
|
+
.tooltip-head {
|
|
11
|
+
white-space: nowrap;
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
text-overflow: ellipsis;
|
|
14
|
+
border-bottom: 1px solid #eeeeee;
|
|
15
|
+
padding: 10px 16px 10px;
|
|
16
|
+
font-weight: bold;
|
|
17
|
+
font-size: 15px;
|
|
18
|
+
color: #364141;
|
|
19
|
+
line-height: 22px;
|
|
20
|
+
}
|
|
21
|
+
.tooltip-body {
|
|
22
|
+
padding: 0 0 0 8px;
|
|
23
|
+
max-height: 213.64px;
|
|
24
|
+
overflow-y: auto;
|
|
25
|
+
.total {
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: space-between;
|
|
29
|
+
line-height: 20px;
|
|
30
|
+
font-size: 14px;
|
|
31
|
+
font-weight: 600;
|
|
32
|
+
color: #364141;
|
|
33
|
+
padding: 14px 8px 2px 8px;
|
|
34
|
+
}
|
|
35
|
+
.item {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: space-between;
|
|
39
|
+
line-height: 20px;
|
|
40
|
+
font-weight: 400;
|
|
41
|
+
font-size: 14px;
|
|
42
|
+
color: #515e5f;
|
|
43
|
+
cursor: pointer;
|
|
44
|
+
border-radius: 6px;
|
|
45
|
+
margin-top: 8px;
|
|
46
|
+
margin-right: 1px;
|
|
47
|
+
height: 32px;
|
|
48
|
+
padding: 0 8px;
|
|
49
|
+
.l {
|
|
50
|
+
flex-grow: 1;
|
|
51
|
+
flex-shrink: 1;
|
|
52
|
+
flex-basis: auto;
|
|
53
|
+
white-space: nowrap;
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
text-overflow: ellipsis;
|
|
56
|
+
}
|
|
57
|
+
.l-color {
|
|
58
|
+
display: inline-block;
|
|
59
|
+
margin-right: 6px;
|
|
60
|
+
margin-left: 2px;
|
|
61
|
+
margin-bottom: 3px;
|
|
62
|
+
width: 16px;
|
|
63
|
+
height: 4px;
|
|
64
|
+
vertical-align: middle;
|
|
65
|
+
}
|
|
66
|
+
.r {
|
|
67
|
+
padding-left: 6px;
|
|
68
|
+
flex-grow: 0;
|
|
69
|
+
flex-shrink: 0;
|
|
70
|
+
white-space: nowrap;
|
|
71
|
+
.num {
|
|
72
|
+
vertical-align: baseline;
|
|
73
|
+
font-weight: bold;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
.item:last-child {
|
|
78
|
+
margin-bottom: 8px;
|
|
79
|
+
border-bottom: none;
|
|
80
|
+
}
|
|
81
|
+
.item:only-child {
|
|
82
|
+
line-height: 32px;
|
|
83
|
+
}
|
|
84
|
+
.item:hover {
|
|
85
|
+
background: #f3f4f4;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
.triangle-down {
|
|
89
|
+
width: 280px;
|
|
90
|
+
height: 12px;
|
|
91
|
+
background: transparent;
|
|
92
|
+
position: absolute; /* 使用绝对定位 */
|
|
93
|
+
bottom: -12px; /* 将三角形移动到div的外部 */
|
|
94
|
+
left: 50%; /* 水平居中 */
|
|
95
|
+
transform: translateX(-50%); /* 精确调整以确保居中 */
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.triangle-down::after {
|
|
99
|
+
content: '';
|
|
100
|
+
width: 0;
|
|
101
|
+
height: 0;
|
|
102
|
+
border-left: 8px solid transparent;
|
|
103
|
+
border-right: 8px solid transparent;
|
|
104
|
+
border-top: 8px solid white;
|
|
105
|
+
position: absolute;
|
|
106
|
+
left: 50%;
|
|
107
|
+
transform: translateX(-50%);
|
|
108
|
+
filter: drop-shadow(0 1px 0 #dddddd);
|
|
109
|
+
}
|
|
110
|
+
}
|