onesight-charts 0.4.2 → 0.4.4
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/common-bar/demo/base.js +34 -13
- package/es/components/common-bar/demo/yIcon.js +10 -1
- package/es/components/common-bar/index.js +12 -21
- package/es/components/custom-line/demo/base.js +5 -3
- package/es/components/custom-line/index.js +2 -2
- package/es/components/line/demo.js +10 -1
- package/es/components/line/index.js +32 -1
- package/es/components/line/tooltipConfig.js +1 -1
- package/es/components/pie/demo/demo.js +11 -1
- package/es/components/pie/demo/legendDemo.js +11 -1
- package/es/components/pie/demo/orderDemo.js +11 -1
- package/es/components/pie/demo/paginationDemo.js +11 -1
- package/es/components/pie/demo/tooltipDemo.js +11 -1
- package/es/components/pie/index.js +1 -1
- package/es/components/pie/legend/index.js +1 -1
- package/es/components/vertical-stacked-bar/demo/base.js +10 -1
- package/es/components/vertical-stacked-bar/demo/seriesData.js +10 -1
- package/es/components/vertical-stacked-bar/index.js +32 -1
- package/lib/components/common-bar/demo/base.js +29 -13
- package/lib/components/common-bar/demo/yIcon.js +5 -1
- package/lib/components/common-bar/index.js +10 -20
- package/lib/components/custom-line/demo/base.js +2 -1
- package/lib/components/custom-line/index.js +2 -2
- package/lib/components/line/demo.js +5 -1
- package/lib/components/line/index.js +27 -1
- package/lib/components/line/tooltipConfig.js +3 -1
- package/lib/components/pie/demo/demo.js +5 -1
- package/lib/components/pie/demo/legendDemo.js +13 -1
- package/lib/components/pie/demo/orderDemo.js +13 -1
- package/lib/components/pie/demo/paginationDemo.js +5 -1
- package/lib/components/pie/demo/tooltipDemo.js +13 -1
- package/lib/components/pie/index.js +1 -1
- package/lib/components/pie/legend/index.js +1 -1
- package/lib/components/vertical-stacked-bar/demo/base.js +12 -1
- package/lib/components/vertical-stacked-bar/demo/seriesData.js +12 -1
- package/lib/components/vertical-stacked-bar/index.js +27 -1
- package/package.json +1 -1
|
@@ -3,52 +3,72 @@ import CommonBar from "../index";
|
|
|
3
3
|
var data = [{
|
|
4
4
|
name: 'X',
|
|
5
5
|
value: 1004,
|
|
6
|
-
proportion: 0.26379400945874937
|
|
6
|
+
proportion: 0.26379400945874937,
|
|
7
|
+
color: '#4B5F6F'
|
|
7
8
|
}, {
|
|
8
9
|
name: 'Instagram',
|
|
9
10
|
value: 932,
|
|
10
|
-
proportion: 0.24487651077246453
|
|
11
|
+
proportion: 0.24487651077246453,
|
|
12
|
+
color: '#EC798E'
|
|
11
13
|
}, {
|
|
12
14
|
name: 'YouTube',
|
|
13
15
|
value: 658,
|
|
14
|
-
proportion: 0.17288491854965843
|
|
16
|
+
proportion: 0.17288491854965843,
|
|
17
|
+
color: '#FF4D4C'
|
|
15
18
|
}, {
|
|
16
19
|
name: '新闻',
|
|
17
20
|
value: 545,
|
|
18
|
-
proportion: 0.14319495533368365
|
|
21
|
+
proportion: 0.14319495533368365,
|
|
22
|
+
color: '#F9B522'
|
|
19
23
|
}, {
|
|
20
24
|
name: '论坛',
|
|
21
25
|
value: 418,
|
|
22
|
-
proportion: 0.10982658959537572
|
|
26
|
+
proportion: 0.10982658959537572,
|
|
27
|
+
color: '#07afc6'
|
|
23
28
|
}, {
|
|
24
29
|
name: 'VKontakte',
|
|
25
30
|
value: 127,
|
|
26
|
-
proportion: 0.03336836573830793
|
|
31
|
+
proportion: 0.03336836573830793,
|
|
32
|
+
color: '#529CD6'
|
|
27
33
|
}, {
|
|
28
34
|
name: 'Reddit',
|
|
29
35
|
value: 61,
|
|
30
|
-
proportion: 0.01602732527588019
|
|
36
|
+
proportion: 0.01602732527588019,
|
|
37
|
+
color: '#FF4500'
|
|
31
38
|
}, {
|
|
32
39
|
name: '博客',
|
|
33
40
|
value: 38,
|
|
34
|
-
proportion: 0.009984235417761429
|
|
41
|
+
proportion: 0.009984235417761429,
|
|
42
|
+
color: '#a55ec6'
|
|
35
43
|
}, {
|
|
36
44
|
name: 'TikTok',
|
|
37
45
|
value: 12,
|
|
38
|
-
proportion: 0.0031529164477141357
|
|
46
|
+
proportion: 0.0031529164477141357,
|
|
47
|
+
color: '#4C4C4C'
|
|
39
48
|
}, {
|
|
40
49
|
name: 'LinkedIn',
|
|
41
50
|
value: 10,
|
|
42
|
-
proportion: 0.002627430373095113
|
|
51
|
+
proportion: 0.002627430373095113,
|
|
52
|
+
color: '#4D7797'
|
|
43
53
|
}, {
|
|
44
54
|
name: 'Facebook',
|
|
45
55
|
value: 1,
|
|
46
|
-
proportion: 0.0002627430373095113
|
|
56
|
+
proportion: 0.0002627430373095113,
|
|
57
|
+
color: '#358FFF'
|
|
47
58
|
}, {
|
|
48
59
|
name: '产品评论',
|
|
49
60
|
value: 1,
|
|
50
|
-
proportion: 0.0002627430373095113
|
|
61
|
+
proportion: 0.0002627430373095113,
|
|
62
|
+
color: '#f97322'
|
|
51
63
|
}];
|
|
64
|
+
|
|
65
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
66
|
+
// dataPointType是指点击的图形上可点击区域
|
|
67
|
+
// tooltipType是指点击的提示框区域
|
|
68
|
+
var handleClick = function handleClick(type, params) {
|
|
69
|
+
console.log('type', type);
|
|
70
|
+
console.log('params', params);
|
|
71
|
+
};
|
|
52
72
|
function App() {
|
|
53
73
|
return /*#__PURE__*/React.createElement("div", {
|
|
54
74
|
style: {
|
|
@@ -56,7 +76,8 @@ function App() {
|
|
|
56
76
|
height: 282
|
|
57
77
|
}
|
|
58
78
|
}, /*#__PURE__*/React.createElement(CommonBar, {
|
|
59
|
-
data: data
|
|
79
|
+
data: data,
|
|
80
|
+
handleClick: handleClick
|
|
60
81
|
}));
|
|
61
82
|
}
|
|
62
83
|
export default App;
|
|
@@ -49,6 +49,14 @@ var data = [{
|
|
|
49
49
|
value: 1,
|
|
50
50
|
platformIcon: '/img/blogs.svg'
|
|
51
51
|
}];
|
|
52
|
+
|
|
53
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
54
|
+
// dataPointType是指点击的图形上可点击区域
|
|
55
|
+
// tooltipType是指点击的提示框区域
|
|
56
|
+
var handleClick = function handleClick(type, params) {
|
|
57
|
+
console.log('type', type);
|
|
58
|
+
console.log('params', params);
|
|
59
|
+
};
|
|
52
60
|
function App() {
|
|
53
61
|
return /*#__PURE__*/React.createElement("div", {
|
|
54
62
|
style: {
|
|
@@ -56,7 +64,8 @@ function App() {
|
|
|
56
64
|
height: 282
|
|
57
65
|
}
|
|
58
66
|
}, /*#__PURE__*/React.createElement(CommonBar, {
|
|
59
|
-
data: data
|
|
67
|
+
data: data,
|
|
68
|
+
handleClick: handleClick
|
|
60
69
|
}));
|
|
61
70
|
}
|
|
62
71
|
export default App;
|
|
@@ -25,7 +25,6 @@ function CommonBar(props) {
|
|
|
25
25
|
showProportion = _props$showProportion === void 0 ? false : _props$showProportion,
|
|
26
26
|
_props$barColor = props.barColor,
|
|
27
27
|
barColor = _props$barColor === void 0 ? 'rgba(29, 169, 160, 1)' : _props$barColor,
|
|
28
|
-
callBackClick = props.callBackClick,
|
|
29
28
|
_props$callBackValue = props.callBackValue,
|
|
30
29
|
callBackValue = _props$callBackValue === void 0 ? '' : _props$callBackValue,
|
|
31
30
|
_props$tipName = props.tipName,
|
|
@@ -37,7 +36,9 @@ function CommonBar(props) {
|
|
|
37
36
|
_props$height = props.height,
|
|
38
37
|
height = _props$height === void 0 ? '100%' : _props$height,
|
|
39
38
|
_props$callbackGetPag = props.callbackGetPage,
|
|
40
|
-
callbackGetPage = _props$callbackGetPag === void 0 ? function () {} : _props$callbackGetPag
|
|
39
|
+
callbackGetPage = _props$callbackGetPag === void 0 ? function () {} : _props$callbackGetPag,
|
|
40
|
+
_props$handleClick = props.handleClick,
|
|
41
|
+
handleClick = _props$handleClick === void 0 ? function () {} : _props$handleClick;
|
|
41
42
|
// 总数页码数
|
|
42
43
|
var _useState = useState(0),
|
|
43
44
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -79,13 +80,7 @@ function CommonBar(props) {
|
|
|
79
80
|
if (seriesNameElement) {
|
|
80
81
|
var seriesItem = seriesNameElement.getAttribute('data-series-item');
|
|
81
82
|
var seriesData = JSON.parse(seriesItem);
|
|
82
|
-
|
|
83
|
-
name: seriesData.data.name || '-'
|
|
84
|
-
};
|
|
85
|
-
if (callBackValue) {
|
|
86
|
-
defaultParams.callBackValue = seriesData.data[callBackValue] || '-';
|
|
87
|
-
}
|
|
88
|
-
callBackClick && callBackClick(defaultParams);
|
|
83
|
+
handleClick && handleClick('tooltipType', seriesData);
|
|
89
84
|
}
|
|
90
85
|
};
|
|
91
86
|
function toggleAxisPointer(myChart, show) {
|
|
@@ -200,12 +195,14 @@ function CommonBar(props) {
|
|
|
200
195
|
return item.format || item.name || '-';
|
|
201
196
|
});
|
|
202
197
|
var seriesData = currentData.map(function (item) {
|
|
198
|
+
// 优先使用每项自己的颜色,如果没有则使用默认的 barColor
|
|
199
|
+
var itemColor = item.color || barColor;
|
|
203
200
|
if (showProportion) {
|
|
204
201
|
return {
|
|
205
202
|
name: item.name || '-',
|
|
206
203
|
value: (item === null || item === void 0 ? void 0 : item.proportion) || 0,
|
|
207
204
|
itemStyle: item !== null && item !== void 0 && item.proportion ? {
|
|
208
|
-
color:
|
|
205
|
+
color: itemColor
|
|
209
206
|
} : {
|
|
210
207
|
color: 'rgba(29, 169, 160, 0)'
|
|
211
208
|
}
|
|
@@ -215,7 +212,7 @@ function CommonBar(props) {
|
|
|
215
212
|
name: item.name || '-',
|
|
216
213
|
value: item.value || 0,
|
|
217
214
|
itemStyle: item.value ? {
|
|
218
|
-
color:
|
|
215
|
+
color: itemColor
|
|
219
216
|
} : {
|
|
220
217
|
color: 'rgba(29, 169, 160, 0)'
|
|
221
218
|
}
|
|
@@ -440,22 +437,16 @@ function CommonBar(props) {
|
|
|
440
437
|
if (dataCoord[1] === -0) {
|
|
441
438
|
if (axisData[0]) {
|
|
442
439
|
var defaultParams = {
|
|
443
|
-
name: seriesData[0]
|
|
440
|
+
name: seriesData[0]
|
|
444
441
|
};
|
|
445
|
-
|
|
446
|
-
defaultParams.callBackValue = seriesData[0][callBackValue] || '-';
|
|
447
|
-
}
|
|
448
|
-
callBackClick && callBackClick(defaultParams);
|
|
442
|
+
handleClick && handleClick('dataPointType', defaultParams);
|
|
449
443
|
}
|
|
450
444
|
} else if (dataCoord[1] >= 0) {
|
|
451
445
|
if (axisData[dataCoord[1]]) {
|
|
452
446
|
var _defaultParams = {
|
|
453
|
-
name: seriesData[dataCoord[1]]
|
|
447
|
+
name: seriesData[dataCoord[1]]
|
|
454
448
|
};
|
|
455
|
-
|
|
456
|
-
_defaultParams.callBackValue = seriesData[dataCoord[1]][callBackValue] || '-';
|
|
457
|
-
}
|
|
458
|
-
callBackClick && callBackClick(_defaultParams);
|
|
449
|
+
handleClick && handleClick('dataPointType', _defaultParams);
|
|
459
450
|
}
|
|
460
451
|
}
|
|
461
452
|
} else {
|
|
@@ -13,9 +13,11 @@ function App() {
|
|
|
13
13
|
Reddit: [13094, 10075, 11410, 12374, 9413, 7904, 5295]
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
|
|
16
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
17
|
+
// dataPointType是指点击的图形上可点击区域
|
|
18
|
+
// tooltipType是指点击的提示框区域
|
|
19
|
+
var handleClick = function handleClick(type, params) {
|
|
20
|
+
console.log('type', type);
|
|
19
21
|
console.log('params', params);
|
|
20
22
|
};
|
|
21
23
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -61,7 +61,7 @@ function CustomLine(props) {
|
|
|
61
61
|
if (seriesNameElement) {
|
|
62
62
|
var seriesItem = seriesNameElement.getAttribute('data-series-item');
|
|
63
63
|
var _seriesData = JSON.parse(seriesItem);
|
|
64
|
-
handleClick && handleClick(_seriesData);
|
|
64
|
+
handleClick && handleClick('tooltipType', _seriesData);
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
function toggleAxisPointer(myChart, show) {
|
|
@@ -217,7 +217,7 @@ function CustomLine(props) {
|
|
|
217
217
|
// const D1 = params.name;
|
|
218
218
|
// const D2 = params.seriesName;
|
|
219
219
|
// 点击回调函数
|
|
220
|
-
handleClick && handleClick(params);
|
|
220
|
+
handleClick && handleClick('dataPointType', params);
|
|
221
221
|
});
|
|
222
222
|
myChart.off('mouseover');
|
|
223
223
|
myChart.on('mouseover', function (params) {
|
|
@@ -5,6 +5,14 @@ var seriesData = {
|
|
|
5
5
|
Facebook: [1002, 831, 960, 750, 1451, 1717, 903],
|
|
6
6
|
X: [22094, 20075, 17410, 12374, 13413, 13904, 6895]
|
|
7
7
|
};
|
|
8
|
+
|
|
9
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
10
|
+
// dataPointType是指点击的图形上可点击区域
|
|
11
|
+
// tooltipType是指点击的提示框区域
|
|
12
|
+
var handleClick = function handleClick(type, params) {
|
|
13
|
+
console.log('type', type);
|
|
14
|
+
console.log('params', params);
|
|
15
|
+
};
|
|
8
16
|
export default (function () {
|
|
9
17
|
return /*#__PURE__*/React.createElement("div", {
|
|
10
18
|
style: {
|
|
@@ -13,6 +21,7 @@ export default (function () {
|
|
|
13
21
|
}
|
|
14
22
|
}, /*#__PURE__*/React.createElement(Line, {
|
|
15
23
|
xAxis: xAxis,
|
|
16
|
-
seriesData: seriesData
|
|
24
|
+
seriesData: seriesData,
|
|
25
|
+
handleClick: handleClick
|
|
17
26
|
}));
|
|
18
27
|
});
|
|
@@ -22,11 +22,33 @@ function Line(props) {
|
|
|
22
22
|
_props$tooltipTotalNa = props.tooltipTotalName,
|
|
23
23
|
tooltipTotalName = _props$tooltipTotalNa === void 0 ? '总计' : _props$tooltipTotalNa,
|
|
24
24
|
_props$tooltipPositio = props.tooltipPosition,
|
|
25
|
-
tooltipPosition = _props$tooltipPositio === void 0 ? true : _props$tooltipPositio
|
|
25
|
+
tooltipPosition = _props$tooltipPositio === void 0 ? true : _props$tooltipPositio,
|
|
26
|
+
_props$handleClick = props.handleClick,
|
|
27
|
+
handleClick = _props$handleClick === void 0 ? function () {} : _props$handleClick;
|
|
26
28
|
var chartRef = useRef(null);
|
|
27
29
|
useEffect(function () {
|
|
28
30
|
createChart();
|
|
31
|
+
bindClickEvents();
|
|
32
|
+
return function () {
|
|
33
|
+
unbindClickEvents();
|
|
34
|
+
};
|
|
29
35
|
}, [seriesData]);
|
|
36
|
+
var bindClickEvents = function bindClickEvents() {
|
|
37
|
+
var chartElement = chartRef.current;
|
|
38
|
+
chartElement && chartElement.addEventListener('click', onChartClick);
|
|
39
|
+
};
|
|
40
|
+
var unbindClickEvents = function unbindClickEvents() {
|
|
41
|
+
var chartElement = chartRef.current;
|
|
42
|
+
chartElement && chartElement.removeEventListener('click', onChartClick);
|
|
43
|
+
};
|
|
44
|
+
var onChartClick = function onChartClick(event) {
|
|
45
|
+
var seriesNameElement = event.target.closest('.item');
|
|
46
|
+
if (seriesNameElement) {
|
|
47
|
+
var seriesItem = seriesNameElement.getAttribute('data-series-item');
|
|
48
|
+
var _seriesData = JSON.parse(seriesItem);
|
|
49
|
+
handleClick && handleClick('tooltipType', _seriesData);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
30
52
|
var seriesTotal = legendValue ? calculateSeriesTotal(seriesData) : {};
|
|
31
53
|
var createChart = function createChart() {
|
|
32
54
|
var myChart = echarts.init(chartRef.current, null, {
|
|
@@ -153,6 +175,15 @@ function Line(props) {
|
|
|
153
175
|
},
|
|
154
176
|
series: series
|
|
155
177
|
};
|
|
178
|
+
|
|
179
|
+
// 取消监听点击事件,也可以防止重复绑定
|
|
180
|
+
myChart.off('click');
|
|
181
|
+
myChart.on('click', function (params) {
|
|
182
|
+
// const D1 = params.name;
|
|
183
|
+
// const D2 = params.seriesName;
|
|
184
|
+
// 点击回调函数
|
|
185
|
+
handleClick && handleClick('dataPointType', params);
|
|
186
|
+
});
|
|
156
187
|
myChart.off('mouseover');
|
|
157
188
|
myChart.on('mouseover', function (params) {
|
|
158
189
|
// 操作线上选中点
|
|
@@ -86,7 +86,7 @@ export var createCustomTooltip = function createCustomTooltip(_ref) {
|
|
|
86
86
|
marginRight = 3;
|
|
87
87
|
}
|
|
88
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
|
|
89
|
+
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, "\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
90
|
}).join(''), "\n </div>\n ").concat(tooltipPosition ? '<div class="triangle-down"></div>' : '', "\n </div>\n ");
|
|
91
91
|
}
|
|
92
92
|
};
|
|
@@ -15,6 +15,15 @@ var seriesData = [{
|
|
|
15
15
|
percentage: 0.5365,
|
|
16
16
|
color: '#bbbbbb'
|
|
17
17
|
}];
|
|
18
|
+
|
|
19
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
20
|
+
// dataPointType是指点击的图形上可点击区域
|
|
21
|
+
// tooltipType是指点击的提示框区域
|
|
22
|
+
// legendType是指点击的图例区域(这个图特殊,点击图例可以下钻)
|
|
23
|
+
var handleClick = function handleClick(type, params) {
|
|
24
|
+
console.log('type', type);
|
|
25
|
+
console.log('params', params);
|
|
26
|
+
};
|
|
18
27
|
export default (function () {
|
|
19
28
|
return /*#__PURE__*/React.createElement("div", {
|
|
20
29
|
style: {
|
|
@@ -22,6 +31,7 @@ export default (function () {
|
|
|
22
31
|
height: '286px'
|
|
23
32
|
}
|
|
24
33
|
}, /*#__PURE__*/React.createElement(Pie, {
|
|
25
|
-
seriesData: seriesData
|
|
34
|
+
seriesData: seriesData,
|
|
35
|
+
handleClick: handleClick
|
|
26
36
|
}));
|
|
27
37
|
});
|
|
@@ -15,6 +15,15 @@ var seriesData = [{
|
|
|
15
15
|
percentage: 0.5365,
|
|
16
16
|
color: '#bbbbbb'
|
|
17
17
|
}];
|
|
18
|
+
|
|
19
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
20
|
+
// dataPointType是指点击的图形上可点击区域
|
|
21
|
+
// tooltipType是指点击的提示框区域
|
|
22
|
+
// legendType是指点击的图例区域(这个图特殊,点击图例可以下钻)
|
|
23
|
+
var handleClick = function handleClick(type, params) {
|
|
24
|
+
console.log('type', type);
|
|
25
|
+
console.log('params', params);
|
|
26
|
+
};
|
|
18
27
|
export default (function () {
|
|
19
28
|
return /*#__PURE__*/React.createElement("div", {
|
|
20
29
|
style: {
|
|
@@ -24,6 +33,7 @@ export default (function () {
|
|
|
24
33
|
}, /*#__PURE__*/React.createElement(Pie, {
|
|
25
34
|
seriesData: seriesData,
|
|
26
35
|
legendNumShow: false,
|
|
27
|
-
legendPerShow: false
|
|
36
|
+
legendPerShow: false,
|
|
37
|
+
handleClick: handleClick
|
|
28
38
|
}));
|
|
29
39
|
});
|
|
@@ -16,6 +16,15 @@ var seriesData = [{
|
|
|
16
16
|
color: '#bbbbbb'
|
|
17
17
|
}];
|
|
18
18
|
var order = ['积极', '消极', '中性'];
|
|
19
|
+
|
|
20
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
21
|
+
// dataPointType是指点击的图形上可点击区域
|
|
22
|
+
// tooltipType是指点击的提示框区域
|
|
23
|
+
// legendType是指点击的图例区域(这个图特殊,点击图例可以下钻)
|
|
24
|
+
var handleClick = function handleClick(type, params) {
|
|
25
|
+
console.log('type', type);
|
|
26
|
+
console.log('params', params);
|
|
27
|
+
};
|
|
19
28
|
export default (function () {
|
|
20
29
|
return /*#__PURE__*/React.createElement("div", {
|
|
21
30
|
style: {
|
|
@@ -25,6 +34,7 @@ export default (function () {
|
|
|
25
34
|
}, /*#__PURE__*/React.createElement(Pie, {
|
|
26
35
|
seriesData: seriesData,
|
|
27
36
|
order: order,
|
|
28
|
-
id: "orderId"
|
|
37
|
+
id: "orderId",
|
|
38
|
+
handleClick: handleClick
|
|
29
39
|
}));
|
|
30
40
|
});
|
|
@@ -65,6 +65,15 @@ var seriesData = [{
|
|
|
65
65
|
percentage: 0.1341,
|
|
66
66
|
color: '#C1232B'
|
|
67
67
|
}];
|
|
68
|
+
|
|
69
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
70
|
+
// dataPointType是指点击的图形上可点击区域
|
|
71
|
+
// tooltipType是指点击的提示框区域
|
|
72
|
+
// legendType是指点击的图例区域(这个图特殊,点击图例可以下钻)
|
|
73
|
+
var handleClick = function handleClick(type, params) {
|
|
74
|
+
console.log('type', type);
|
|
75
|
+
console.log('params', params);
|
|
76
|
+
};
|
|
68
77
|
export default (function () {
|
|
69
78
|
return /*#__PURE__*/React.createElement("div", {
|
|
70
79
|
style: {
|
|
@@ -73,6 +82,7 @@ export default (function () {
|
|
|
73
82
|
}
|
|
74
83
|
}, /*#__PURE__*/React.createElement(Pie, {
|
|
75
84
|
seriesData: seriesData,
|
|
76
|
-
legendNumber: 5
|
|
85
|
+
legendNumber: 5,
|
|
86
|
+
handleClick: handleClick
|
|
77
87
|
}));
|
|
78
88
|
});
|
|
@@ -15,6 +15,15 @@ var seriesData = [{
|
|
|
15
15
|
percentage: 0.5365,
|
|
16
16
|
color: '#bbbbbb'
|
|
17
17
|
}];
|
|
18
|
+
|
|
19
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
20
|
+
// dataPointType是指点击的图形上可点击区域
|
|
21
|
+
// tooltipType是指点击的提示框区域
|
|
22
|
+
// legendType是指点击的图例区域(这个图特殊,点击图例可以下钻)
|
|
23
|
+
var handleClick = function handleClick(type, params) {
|
|
24
|
+
console.log('type', type);
|
|
25
|
+
console.log('params', params);
|
|
26
|
+
};
|
|
18
27
|
export default (function () {
|
|
19
28
|
return /*#__PURE__*/React.createElement("div", {
|
|
20
29
|
style: {
|
|
@@ -24,6 +33,7 @@ export default (function () {
|
|
|
24
33
|
}, /*#__PURE__*/React.createElement(Pie, {
|
|
25
34
|
seriesData: seriesData,
|
|
26
35
|
tooltipName: "\u6570\u91CF",
|
|
27
|
-
tooltipPerShow: false
|
|
36
|
+
tooltipPerShow: false,
|
|
37
|
+
handleClick: handleClick
|
|
28
38
|
}));
|
|
29
39
|
});
|
|
@@ -162,7 +162,7 @@ function Pie(props) {
|
|
|
162
162
|
setLegendData(legendShowData.slice(0, legendNumber));
|
|
163
163
|
myChart.off('click');
|
|
164
164
|
myChart.on('click', 'series', function (params) {
|
|
165
|
-
handleClick && handleClick(params.data);
|
|
165
|
+
handleClick && handleClick('dataPointType', params.data);
|
|
166
166
|
});
|
|
167
167
|
};
|
|
168
168
|
var paginationCb = function paginationCb(currData, page) {
|
|
@@ -80,7 +80,7 @@ function Legend(props) {
|
|
|
80
80
|
width: 'auto'
|
|
81
81
|
} : undefined,
|
|
82
82
|
onClick: function onClick() {
|
|
83
|
-
return handleClick ? handleClick(item) : handleLegendClick(item);
|
|
83
|
+
return handleClick ? handleClick('legendType', item) : handleLegendClick(item);
|
|
84
84
|
},
|
|
85
85
|
onMouseEnter: function onMouseEnter() {
|
|
86
86
|
return handleHover(item);
|
|
@@ -102,6 +102,14 @@ function App() {
|
|
|
102
102
|
VKontakte: 320,
|
|
103
103
|
Reddit: 220
|
|
104
104
|
}];
|
|
105
|
+
|
|
106
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
107
|
+
// dataPointType是指点击的图形上可点击区域
|
|
108
|
+
// tooltipType是指点击的提示框区域
|
|
109
|
+
var handleClick = function handleClick(type, params) {
|
|
110
|
+
console.log('type', type);
|
|
111
|
+
console.log('params', params);
|
|
112
|
+
};
|
|
105
113
|
return /*#__PURE__*/React.createElement("div", {
|
|
106
114
|
style: {
|
|
107
115
|
width: '500px',
|
|
@@ -109,7 +117,8 @@ function App() {
|
|
|
109
117
|
}
|
|
110
118
|
}, /*#__PURE__*/React.createElement(VerticalStackedBar, {
|
|
111
119
|
data: data,
|
|
112
|
-
exclude: ['name']
|
|
120
|
+
exclude: ['name'],
|
|
121
|
+
handleClick: handleClick
|
|
113
122
|
}));
|
|
114
123
|
}
|
|
115
124
|
export default App;
|
|
@@ -75,6 +75,14 @@ function App() {
|
|
|
75
75
|
data: [220, 220, 220, 220, 220, 220, 220, 220, 220, 220]
|
|
76
76
|
}];
|
|
77
77
|
var categories = ['图片', '文本', 'Reels', '视频', '链接', '轮播', 'Shorts', '其他', '组合', '动图'];
|
|
78
|
+
|
|
79
|
+
// type: 'dataPointType' | 'tooltipType'
|
|
80
|
+
// dataPointType是指点击的图形上可点击区域
|
|
81
|
+
// tooltipType是指点击的提示框区域
|
|
82
|
+
var handleClick = function handleClick(type, params) {
|
|
83
|
+
console.log('type', type);
|
|
84
|
+
console.log('params', params);
|
|
85
|
+
};
|
|
78
86
|
return /*#__PURE__*/React.createElement("div", {
|
|
79
87
|
style: {
|
|
80
88
|
width: '500px',
|
|
@@ -82,7 +90,8 @@ function App() {
|
|
|
82
90
|
}
|
|
83
91
|
}, /*#__PURE__*/React.createElement(VerticalStackedBar, {
|
|
84
92
|
seriesData: seriesData,
|
|
85
|
-
categories: categories
|
|
93
|
+
categories: categories,
|
|
94
|
+
handleClick: handleClick
|
|
86
95
|
}));
|
|
87
96
|
}
|
|
88
97
|
export default App;
|
|
@@ -59,10 +59,32 @@ function VerticalStackedBar(props) {
|
|
|
59
59
|
_props$height = props.height,
|
|
60
60
|
height = _props$height === void 0 ? '100%' : _props$height,
|
|
61
61
|
_props$legendNum = props.legendNum,
|
|
62
|
-
legendNum = _props$legendNum === void 0 ? 4 : _props$legendNum
|
|
62
|
+
legendNum = _props$legendNum === void 0 ? 4 : _props$legendNum,
|
|
63
|
+
_props$handleClick = props.handleClick,
|
|
64
|
+
handleClick = _props$handleClick === void 0 ? function () {} : _props$handleClick;
|
|
63
65
|
useEffect(function () {
|
|
64
66
|
init();
|
|
67
|
+
bindClickEvents();
|
|
68
|
+
return function () {
|
|
69
|
+
unbindClickEvents();
|
|
70
|
+
};
|
|
65
71
|
}, []);
|
|
72
|
+
var bindClickEvents = function bindClickEvents() {
|
|
73
|
+
var chartElement = chartRef.current;
|
|
74
|
+
chartElement && chartElement.addEventListener('click', onChartClick);
|
|
75
|
+
};
|
|
76
|
+
var unbindClickEvents = function unbindClickEvents() {
|
|
77
|
+
var chartElement = chartRef.current;
|
|
78
|
+
chartElement && chartElement.removeEventListener('click', onChartClick);
|
|
79
|
+
};
|
|
80
|
+
var onChartClick = function onChartClick(event) {
|
|
81
|
+
var seriesNameElement = event.target.closest('.item');
|
|
82
|
+
if (seriesNameElement) {
|
|
83
|
+
var seriesItem = seriesNameElement.getAttribute('data-series-item');
|
|
84
|
+
var _seriesData = JSON.parse(seriesItem);
|
|
85
|
+
handleClick && handleClick('tooltipType', _seriesData);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
66
88
|
function toggleAxisPointer(myChart, show) {
|
|
67
89
|
myChart.setOption({
|
|
68
90
|
tooltip: {
|
|
@@ -299,6 +321,15 @@ function VerticalStackedBar(props) {
|
|
|
299
321
|
},
|
|
300
322
|
series: series
|
|
301
323
|
};
|
|
324
|
+
|
|
325
|
+
// 取消监听点击事件,也可以防止重复绑定
|
|
326
|
+
myChart.off('click');
|
|
327
|
+
myChart.on('click', function (params) {
|
|
328
|
+
// const D1 = params.name;
|
|
329
|
+
// const D2 = params.seriesName;
|
|
330
|
+
// 点击回调函数
|
|
331
|
+
handleClick && handleClick('dataPointType', params);
|
|
332
|
+
});
|
|
302
333
|
var currentIndex = 0;
|
|
303
334
|
myChart.off('showTip');
|
|
304
335
|
myChart.on('showTip', function (event) {
|
|
@@ -38,65 +38,81 @@ var data = [
|
|
|
38
38
|
{
|
|
39
39
|
name: "X",
|
|
40
40
|
value: 1004,
|
|
41
|
-
proportion: 0.26379400945874937
|
|
41
|
+
proportion: 0.26379400945874937,
|
|
42
|
+
color: "#4B5F6F"
|
|
42
43
|
},
|
|
43
44
|
{
|
|
44
45
|
name: "Instagram",
|
|
45
46
|
value: 932,
|
|
46
|
-
proportion: 0.24487651077246453
|
|
47
|
+
proportion: 0.24487651077246453,
|
|
48
|
+
color: "#EC798E"
|
|
47
49
|
},
|
|
48
50
|
{
|
|
49
51
|
name: "YouTube",
|
|
50
52
|
value: 658,
|
|
51
|
-
proportion: 0.17288491854965843
|
|
53
|
+
proportion: 0.17288491854965843,
|
|
54
|
+
color: "#FF4D4C"
|
|
52
55
|
},
|
|
53
56
|
{
|
|
54
57
|
name: "新闻",
|
|
55
58
|
value: 545,
|
|
56
|
-
proportion: 0.14319495533368365
|
|
59
|
+
proportion: 0.14319495533368365,
|
|
60
|
+
color: "#F9B522"
|
|
57
61
|
},
|
|
58
62
|
{
|
|
59
63
|
name: "论坛",
|
|
60
64
|
value: 418,
|
|
61
|
-
proportion: 0.10982658959537572
|
|
65
|
+
proportion: 0.10982658959537572,
|
|
66
|
+
color: "#07afc6"
|
|
62
67
|
},
|
|
63
68
|
{
|
|
64
69
|
name: "VKontakte",
|
|
65
70
|
value: 127,
|
|
66
|
-
proportion: 0.03336836573830793
|
|
71
|
+
proportion: 0.03336836573830793,
|
|
72
|
+
color: "#529CD6"
|
|
67
73
|
},
|
|
68
74
|
{
|
|
69
75
|
name: "Reddit",
|
|
70
76
|
value: 61,
|
|
71
|
-
proportion: 0.01602732527588019
|
|
77
|
+
proportion: 0.01602732527588019,
|
|
78
|
+
color: "#FF4500"
|
|
72
79
|
},
|
|
73
80
|
{
|
|
74
81
|
name: "博客",
|
|
75
82
|
value: 38,
|
|
76
|
-
proportion: 0.009984235417761429
|
|
83
|
+
proportion: 0.009984235417761429,
|
|
84
|
+
color: "#a55ec6"
|
|
77
85
|
},
|
|
78
86
|
{
|
|
79
87
|
name: "TikTok",
|
|
80
88
|
value: 12,
|
|
81
|
-
proportion: 0.0031529164477141357
|
|
89
|
+
proportion: 0.0031529164477141357,
|
|
90
|
+
color: "#4C4C4C"
|
|
82
91
|
},
|
|
83
92
|
{
|
|
84
93
|
name: "LinkedIn",
|
|
85
94
|
value: 10,
|
|
86
|
-
proportion: 0.002627430373095113
|
|
95
|
+
proportion: 0.002627430373095113,
|
|
96
|
+
color: "#4D7797"
|
|
87
97
|
},
|
|
88
98
|
{
|
|
89
99
|
name: "Facebook",
|
|
90
100
|
value: 1,
|
|
91
|
-
proportion: 2627430373095113e-19
|
|
101
|
+
proportion: 2627430373095113e-19,
|
|
102
|
+
color: "#358FFF"
|
|
92
103
|
},
|
|
93
104
|
{
|
|
94
105
|
name: "产品评论",
|
|
95
106
|
value: 1,
|
|
96
|
-
proportion: 2627430373095113e-19
|
|
107
|
+
proportion: 2627430373095113e-19,
|
|
108
|
+
color: "#f97322"
|
|
97
109
|
}
|
|
98
110
|
];
|
|
111
|
+
var handleClick = (type, params) => {
|
|
112
|
+
console.log("type", type);
|
|
113
|
+
console.log("params", params);
|
|
114
|
+
};
|
|
99
115
|
function App() {
|
|
100
|
-
return /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 500, height: 282 } }, /* @__PURE__ */ import_react.default.createElement(import__.default, { data }));
|
|
116
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 500, height: 282 } }, /* @__PURE__ */ import_react.default.createElement(import__.default, { data, handleClick }));
|
|
101
117
|
}
|
|
102
118
|
var base_default = App;
|