onesight-charts 0.0.3 → 0.0.5
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/es/components/download-image/demo/index.js +22 -0
- package/es/components/download-image/index.js +63 -0
- package/es/components/icon/index.js +16 -0
- package/es/components/line/demo.js +13 -0
- package/es/components/line/index.js +293 -0
- package/es/components/line/tooltipConfig.js +93 -0
- package/es/components/one-table/demo/line-chart.js +908 -0
- package/es/components/one-table/index.js +128 -0
- package/es/components/pie/demo/demo.js +22 -0
- package/es/components/pie/demo/legendDemo.js +24 -0
- package/es/components/pie/demo/orderDemo.js +25 -0
- package/es/components/pie/demo/paginationDemo.js +73 -0
- package/es/components/pie/demo/tooltipDemo.js +24 -0
- package/es/components/pie/index.js +196 -0
- package/es/components/pie/legend/index.js +134 -0
- package/es/components/pie/pagination/index.js +43 -0
- package/es/components/pie/tooltipConfig.js +43 -0
- package/es/index.js +1 -0
- package/es/utils/chartUtils.js +253 -0
- package/es/utils/colors.js +26 -0
- package/es/utils/common.js +42 -0
- package/lib/components/download-image/index.scss +64 -0
- package/lib/components/icon/iconfont.css +23 -0
- package/lib/components/icon/iconfont.ttf +0 -0
- package/lib/components/icon/iconfont.woff +0 -0
- package/lib/components/icon/iconfont.woff2 +0 -0
- package/lib/components/line/style.scss +110 -0
- package/lib/components/one-table/index.scss +5 -0
- package/lib/components/pie/legend/style.scss +125 -0
- package/lib/components/pie/pagination/style.scss +45 -0
- package/lib/components/pie/style.scss +85 -0
- package/package.json +5 -3
- /package/{dist → es}/components/download-image/index.scss +0 -0
- /package/{dist → es}/components/icon/iconfont.css +0 -0
- /package/{dist → es}/components/icon/iconfont.ttf +0 -0
- /package/{dist → es}/components/icon/iconfont.woff +0 -0
- /package/{dist → es}/components/icon/iconfont.woff2 +0 -0
- /package/{dist → es}/components/line/style.scss +0 -0
- /package/{dist → es}/components/one-table/index.scss +0 -0
- /package/{dist → es}/components/pie/legend/style.scss +0 -0
- /package/{dist → es}/components/pie/pagination/style.scss +0 -0
- /package/{dist → es}/components/pie/style.scss +0 -0
- /package/{dist → lib}/components/download-image/demo/index.js +0 -0
- /package/{dist → lib}/components/download-image/index.js +0 -0
- /package/{dist → lib}/components/icon/index.js +0 -0
- /package/{dist → lib}/components/line/demo.js +0 -0
- /package/{dist → lib}/components/line/index.js +0 -0
- /package/{dist → lib}/components/line/tooltipConfig.js +0 -0
- /package/{dist → lib}/components/one-table/demo/line-chart.js +0 -0
- /package/{dist → lib}/components/one-table/index.js +0 -0
- /package/{dist → lib}/components/pie/demo/demo.js +0 -0
- /package/{dist → lib}/components/pie/demo/legendDemo.js +0 -0
- /package/{dist → lib}/components/pie/demo/orderDemo.js +0 -0
- /package/{dist → lib}/components/pie/demo/paginationDemo.js +0 -0
- /package/{dist → lib}/components/pie/demo/tooltipDemo.js +0 -0
- /package/{dist → lib}/components/pie/index.js +0 -0
- /package/{dist → lib}/components/pie/legend/index.js +0 -0
- /package/{dist → lib}/components/pie/pagination/index.js +0 -0
- /package/{dist → lib}/components/pie/tooltipConfig.js +0 -0
- /package/{dist → lib}/index.js +0 -0
- /package/{dist → lib}/utils/chartUtils.js +0 -0
- /package/{dist → lib}/utils/colors.js +0 -0
- /package/{dist → lib}/utils/common.js +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import Line from "../../line";
|
|
3
|
+
import DownloadImage from "../index.jsx";
|
|
4
|
+
var xAxis = ['07/25', '07/26', '07/27', '07/28', '07/29', '07/30', '07/31'];
|
|
5
|
+
var seriesData = {
|
|
6
|
+
Facebook: [1002, 831, 960, 750, 1451, 1717, 903],
|
|
7
|
+
X: [22094, 20075, 17410, 12374, 13413, 13904, 6895]
|
|
8
|
+
};
|
|
9
|
+
export default (function () {
|
|
10
|
+
var dimensionDOM = useRef(); // 提及趋势 DOM
|
|
11
|
+
|
|
12
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
13
|
+
ref: dimensionDOM
|
|
14
|
+
}, /*#__PURE__*/React.createElement(Line, {
|
|
15
|
+
xAxis: xAxis,
|
|
16
|
+
seriesData: seriesData
|
|
17
|
+
}), /*#__PURE__*/React.createElement(DownloadImage, {
|
|
18
|
+
loading: false,
|
|
19
|
+
DOM: dimensionDOM,
|
|
20
|
+
fileName: "download-chart"
|
|
21
|
+
}));
|
|
22
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
import { Dropdown, Menu } from 'antd';
|
|
8
|
+
import domtoimage from 'dom-to-image';
|
|
9
|
+
import React, { useState } from 'react';
|
|
10
|
+
// import { useIntl } from 'umi';
|
|
11
|
+
import { DownloadFile } from "../../utils/common";
|
|
12
|
+
import "./index.scss";
|
|
13
|
+
function DownloadImage(_ref) {
|
|
14
|
+
var Loading = _ref.Loading,
|
|
15
|
+
DOM = _ref.DOM,
|
|
16
|
+
FileName = _ref.FileName;
|
|
17
|
+
// const { formatMessage } = useIntl();
|
|
18
|
+
var _useState = useState(false),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
visiable = _useState2[0],
|
|
21
|
+
setVisiable = _useState2[1];
|
|
22
|
+
// 导出csv 和 png图片
|
|
23
|
+
var handleMenuFn = function handleMenuFn(value) {
|
|
24
|
+
if (Loading) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (value.key === 'csv') {
|
|
28
|
+
console.log(value, 'csv');
|
|
29
|
+
} else {
|
|
30
|
+
setVisiable(false);
|
|
31
|
+
setTimeout(function () {
|
|
32
|
+
domtoimage.toPng(DOM.current).then(function (dataUrl) {
|
|
33
|
+
DownloadFile(dataUrl, FileName ? FileName : 'filename');
|
|
34
|
+
}).catch(function (error) {
|
|
35
|
+
console.error('oops, something went wrong!', error);
|
|
36
|
+
});
|
|
37
|
+
}, 500);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
41
|
+
className: "dropdown_wrap"
|
|
42
|
+
}, /*#__PURE__*/React.createElement(Dropdown, {
|
|
43
|
+
getPopupContainer: function getPopupContainer(triggerNode) {
|
|
44
|
+
return triggerNode.parentElement;
|
|
45
|
+
},
|
|
46
|
+
visiable: true,
|
|
47
|
+
overlay: /*#__PURE__*/React.createElement(Menu, {
|
|
48
|
+
className: "dropdown_wrap_menu",
|
|
49
|
+
onClick: handleMenuFn
|
|
50
|
+
}, /*#__PURE__*/React.createElement(Menu.Item, {
|
|
51
|
+
key: "png"
|
|
52
|
+
}, /*#__PURE__*/React.createElement("a", null, /*#__PURE__*/React.createElement("i", {
|
|
53
|
+
className: "iconfont iconPNG"
|
|
54
|
+
})))),
|
|
55
|
+
trigger: ['click'],
|
|
56
|
+
placement: "topRight"
|
|
57
|
+
}, /*#__PURE__*/React.createElement("a", {
|
|
58
|
+
className: "common-btn common-more a-common-more ant-dropdown-trigger"
|
|
59
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
60
|
+
className: "iconfont icongengduo3"
|
|
61
|
+
}))));
|
|
62
|
+
}
|
|
63
|
+
export default DownloadImage;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "./iconfont.css";
|
|
2
|
+
function Icon(_ref) {
|
|
3
|
+
var name = _ref.name,
|
|
4
|
+
size = _ref.size,
|
|
5
|
+
color = _ref.color,
|
|
6
|
+
className = _ref.className;
|
|
7
|
+
var style = {
|
|
8
|
+
fontSize: size,
|
|
9
|
+
color: color
|
|
10
|
+
};
|
|
11
|
+
return /*#__PURE__*/React.createElement("i", {
|
|
12
|
+
className: "iconfont ".concat(name, " ").concat(className || ''),
|
|
13
|
+
style: style
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export default Icon;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Line 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(Line, {
|
|
10
|
+
xAxis: xAxis,
|
|
11
|
+
seriesData: seriesData
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,293 @@
|
|
|
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 myChart = echarts.init(chartRef.current, null, {
|
|
33
|
+
renderer: 'svg'
|
|
34
|
+
});
|
|
35
|
+
var tooltipConfig = createCustomTooltip({
|
|
36
|
+
id: id,
|
|
37
|
+
tooltipClassName: tooltipClassName,
|
|
38
|
+
myChart: myChart,
|
|
39
|
+
seriesData: seriesData,
|
|
40
|
+
tooltipTotalName: tooltipTotalName,
|
|
41
|
+
showRate: showRate,
|
|
42
|
+
tooltipPosition: tooltipPosition
|
|
43
|
+
});
|
|
44
|
+
var series = convertSeriesData(seriesData);
|
|
45
|
+
var legendData = Object.keys(seriesData).map(function (item) {
|
|
46
|
+
return {
|
|
47
|
+
name: item
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
var option = {
|
|
51
|
+
legend: {
|
|
52
|
+
data: legendData,
|
|
53
|
+
x: 'center',
|
|
54
|
+
type: 'plain',
|
|
55
|
+
bottom: 0,
|
|
56
|
+
padding: 0,
|
|
57
|
+
left: 'center',
|
|
58
|
+
icon: 'rect',
|
|
59
|
+
itemWidth: 16,
|
|
60
|
+
itemHeight: 4,
|
|
61
|
+
itemGap: 8,
|
|
62
|
+
formatter: function formatter(name) {
|
|
63
|
+
var value = legendValue ? numberFormatMust(seriesTotal[name] || 0) : 0;
|
|
64
|
+
var showName = name;
|
|
65
|
+
if (seriesData.length >= 4) {
|
|
66
|
+
var strLen = 15;
|
|
67
|
+
if (name.length > strLen) {
|
|
68
|
+
showName = name.substring(0, strLen) + '...';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return legendValue ? "{labelName|".concat(showName, "}\n{labelMark|").concat(value, "}") : "{labelName|".concat(showName, "}");
|
|
72
|
+
},
|
|
73
|
+
textStyle: {
|
|
74
|
+
fontWeight: 500,
|
|
75
|
+
fontSize: 12,
|
|
76
|
+
color: '#364141',
|
|
77
|
+
lineHeight: 6,
|
|
78
|
+
rich: {
|
|
79
|
+
// 给labelName添加样式
|
|
80
|
+
labelName: {
|
|
81
|
+
fontWeight: 500,
|
|
82
|
+
fontSize: 12,
|
|
83
|
+
padding: [6, 6, 0, 0]
|
|
84
|
+
},
|
|
85
|
+
// 给labelMark添加样式
|
|
86
|
+
labelMark: {
|
|
87
|
+
color: '#7A8283',
|
|
88
|
+
fontSize: 12,
|
|
89
|
+
padding: [30, 0, 0, 0]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
tooltip: tooltipConfig,
|
|
95
|
+
color: color || defaultChartColors,
|
|
96
|
+
animation: false,
|
|
97
|
+
grid: {
|
|
98
|
+
top: '24px',
|
|
99
|
+
bottom: 40,
|
|
100
|
+
left: 4,
|
|
101
|
+
containLabel: true
|
|
102
|
+
},
|
|
103
|
+
xAxis: {
|
|
104
|
+
type: 'category',
|
|
105
|
+
axisLine: {
|
|
106
|
+
lineStyle: {
|
|
107
|
+
color: '#e5e5e5'
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
axisTick: {
|
|
111
|
+
show: true,
|
|
112
|
+
alignWithLabel: true,
|
|
113
|
+
length: 5
|
|
114
|
+
},
|
|
115
|
+
axisLabel: {
|
|
116
|
+
interval: 'auto',
|
|
117
|
+
margin: 12,
|
|
118
|
+
color: '#515E5F',
|
|
119
|
+
fontWeight: 500,
|
|
120
|
+
fontSize: 12,
|
|
121
|
+
lineHeight: 20
|
|
122
|
+
},
|
|
123
|
+
splitLine: {
|
|
124
|
+
show: false,
|
|
125
|
+
interval: 0
|
|
126
|
+
},
|
|
127
|
+
boundaryGap: false,
|
|
128
|
+
data: xAxis
|
|
129
|
+
},
|
|
130
|
+
yAxis: {
|
|
131
|
+
type: 'value',
|
|
132
|
+
minInterval: 1,
|
|
133
|
+
axisLabel: {
|
|
134
|
+
formatter: function formatter(value) {
|
|
135
|
+
var formatted = numberFormatNull(value);
|
|
136
|
+
if (formatted.length < 4) {
|
|
137
|
+
// 假设最大长度为4
|
|
138
|
+
formatted = ' ' + formatted; // 在前面添加空格
|
|
139
|
+
}
|
|
140
|
+
return formatted;
|
|
141
|
+
},
|
|
142
|
+
margin: 14,
|
|
143
|
+
color: '#515E5F',
|
|
144
|
+
fontSize: 12,
|
|
145
|
+
lineHeight: 20
|
|
146
|
+
},
|
|
147
|
+
splitLine: {
|
|
148
|
+
lineStyle: {
|
|
149
|
+
type: 'dashed',
|
|
150
|
+
color: '#E5E5E5'
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
series: series
|
|
155
|
+
};
|
|
156
|
+
myChart.off('mouseover');
|
|
157
|
+
myChart.on('mouseover', function (params) {
|
|
158
|
+
// 操作线上选中点
|
|
159
|
+
var updateOption = {
|
|
160
|
+
series: [],
|
|
161
|
+
legend: {
|
|
162
|
+
data: []
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
option.series.forEach(function (item) {
|
|
166
|
+
if (params.seriesName === item.name) {
|
|
167
|
+
item.showSymbol = true;
|
|
168
|
+
item.data.forEach(function (val, index) {
|
|
169
|
+
if (index === params.dataIndex) {
|
|
170
|
+
val.symbolSize = 12;
|
|
171
|
+
} else {
|
|
172
|
+
val.symbolSize = 0;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
// 操作图例
|
|
178
|
+
option.legend.data.forEach(function (item) {
|
|
179
|
+
if (params.seriesName !== item.name) {
|
|
180
|
+
item.textStyle = {};
|
|
181
|
+
item.itemStyle = {};
|
|
182
|
+
item.textStyle.opacity = 0.2;
|
|
183
|
+
item.itemStyle.opacity = 0.2;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
updateOption.series = option.series;
|
|
187
|
+
updateOption.legend.data = option.legend.data;
|
|
188
|
+
myChart.setOption(updateOption);
|
|
189
|
+
});
|
|
190
|
+
myChart.off('mouseout');
|
|
191
|
+
myChart.on('mouseout', function (params) {
|
|
192
|
+
var updateOption = {
|
|
193
|
+
series: [],
|
|
194
|
+
legend: {
|
|
195
|
+
data: []
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
// 操作线上选中点
|
|
199
|
+
option.series.forEach(function (item) {
|
|
200
|
+
if (params.seriesName === item.name) {
|
|
201
|
+
item.showSymbol = false;
|
|
202
|
+
item.data.forEach(function (val) {
|
|
203
|
+
val.symbolSize = 8;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
// 操作图例
|
|
208
|
+
option.legend.data.forEach(function (item) {
|
|
209
|
+
item.textStyle = {};
|
|
210
|
+
item.itemStyle = {};
|
|
211
|
+
item.textStyle.opacity = 1;
|
|
212
|
+
item.itemStyle.opacity = 1;
|
|
213
|
+
});
|
|
214
|
+
updateOption.series = option.series;
|
|
215
|
+
updateOption.legend.data = option.legend.data;
|
|
216
|
+
myChart.setOption(updateOption);
|
|
217
|
+
var flag = false;
|
|
218
|
+
var pixelPoint = myChart.convertToPixel({
|
|
219
|
+
seriesIndex: params.seriesIndex
|
|
220
|
+
}, [params.dataIndex, params.value]);
|
|
221
|
+
if (params && params.event && params.event.offsetX) {
|
|
222
|
+
if (params.dataIndex === 0 && params.event.offsetX >= pixelPoint[0]) {
|
|
223
|
+
flag = true;
|
|
224
|
+
} else if (params.dataIndex === xAxis.length - 1 && params.event.offsetX <= pixelPoint[0]) {
|
|
225
|
+
flag = true;
|
|
226
|
+
} else if (params.dataIndex !== 0 && params.dataIndex !== xAxis.length - 1) {
|
|
227
|
+
flag = true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (flag) {
|
|
231
|
+
myChart.dispatchAction({
|
|
232
|
+
type: 'highlight',
|
|
233
|
+
dataIndex: params.dataIndex
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
var mouseoutFlag = true;
|
|
237
|
+
myChart.on('hideTip', function (event) {
|
|
238
|
+
if (mouseoutFlag) {
|
|
239
|
+
myChart.dispatchAction({
|
|
240
|
+
type: 'downplay',
|
|
241
|
+
dataIndex: params.dataIndex
|
|
242
|
+
});
|
|
243
|
+
mouseoutFlag = false;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
var currentIndex = 0;
|
|
248
|
+
var flagIndex = 0;
|
|
249
|
+
myChart.off('showTip');
|
|
250
|
+
myChart.on('showTip', function (event) {
|
|
251
|
+
if (flagIndex !== event.dataIndex) {
|
|
252
|
+
toggleAxisPointer(myChart, true);
|
|
253
|
+
myChart.dispatchAction({
|
|
254
|
+
type: 'highlight',
|
|
255
|
+
dataIndex: event.dataIndex
|
|
256
|
+
});
|
|
257
|
+
currentIndex = event.dataIndex;
|
|
258
|
+
flagIndex = event.dataIndex;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
myChart.setOption(option, true);
|
|
262
|
+
|
|
263
|
+
// 提高图例清晰度
|
|
264
|
+
myChart.off('rendered');
|
|
265
|
+
myChart.on('rendered', function () {
|
|
266
|
+
dealPath(id);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// 增强交互效果
|
|
270
|
+
var element = document.querySelector(".".concat(id));
|
|
271
|
+
if (element) {
|
|
272
|
+
element.addEventListener('mouseleave', function (event) {
|
|
273
|
+
if (event && element.offsetHeight && event.offsetY < element.offsetHeight - 2) {
|
|
274
|
+
toggleAxisPointer(myChart, false);
|
|
275
|
+
flagIndex = 0;
|
|
276
|
+
myChart.dispatchAction({
|
|
277
|
+
type: 'downplay',
|
|
278
|
+
dataIndex: currentIndex
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
285
|
+
ref: chartRef,
|
|
286
|
+
id: id,
|
|
287
|
+
style: {
|
|
288
|
+
width: width,
|
|
289
|
+
height: height
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
export default Line;
|
|
@@ -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
|
+
};
|