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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) wudong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# onesight-charts
|
|
2
|
+
|
|
3
|
+
这是 OneSight 前端图表的公共组件库,提供了一系列用于数据可视化的图表组件。
|
|
4
|
+
|
|
5
|
+
## 开发指南
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# 安装依赖
|
|
9
|
+
$ pnpm install
|
|
10
|
+
|
|
11
|
+
# 通过文档演示开发图表库
|
|
12
|
+
$ pnpm start
|
|
13
|
+
|
|
14
|
+
# 构建图表库源代码
|
|
15
|
+
$ pnpm run build
|
|
16
|
+
|
|
17
|
+
# 监听模式下构建图表库源代码
|
|
18
|
+
$ pnpm run build:watch
|
|
19
|
+
|
|
20
|
+
# 构建文档
|
|
21
|
+
$ pnpm run docs:build
|
|
22
|
+
|
|
23
|
+
# 检查项目潜在问题
|
|
24
|
+
$ pnpm run doctor
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import LineChart from "./index.jsx";
|
|
3
|
+
var xAxis = ['07/25', '07/26', '07/27', '07/28', '07/29', '07/30', '07/31'];
|
|
4
|
+
var seriesData = {
|
|
5
|
+
Facebook: [1002, 831, 960, 750, 1451, 1717, 903],
|
|
6
|
+
X: [22094, 20075, 17410, 12374, 13413, 13904, 6895]
|
|
7
|
+
};
|
|
8
|
+
export default (function () {
|
|
9
|
+
return /*#__PURE__*/React.createElement(LineChart, {
|
|
10
|
+
xAxis: xAxis,
|
|
11
|
+
seriesData: seriesData
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import * as echarts from 'echarts';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { calculateSeriesTotal, convertSeriesData, dealPath, numberFormatMust, numberFormatNull, toggleAxisPointer } from "../../utils/chartUtils";
|
|
4
|
+
import { defaultChartColors } from "../../utils/colors";
|
|
5
|
+
import { createCustomTooltip } from "./tooltipConfig";
|
|
6
|
+
import "./style.scss";
|
|
7
|
+
function Line(props) {
|
|
8
|
+
var _props$id = props.id,
|
|
9
|
+
id = _props$id === void 0 ? 'lineId' : _props$id,
|
|
10
|
+
_props$width = props.width,
|
|
11
|
+
width = _props$width === void 0 ? '100%' : _props$width,
|
|
12
|
+
_props$height = props.height,
|
|
13
|
+
height = _props$height === void 0 ? '400px' : _props$height,
|
|
14
|
+
color = props.color,
|
|
15
|
+
xAxis = props.xAxis,
|
|
16
|
+
seriesData = props.seriesData,
|
|
17
|
+
tooltipClassName = props.tooltipClassName,
|
|
18
|
+
_props$legendValue = props.legendValue,
|
|
19
|
+
legendValue = _props$legendValue === void 0 ? true : _props$legendValue,
|
|
20
|
+
_props$showRate = props.showRate,
|
|
21
|
+
showRate = _props$showRate === void 0 ? true : _props$showRate,
|
|
22
|
+
_props$tooltipTotalNa = props.tooltipTotalName,
|
|
23
|
+
tooltipTotalName = _props$tooltipTotalNa === void 0 ? '总计' : _props$tooltipTotalNa,
|
|
24
|
+
_props$tooltipPositio = props.tooltipPosition,
|
|
25
|
+
tooltipPosition = _props$tooltipPositio === void 0 ? true : _props$tooltipPositio;
|
|
26
|
+
var chartRef = useRef(null);
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
ceartChart();
|
|
29
|
+
}, [seriesData]);
|
|
30
|
+
var seriesTotal = legendValue ? calculateSeriesTotal(seriesData) : {};
|
|
31
|
+
var ceartChart = function ceartChart() {
|
|
32
|
+
var chartColor = color || defaultChartColors;
|
|
33
|
+
var myChart = echarts.init(chartRef.current, null, {
|
|
34
|
+
renderer: 'svg'
|
|
35
|
+
});
|
|
36
|
+
var tooltipConfig = createCustomTooltip({
|
|
37
|
+
id: id,
|
|
38
|
+
tooltipClassName: tooltipClassName,
|
|
39
|
+
myChart: myChart,
|
|
40
|
+
seriesData: seriesData,
|
|
41
|
+
tooltipTotalName: tooltipTotalName,
|
|
42
|
+
showRate: showRate,
|
|
43
|
+
tooltipPosition: tooltipPosition
|
|
44
|
+
});
|
|
45
|
+
var series = convertSeriesData(seriesData);
|
|
46
|
+
var legendData = Object.keys(seriesData).map(function (item) {
|
|
47
|
+
return {
|
|
48
|
+
name: item
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
var option = {
|
|
52
|
+
legend: {
|
|
53
|
+
data: legendData,
|
|
54
|
+
x: 'center',
|
|
55
|
+
type: 'plain',
|
|
56
|
+
bottom: 0,
|
|
57
|
+
padding: 0,
|
|
58
|
+
left: 'center',
|
|
59
|
+
icon: 'rect',
|
|
60
|
+
itemWidth: 16,
|
|
61
|
+
itemHeight: 4,
|
|
62
|
+
itemGap: 8,
|
|
63
|
+
formatter: function formatter(name) {
|
|
64
|
+
var value = legendValue ? numberFormatMust(seriesTotal[name] || 0) : 0;
|
|
65
|
+
var showName = name;
|
|
66
|
+
if (seriesData.length >= 4) {
|
|
67
|
+
var strLen = 15;
|
|
68
|
+
if (name.length > strLen) {
|
|
69
|
+
showName = name.substring(0, strLen) + '...';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return legendValue ? "{labelName|".concat(showName, "}\n{labelMark|").concat(value, "}") : "{labelName|".concat(showName, "}");
|
|
73
|
+
},
|
|
74
|
+
textStyle: {
|
|
75
|
+
fontWeight: 500,
|
|
76
|
+
fontSize: 12,
|
|
77
|
+
color: '#364141',
|
|
78
|
+
lineHeight: 6,
|
|
79
|
+
rich: {
|
|
80
|
+
// 给labelName添加样式
|
|
81
|
+
labelName: {
|
|
82
|
+
fontWeight: 500,
|
|
83
|
+
fontSize: 12,
|
|
84
|
+
padding: [6, 6, 0, 0]
|
|
85
|
+
},
|
|
86
|
+
// 给labelMark添加样式
|
|
87
|
+
labelMark: {
|
|
88
|
+
color: '#7A8283',
|
|
89
|
+
fontSize: 12,
|
|
90
|
+
padding: [30, 0, 0, 0]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
tooltip: tooltipConfig,
|
|
96
|
+
color: chartColor,
|
|
97
|
+
animation: false,
|
|
98
|
+
grid: {
|
|
99
|
+
top: '24px',
|
|
100
|
+
bottom: 40,
|
|
101
|
+
left: 4,
|
|
102
|
+
containLabel: true
|
|
103
|
+
},
|
|
104
|
+
xAxis: {
|
|
105
|
+
type: 'category',
|
|
106
|
+
axisLine: {
|
|
107
|
+
lineStyle: {
|
|
108
|
+
color: '#e5e5e5'
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
axisTick: {
|
|
112
|
+
show: true,
|
|
113
|
+
alignWithLabel: true,
|
|
114
|
+
length: 5
|
|
115
|
+
},
|
|
116
|
+
axisLabel: {
|
|
117
|
+
interval: 'auto',
|
|
118
|
+
margin: 12,
|
|
119
|
+
color: '#515E5F',
|
|
120
|
+
fontWeight: 500,
|
|
121
|
+
fontSize: 12,
|
|
122
|
+
lineHeight: 20
|
|
123
|
+
},
|
|
124
|
+
splitLine: {
|
|
125
|
+
show: false,
|
|
126
|
+
interval: 0
|
|
127
|
+
},
|
|
128
|
+
boundaryGap: false,
|
|
129
|
+
data: xAxis
|
|
130
|
+
},
|
|
131
|
+
yAxis: {
|
|
132
|
+
type: 'value',
|
|
133
|
+
minInterval: 1,
|
|
134
|
+
axisLabel: {
|
|
135
|
+
formatter: function formatter(value) {
|
|
136
|
+
var formatted = numberFormatNull(value);
|
|
137
|
+
if (formatted.length < 4) {
|
|
138
|
+
// 假设最大长度为4
|
|
139
|
+
formatted = ' ' + formatted; // 在前面添加空格
|
|
140
|
+
}
|
|
141
|
+
return formatted;
|
|
142
|
+
},
|
|
143
|
+
margin: 14,
|
|
144
|
+
color: '#515E5F',
|
|
145
|
+
fontSize: 12,
|
|
146
|
+
lineHeight: 20
|
|
147
|
+
},
|
|
148
|
+
splitLine: {
|
|
149
|
+
lineStyle: {
|
|
150
|
+
type: 'dashed',
|
|
151
|
+
color: '#E5E5E5'
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
series: series
|
|
156
|
+
};
|
|
157
|
+
myChart.off('mouseover');
|
|
158
|
+
myChart.on('mouseover', function (params) {
|
|
159
|
+
// 操作线上选中点
|
|
160
|
+
var updateOption = {
|
|
161
|
+
series: [],
|
|
162
|
+
legend: {
|
|
163
|
+
data: []
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
option.series.forEach(function (item) {
|
|
167
|
+
if (params.seriesName === item.name) {
|
|
168
|
+
item.showSymbol = true;
|
|
169
|
+
item.data.forEach(function (val, index) {
|
|
170
|
+
if (index === params.dataIndex) {
|
|
171
|
+
val.symbolSize = 12;
|
|
172
|
+
} else {
|
|
173
|
+
val.symbolSize = 0;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
// 操作图例
|
|
179
|
+
option.legend.data.forEach(function (item) {
|
|
180
|
+
if (params.seriesName !== item.name) {
|
|
181
|
+
item.textStyle = {};
|
|
182
|
+
item.itemStyle = {};
|
|
183
|
+
item.textStyle.opacity = 0.2;
|
|
184
|
+
item.itemStyle.opacity = 0.2;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
updateOption.series = option.series;
|
|
188
|
+
updateOption.legend.data = option.legend.data;
|
|
189
|
+
myChart.setOption(updateOption);
|
|
190
|
+
});
|
|
191
|
+
myChart.off('mouseout');
|
|
192
|
+
myChart.on('mouseout', function (params) {
|
|
193
|
+
var updateOption = {
|
|
194
|
+
series: [],
|
|
195
|
+
legend: {
|
|
196
|
+
data: []
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
// 操作线上选中点
|
|
200
|
+
option.series.forEach(function (item) {
|
|
201
|
+
if (params.seriesName === item.name) {
|
|
202
|
+
item.showSymbol = false;
|
|
203
|
+
item.data.forEach(function (val) {
|
|
204
|
+
val.symbolSize = 8;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
// 操作图例
|
|
209
|
+
option.legend.data.forEach(function (item) {
|
|
210
|
+
item.textStyle = {};
|
|
211
|
+
item.itemStyle = {};
|
|
212
|
+
item.textStyle.opacity = 1;
|
|
213
|
+
item.itemStyle.opacity = 1;
|
|
214
|
+
});
|
|
215
|
+
updateOption.series = option.series;
|
|
216
|
+
updateOption.legend.data = option.legend.data;
|
|
217
|
+
myChart.setOption(updateOption);
|
|
218
|
+
var flag = false;
|
|
219
|
+
var pixelPoint = myChart.convertToPixel({
|
|
220
|
+
seriesIndex: params.seriesIndex
|
|
221
|
+
}, [params.dataIndex, params.value]);
|
|
222
|
+
if (params && params.event && params.event.offsetX) {
|
|
223
|
+
if (params.dataIndex === 0 && params.event.offsetX >= pixelPoint[0]) {
|
|
224
|
+
flag = true;
|
|
225
|
+
} else if (params.dataIndex === xAxis.length - 1 && params.event.offsetX <= pixelPoint[0]) {
|
|
226
|
+
flag = true;
|
|
227
|
+
} else if (params.dataIndex !== 0 && params.dataIndex !== xAxis.length - 1) {
|
|
228
|
+
flag = true;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (flag) {
|
|
232
|
+
myChart.dispatchAction({
|
|
233
|
+
type: 'highlight',
|
|
234
|
+
dataIndex: params.dataIndex
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
var mouseoutFlag = true;
|
|
238
|
+
myChart.on('hideTip', function (event) {
|
|
239
|
+
if (mouseoutFlag) {
|
|
240
|
+
myChart.dispatchAction({
|
|
241
|
+
type: 'downplay',
|
|
242
|
+
dataIndex: params.dataIndex
|
|
243
|
+
});
|
|
244
|
+
mouseoutFlag = false;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
var currentIndex = 0;
|
|
249
|
+
var flagIndex = 0;
|
|
250
|
+
myChart.off('showTip');
|
|
251
|
+
myChart.on('showTip', function (event) {
|
|
252
|
+
if (flagIndex !== event.dataIndex) {
|
|
253
|
+
toggleAxisPointer(myChart, true);
|
|
254
|
+
myChart.dispatchAction({
|
|
255
|
+
type: 'highlight',
|
|
256
|
+
dataIndex: event.dataIndex
|
|
257
|
+
});
|
|
258
|
+
currentIndex = event.dataIndex;
|
|
259
|
+
flagIndex = event.dataIndex;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
myChart.setOption(option, true);
|
|
263
|
+
|
|
264
|
+
// 提高图例清晰度
|
|
265
|
+
myChart.off('rendered');
|
|
266
|
+
myChart.on('rendered', function () {
|
|
267
|
+
dealPath(id);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// 增强交互效果
|
|
271
|
+
var element = document.querySelector(".".concat(id));
|
|
272
|
+
if (element) {
|
|
273
|
+
element.addEventListener('mouseleave', function (event) {
|
|
274
|
+
if (event && element.offsetHeight && event.offsetY < element.offsetHeight - 2) {
|
|
275
|
+
toggleAxisPointer(myChart, false);
|
|
276
|
+
flagIndex = 0;
|
|
277
|
+
myChart.dispatchAction({
|
|
278
|
+
type: 'downplay',
|
|
279
|
+
dataIndex: currentIndex
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
286
|
+
ref: chartRef,
|
|
287
|
+
id: id,
|
|
288
|
+
style: {
|
|
289
|
+
width: width,
|
|
290
|
+
height: height
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
export 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
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
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
|
+
import { changeDataTypeEn, computeFloatNull, computePos } from "../../utils/chartUtils";
|
|
8
|
+
export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
9
|
+
var id = _ref.id,
|
|
10
|
+
tooltipClassName = _ref.tooltipClassName,
|
|
11
|
+
myChart = _ref.myChart,
|
|
12
|
+
seriesData = _ref.seriesData,
|
|
13
|
+
tooltipTotalName = _ref.tooltipTotalName,
|
|
14
|
+
showRate = _ref.showRate,
|
|
15
|
+
tooltipPosition = _ref.tooltipPosition;
|
|
16
|
+
return {
|
|
17
|
+
className: "onesight-line-tooltip ".concat(tooltipClassName, " ").concat(id),
|
|
18
|
+
trigger: 'axis',
|
|
19
|
+
enterable: true,
|
|
20
|
+
axisPointer: {
|
|
21
|
+
z: 1,
|
|
22
|
+
show: true,
|
|
23
|
+
type: 'line',
|
|
24
|
+
lineStyle: {
|
|
25
|
+
color: 'rgba(0, 0, 0, 0.24)',
|
|
26
|
+
type: 'solid',
|
|
27
|
+
width: 2
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
padding: 0,
|
|
31
|
+
// showContent: true,
|
|
32
|
+
// alwaysShowContent: true,
|
|
33
|
+
// hideDelay: 1000000000,
|
|
34
|
+
position: tooltipPosition ? function (point, params) {
|
|
35
|
+
var pixelPoint = myChart.convertToPixel({
|
|
36
|
+
seriesIndex: params[0].seriesIndex
|
|
37
|
+
}, [params[0].dataIndex, params[0].value]);
|
|
38
|
+
var element = document.querySelector(".".concat(id));
|
|
39
|
+
var yValue = 0;
|
|
40
|
+
var currentWidth = 0;
|
|
41
|
+
if (element) {
|
|
42
|
+
if (element.offsetHeight) {
|
|
43
|
+
yValue = -element.offsetHeight + 14;
|
|
44
|
+
}
|
|
45
|
+
if (element.offsetWidth) {
|
|
46
|
+
currentWidth = element.offsetWidth;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var x = computePos(pixelPoint[0], currentWidth);
|
|
50
|
+
return [x, yValue];
|
|
51
|
+
} : undefined,
|
|
52
|
+
formatter: function formatter(res) {
|
|
53
|
+
if (!res.some(function (i) {
|
|
54
|
+
return i.value !== undefined && i.value !== null;
|
|
55
|
+
})) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
var total = 0;
|
|
59
|
+
var dataArr = _toConsumableArray(res);
|
|
60
|
+
res.forEach(function (v) {
|
|
61
|
+
total += v.value || 0;
|
|
62
|
+
});
|
|
63
|
+
var resNameArr = res.map(function (item) {
|
|
64
|
+
return item.seriesName;
|
|
65
|
+
});
|
|
66
|
+
var resColorArr = res.map(function (item) {
|
|
67
|
+
return item.color;
|
|
68
|
+
});
|
|
69
|
+
var allName = Object.keys(seriesData);
|
|
70
|
+
var currentName = allName.filter(function (item) {
|
|
71
|
+
return resNameArr.includes(item);
|
|
72
|
+
});
|
|
73
|
+
dataArr = currentName.map(function (item, index) {
|
|
74
|
+
var dataIndex = res[0].dataIndex;
|
|
75
|
+
var num = seriesData[item][dataIndex];
|
|
76
|
+
return {
|
|
77
|
+
color: resColorArr[index],
|
|
78
|
+
seriesName: item,
|
|
79
|
+
value: num,
|
|
80
|
+
proportion: num / total,
|
|
81
|
+
date: res[0].axisValue
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
var marginRight = 7;
|
|
85
|
+
if (dataArr.length > 4) {
|
|
86
|
+
marginRight = 3;
|
|
87
|
+
}
|
|
88
|
+
return "\n <div class='tooltip-wrap'>\n <div class='tooltip-head'>\n ".concat(res[0].axisValue, "\n </div>\n <div class='tooltip-body' style=\"margin-right:").concat(marginRight, "px\">\n ").concat(dataArr.length > 1 ? "\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) {
|
|
89
|
+
return "\n <div class='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, "\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 ");
|
|
90
|
+
}).join(''), "\n </div>\n ").concat(tooltipPosition ? '<div class="triangle-down"></div>' : '', "\n </div>\n ");
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|