@easyv/charts 1.6.19 → 1.6.20
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/.babelrc +8 -8
- package/CHANGELOG.md +18 -18
- package/commitlint.config.js +1 -1
- package/lib/components/Background.js +2 -2
- package/lib/components/Band.js +2 -2
- package/lib/components/Brush.js +2 -2
- package/lib/components/CartesianChart.js +6 -3
- package/lib/components/Chart.js +3 -2
- package/lib/components/ChartContainer.js +2 -2
- package/lib/components/ConicalGradient.js +21 -21
- package/lib/components/ExtentData.js +2 -2
- package/lib/components/Indicator.js +6 -5
- package/lib/components/Label.js +2 -2
- package/lib/components/Legend.js +2 -2
- package/lib/components/Lighter.js +2 -2
- package/lib/components/Line.js +2 -2
- package/lib/components/LinearGradient.js +2 -2
- package/lib/components/StereoBar.js +2 -2
- package/lib/components/Tooltip.js +4 -3
- package/lib/css/index.module.css +42 -42
- package/lib/css/piechart.module.css +26 -26
- package/lib/hooks/useAnimateData.js +6 -6
- package/lib/hooks/useFilterData.js +5 -5
- package/lib/hooks/useStackData.js +5 -5
- package/lib/hooks/useTooltip.js +11 -11
- package/package.json +55 -55
- package/src/components/Background.tsx +61 -61
- package/src/components/Band.tsx +302 -302
- package/src/components/Brush.js +159 -159
- package/src/components/CartesianChart.js +3 -0
- package/src/components/Chart.js +153 -154
- package/src/components/ChartContainer.tsx +71 -71
- package/src/components/ConicalGradient.js +258 -258
- package/src/components/Control.jsx +241 -241
- package/src/components/ExtentData.js +18 -18
- package/src/components/Indicator.js +59 -58
- package/src/components/Label.js +262 -262
- package/src/components/Legend.js +189 -189
- package/src/components/Lighter.jsx +173 -173
- package/src/components/Line.js +153 -153
- package/src/components/LinearGradient.js +29 -29
- package/src/components/PieTooltip.jsx +160 -160
- package/src/components/StereoBar.tsx +307 -307
- package/src/components/Tooltip.js +3 -2
- package/src/components/index.js +59 -59
- package/src/context/index.js +2 -2
- package/src/css/index.module.css +42 -42
- package/src/css/piechart.module.css +26 -26
- package/src/element/ConicGradient.jsx +55 -55
- package/src/element/Line.tsx +33 -33
- package/src/element/index.ts +3 -3
- package/src/formatter/index.js +1 -1
- package/src/formatter/legend.js +114 -114
- package/src/hooks/index.js +20 -20
- package/src/hooks/useAnimateData.ts +68 -68
- package/src/hooks/useFilterData.js +78 -78
- package/src/hooks/useStackData.js +102 -102
- package/src/hooks/useTooltip.ts +104 -104
- package/src/index.js +6 -6
- package/src/types/index.d.ts +68 -68
- package/src/utils/index.js +800 -800
- package/tsconfig.json +23 -23
package/src/components/Brush.js
CHANGED
|
@@ -1,159 +1,159 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 实现中
|
|
3
|
-
*/
|
|
4
|
-
import { memo, useState, useCallback, useEffect, useRef } from 'react';
|
|
5
|
-
|
|
6
|
-
const left = {
|
|
7
|
-
position: 'relative',
|
|
8
|
-
width: 5,
|
|
9
|
-
height: '100%',
|
|
10
|
-
cursor: 'col-resize',
|
|
11
|
-
backgroundClip: 'content-box',
|
|
12
|
-
};
|
|
13
|
-
const center = {
|
|
14
|
-
flex: '1 1 0%',
|
|
15
|
-
height: '100%',
|
|
16
|
-
cursor: 'move',
|
|
17
|
-
};
|
|
18
|
-
const right = {
|
|
19
|
-
position: 'relative',
|
|
20
|
-
width: 5,
|
|
21
|
-
height: '100%',
|
|
22
|
-
cursor: 'col-resize',
|
|
23
|
-
backgroundClip: 'content-box',
|
|
24
|
-
};
|
|
25
|
-
const initialPosition = {
|
|
26
|
-
start: 0,
|
|
27
|
-
end: 0,
|
|
28
|
-
status: '',
|
|
29
|
-
};
|
|
30
|
-
const getValue = (x, min, max) => Math.max(min, Math.min(x, max));
|
|
31
|
-
export default ({
|
|
32
|
-
width,
|
|
33
|
-
config: {
|
|
34
|
-
height,
|
|
35
|
-
background,
|
|
36
|
-
margin: { marginLeft, marginRight },
|
|
37
|
-
detail: { width: blockWidth, color },
|
|
38
|
-
},
|
|
39
|
-
}) => {
|
|
40
|
-
const [state, setState] = useState({ translateX: 0, width: blockWidth });
|
|
41
|
-
const availableWidth = width - marginLeft - marginRight;
|
|
42
|
-
const cache = useRef(state);
|
|
43
|
-
|
|
44
|
-
const move = useCallback(
|
|
45
|
-
({ delta, status, name }) => {
|
|
46
|
-
let { width, translateX } = cache.current;
|
|
47
|
-
const minWidth = 40;
|
|
48
|
-
const minX = 0;
|
|
49
|
-
switch (name) {
|
|
50
|
-
case 'center':
|
|
51
|
-
translateX = getValue(
|
|
52
|
-
translateX + delta,
|
|
53
|
-
minX,
|
|
54
|
-
availableWidth - width
|
|
55
|
-
);
|
|
56
|
-
break;
|
|
57
|
-
case 'left':
|
|
58
|
-
let tempWidth = width;
|
|
59
|
-
width = getValue(width + delta * -1, minWidth, translateX + width);
|
|
60
|
-
translateX = getValue(
|
|
61
|
-
translateX + delta,
|
|
62
|
-
minX,
|
|
63
|
-
translateX + tempWidth - width
|
|
64
|
-
);
|
|
65
|
-
break;
|
|
66
|
-
case 'right':
|
|
67
|
-
width = getValue(
|
|
68
|
-
width + delta,
|
|
69
|
-
minWidth,
|
|
70
|
-
availableWidth - translateX
|
|
71
|
-
);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (status === 'up') {
|
|
76
|
-
cache.current = { width, translateX };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
setState({ width, translateX });
|
|
80
|
-
},
|
|
81
|
-
[availableWidth]
|
|
82
|
-
);
|
|
83
|
-
useEffect(() => {}, [state]);
|
|
84
|
-
return (
|
|
85
|
-
<div
|
|
86
|
-
style={{
|
|
87
|
-
marginLeft,
|
|
88
|
-
marginRight,
|
|
89
|
-
height,
|
|
90
|
-
background,
|
|
91
|
-
position: 'absolute',
|
|
92
|
-
bottom: 0,
|
|
93
|
-
width: availableWidth,
|
|
94
|
-
}}
|
|
95
|
-
>
|
|
96
|
-
<div
|
|
97
|
-
style={{
|
|
98
|
-
display: 'flex',
|
|
99
|
-
justifyContent: 'space-between',
|
|
100
|
-
position: 'absolute',
|
|
101
|
-
top: 0,
|
|
102
|
-
left: 0,
|
|
103
|
-
transform: 'translate3d(' + state.translateX + 'px, 0, 0)',
|
|
104
|
-
height: '100%',
|
|
105
|
-
width: state.width + 'px',
|
|
106
|
-
backgroundColor: color,
|
|
107
|
-
}}
|
|
108
|
-
>
|
|
109
|
-
<Move style={left} move={move} name='left' />
|
|
110
|
-
<Move style={center} move={move} name='center' />
|
|
111
|
-
<Move style={right} move={move} name='right' />
|
|
112
|
-
</div>
|
|
113
|
-
</div>
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
const Move = memo(({ style, move, name }) => {
|
|
117
|
-
const [position, setPosition] = useState(initialPosition);
|
|
118
|
-
|
|
119
|
-
const documentOnMouseMove = useCallback((e) => {
|
|
120
|
-
// console.log('documentOnMouseMove');
|
|
121
|
-
setPosition((position) => {
|
|
122
|
-
return {
|
|
123
|
-
...position,
|
|
124
|
-
end: e.clientX,
|
|
125
|
-
status: 'move',
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
}, []);
|
|
129
|
-
|
|
130
|
-
const documentOnMouseUp = useCallback((e) => {
|
|
131
|
-
// console.log('documentOnMouseUp');
|
|
132
|
-
setPosition((position) => {
|
|
133
|
-
return {
|
|
134
|
-
...position,
|
|
135
|
-
end: e.clientX,
|
|
136
|
-
status: 'up',
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
document.removeEventListener('mousemove', documentOnMouseMove);
|
|
140
|
-
document.removeEventListener('mouseup', documentOnMouseUp);
|
|
141
|
-
}, []);
|
|
142
|
-
|
|
143
|
-
const onMouseDown = useCallback((e) => {
|
|
144
|
-
// console.log('onMouseDown');
|
|
145
|
-
setPosition({
|
|
146
|
-
end: e.clientX,
|
|
147
|
-
start: e.clientX,
|
|
148
|
-
status: 'down',
|
|
149
|
-
});
|
|
150
|
-
document.addEventListener('mousemove', documentOnMouseMove);
|
|
151
|
-
document.addEventListener('mouseup', documentOnMouseUp);
|
|
152
|
-
}, []);
|
|
153
|
-
|
|
154
|
-
useEffect(() => {
|
|
155
|
-
const { start, end, status } = position;
|
|
156
|
-
move({ delta: end - start, status, name });
|
|
157
|
-
}, [position, move, name]);
|
|
158
|
-
return <div style={style} onMouseDown={onMouseDown} />;
|
|
159
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* 实现中
|
|
3
|
+
*/
|
|
4
|
+
import { memo, useState, useCallback, useEffect, useRef } from 'react';
|
|
5
|
+
|
|
6
|
+
const left = {
|
|
7
|
+
position: 'relative',
|
|
8
|
+
width: 5,
|
|
9
|
+
height: '100%',
|
|
10
|
+
cursor: 'col-resize',
|
|
11
|
+
backgroundClip: 'content-box',
|
|
12
|
+
};
|
|
13
|
+
const center = {
|
|
14
|
+
flex: '1 1 0%',
|
|
15
|
+
height: '100%',
|
|
16
|
+
cursor: 'move',
|
|
17
|
+
};
|
|
18
|
+
const right = {
|
|
19
|
+
position: 'relative',
|
|
20
|
+
width: 5,
|
|
21
|
+
height: '100%',
|
|
22
|
+
cursor: 'col-resize',
|
|
23
|
+
backgroundClip: 'content-box',
|
|
24
|
+
};
|
|
25
|
+
const initialPosition = {
|
|
26
|
+
start: 0,
|
|
27
|
+
end: 0,
|
|
28
|
+
status: '',
|
|
29
|
+
};
|
|
30
|
+
const getValue = (x, min, max) => Math.max(min, Math.min(x, max));
|
|
31
|
+
export default ({
|
|
32
|
+
width,
|
|
33
|
+
config: {
|
|
34
|
+
height,
|
|
35
|
+
background,
|
|
36
|
+
margin: { marginLeft, marginRight },
|
|
37
|
+
detail: { width: blockWidth, color },
|
|
38
|
+
},
|
|
39
|
+
}) => {
|
|
40
|
+
const [state, setState] = useState({ translateX: 0, width: blockWidth });
|
|
41
|
+
const availableWidth = width - marginLeft - marginRight;
|
|
42
|
+
const cache = useRef(state);
|
|
43
|
+
|
|
44
|
+
const move = useCallback(
|
|
45
|
+
({ delta, status, name }) => {
|
|
46
|
+
let { width, translateX } = cache.current;
|
|
47
|
+
const minWidth = 40;
|
|
48
|
+
const minX = 0;
|
|
49
|
+
switch (name) {
|
|
50
|
+
case 'center':
|
|
51
|
+
translateX = getValue(
|
|
52
|
+
translateX + delta,
|
|
53
|
+
minX,
|
|
54
|
+
availableWidth - width
|
|
55
|
+
);
|
|
56
|
+
break;
|
|
57
|
+
case 'left':
|
|
58
|
+
let tempWidth = width;
|
|
59
|
+
width = getValue(width + delta * -1, minWidth, translateX + width);
|
|
60
|
+
translateX = getValue(
|
|
61
|
+
translateX + delta,
|
|
62
|
+
minX,
|
|
63
|
+
translateX + tempWidth - width
|
|
64
|
+
);
|
|
65
|
+
break;
|
|
66
|
+
case 'right':
|
|
67
|
+
width = getValue(
|
|
68
|
+
width + delta,
|
|
69
|
+
minWidth,
|
|
70
|
+
availableWidth - translateX
|
|
71
|
+
);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (status === 'up') {
|
|
76
|
+
cache.current = { width, translateX };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setState({ width, translateX });
|
|
80
|
+
},
|
|
81
|
+
[availableWidth]
|
|
82
|
+
);
|
|
83
|
+
useEffect(() => {}, [state]);
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
style={{
|
|
87
|
+
marginLeft,
|
|
88
|
+
marginRight,
|
|
89
|
+
height,
|
|
90
|
+
background,
|
|
91
|
+
position: 'absolute',
|
|
92
|
+
bottom: 0,
|
|
93
|
+
width: availableWidth,
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<div
|
|
97
|
+
style={{
|
|
98
|
+
display: 'flex',
|
|
99
|
+
justifyContent: 'space-between',
|
|
100
|
+
position: 'absolute',
|
|
101
|
+
top: 0,
|
|
102
|
+
left: 0,
|
|
103
|
+
transform: 'translate3d(' + state.translateX + 'px, 0, 0)',
|
|
104
|
+
height: '100%',
|
|
105
|
+
width: state.width + 'px',
|
|
106
|
+
backgroundColor: color,
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
<Move style={left} move={move} name='left' />
|
|
110
|
+
<Move style={center} move={move} name='center' />
|
|
111
|
+
<Move style={right} move={move} name='right' />
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
const Move = memo(({ style, move, name }) => {
|
|
117
|
+
const [position, setPosition] = useState(initialPosition);
|
|
118
|
+
|
|
119
|
+
const documentOnMouseMove = useCallback((e) => {
|
|
120
|
+
// console.log('documentOnMouseMove');
|
|
121
|
+
setPosition((position) => {
|
|
122
|
+
return {
|
|
123
|
+
...position,
|
|
124
|
+
end: e.clientX,
|
|
125
|
+
status: 'move',
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
const documentOnMouseUp = useCallback((e) => {
|
|
131
|
+
// console.log('documentOnMouseUp');
|
|
132
|
+
setPosition((position) => {
|
|
133
|
+
return {
|
|
134
|
+
...position,
|
|
135
|
+
end: e.clientX,
|
|
136
|
+
status: 'up',
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
document.removeEventListener('mousemove', documentOnMouseMove);
|
|
140
|
+
document.removeEventListener('mouseup', documentOnMouseUp);
|
|
141
|
+
}, []);
|
|
142
|
+
|
|
143
|
+
const onMouseDown = useCallback((e) => {
|
|
144
|
+
// console.log('onMouseDown');
|
|
145
|
+
setPosition({
|
|
146
|
+
end: e.clientX,
|
|
147
|
+
start: e.clientX,
|
|
148
|
+
status: 'down',
|
|
149
|
+
});
|
|
150
|
+
document.addEventListener('mousemove', documentOnMouseMove);
|
|
151
|
+
document.addEventListener('mouseup', documentOnMouseUp);
|
|
152
|
+
}, []);
|
|
153
|
+
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
const { start, end, status } = position;
|
|
156
|
+
move({ delta: end - start, status, name });
|
|
157
|
+
}, [position, move, name]);
|
|
158
|
+
return <div style={style} onMouseDown={onMouseDown} />;
|
|
159
|
+
});
|
|
@@ -468,6 +468,7 @@ const Chart = memo(
|
|
|
468
468
|
xName={item.tick}
|
|
469
469
|
setCtlTip={setCtlTip}
|
|
470
470
|
ctlIndicatorList={ctlIndicatorList}
|
|
471
|
+
manual= {manual}
|
|
471
472
|
/>
|
|
472
473
|
);
|
|
473
474
|
})}
|
|
@@ -571,6 +572,7 @@ const Chart = memo(
|
|
|
571
572
|
series={series}
|
|
572
573
|
width={width}
|
|
573
574
|
height={height}
|
|
575
|
+
manual= {manual}
|
|
574
576
|
/>
|
|
575
577
|
)}
|
|
576
578
|
{showCtl && !!control && (
|
|
@@ -585,6 +587,7 @@ const Chart = memo(
|
|
|
585
587
|
series={series}
|
|
586
588
|
width={width}
|
|
587
589
|
height={height}
|
|
590
|
+
manual= {manual}
|
|
588
591
|
/>
|
|
589
592
|
)}
|
|
590
593
|
{brush && <Brush config={brush} width={width} />}
|
package/src/components/Chart.js
CHANGED
|
@@ -1,154 +1,153 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 总入口,通过外面传进来的type来确定渲染哪种图表,饼环图表为“pie”,否则为轴类图表
|
|
3
|
-
*/
|
|
4
|
-
import React, { memo, useMemo, useRef, createRef, useState, useEffect, useCallback } from 'react';
|
|
5
|
-
import { chartContext } from '../context';
|
|
6
|
-
import { PieChart, CartesianChart } from '.';
|
|
7
|
-
import { group } from 'd3v7';
|
|
8
|
-
|
|
9
|
-
const getCallbackData = (action,callbacks, data) => {
|
|
10
|
-
const callbackData={};
|
|
11
|
-
if (callbacks && Array.isArray(callbacks) && callbacks.length && data) {
|
|
12
|
-
callbacks.forEach(({ origin, target, actions:_action }) => {
|
|
13
|
-
if(action === _action){
|
|
14
|
-
callbackData[target] = data[origin];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return callbackData;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const Chart = memo(
|
|
22
|
-
({
|
|
23
|
-
id,
|
|
24
|
-
type,
|
|
25
|
-
config,
|
|
26
|
-
config: {
|
|
27
|
-
axes,
|
|
28
|
-
chart: {
|
|
29
|
-
dimension: {
|
|
30
|
-
chartDimension: { height, width },
|
|
31
|
-
},
|
|
32
|
-
margin: { marginRight, marginLeft, marginBottom, marginTop },
|
|
33
|
-
},
|
|
34
|
-
interaction,
|
|
35
|
-
},
|
|
36
|
-
data:originData,
|
|
37
|
-
onRelative,
|
|
38
|
-
emit,
|
|
39
|
-
emitEvent,
|
|
40
|
-
...props
|
|
41
|
-
}) => {
|
|
42
|
-
const isIOS = useRef(/iPad|iPhone|iPod|iOS|CriOS/i.test(navigator.userAgent));
|
|
43
|
-
const svg = createRef();
|
|
44
|
-
const chartWidth = width - marginLeft - marginRight;
|
|
45
|
-
const chartHeight = height - marginTop - marginBottom;
|
|
46
|
-
const [active, setActive] = useState(true);
|
|
47
|
-
const scaleRef = useRef([1,1]);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
control.
|
|
62
|
-
control.type
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
document.addEventListener(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
document.removeEventListener(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
export default Chart;
|
|
1
|
+
/**
|
|
2
|
+
* 总入口,通过外面传进来的type来确定渲染哪种图表,饼环图表为“pie”,否则为轴类图表
|
|
3
|
+
*/
|
|
4
|
+
import React, { memo, useMemo, useRef, createRef, useState, useEffect, useCallback } from 'react';
|
|
5
|
+
import { chartContext } from '../context';
|
|
6
|
+
import { PieChart, CartesianChart } from '.';
|
|
7
|
+
import { group } from 'd3v7';
|
|
8
|
+
|
|
9
|
+
const getCallbackData = (action,callbacks, data) => {
|
|
10
|
+
const callbackData={};
|
|
11
|
+
if (callbacks && Array.isArray(callbacks) && callbacks.length && data) {
|
|
12
|
+
callbacks.forEach(({ origin, target, actions:_action }) => {
|
|
13
|
+
if(action === _action){
|
|
14
|
+
callbackData[target] = data[origin];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return callbackData;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const Chart = memo(
|
|
22
|
+
({
|
|
23
|
+
id,
|
|
24
|
+
type,
|
|
25
|
+
config,
|
|
26
|
+
config: {
|
|
27
|
+
axes,
|
|
28
|
+
chart: {
|
|
29
|
+
dimension: {
|
|
30
|
+
chartDimension: { height, width },
|
|
31
|
+
},
|
|
32
|
+
margin: { marginRight, marginLeft, marginBottom, marginTop },
|
|
33
|
+
},
|
|
34
|
+
interaction,
|
|
35
|
+
},
|
|
36
|
+
data:originData,
|
|
37
|
+
onRelative,
|
|
38
|
+
emit,
|
|
39
|
+
emitEvent,
|
|
40
|
+
...props
|
|
41
|
+
}) => {
|
|
42
|
+
const isIOS = useRef(/iPad|iPhone|iPod|iOS|CriOS/i.test(navigator.userAgent));
|
|
43
|
+
const svg = createRef();
|
|
44
|
+
const chartWidth = width - marginLeft - marginRight;
|
|
45
|
+
const chartHeight = height - marginTop - marginBottom;
|
|
46
|
+
const [active, setActive] = useState(true);
|
|
47
|
+
const scaleRef = useRef([1,1]);
|
|
48
|
+
const triggerOnRelative = useCallback(
|
|
49
|
+
(action,data) => {
|
|
50
|
+
if (!interaction) return;
|
|
51
|
+
const { callbacks, remoteControls } = interaction;
|
|
52
|
+
const callbackData = getCallbackData(action,callbacks, data);
|
|
53
|
+
if (JSON.stringify(callbackData)!="{}") {
|
|
54
|
+
onRelative && onRelative(id, callbackData);
|
|
55
|
+
remoteControls &&
|
|
56
|
+
emitEvent &&
|
|
57
|
+
remoteControls.forEach((o) => {
|
|
58
|
+
const control = JSON.parse(o.control);
|
|
59
|
+
if (
|
|
60
|
+
control.screen &&
|
|
61
|
+
control.type &&
|
|
62
|
+
control.type === 'callback'
|
|
63
|
+
) {
|
|
64
|
+
emitEvent({
|
|
65
|
+
screen: control.screen,
|
|
66
|
+
type: 'callback',
|
|
67
|
+
callbackData,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[ JSON.stringify(interaction)]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const onEmit = useCallback(
|
|
77
|
+
(type = 'click', data) => emit && emit(type, data),
|
|
78
|
+
[emit]
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const context = useMemo(
|
|
82
|
+
() => ({
|
|
83
|
+
id,
|
|
84
|
+
isIOS:isIOS.current, //是否为IOS设备
|
|
85
|
+
scale:scaleRef, //大屏的缩放比
|
|
86
|
+
width: chartWidth,
|
|
87
|
+
height: chartHeight,
|
|
88
|
+
triggerOnRelative,
|
|
89
|
+
svg,
|
|
90
|
+
onEmit,
|
|
91
|
+
}),
|
|
92
|
+
[id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
useEffect(()=>{
|
|
96
|
+
let isAnimation = window.screenConfig?window.screenConfig.isAnimation:true; //大屏的全局设置是否允许开启动画,false为不允许
|
|
97
|
+
if(!isAnimation) setActive(false);
|
|
98
|
+
const activeHandler=(e)=>{
|
|
99
|
+
const { dynamicData = true } = e;
|
|
100
|
+
// console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
|
|
101
|
+
isAnimation && setActive(dynamicData);
|
|
102
|
+
}
|
|
103
|
+
getScreenScale();
|
|
104
|
+
document.addEventListener(`switchActive_${id}`,activeHandler);
|
|
105
|
+
document.addEventListener("resize",getScreenScale);
|
|
106
|
+
return ()=>{
|
|
107
|
+
document.removeEventListener(`switchActive_${id}`,activeHandler);
|
|
108
|
+
document.removeEventListener("resize",getScreenScale);
|
|
109
|
+
}
|
|
110
|
+
},[]);
|
|
111
|
+
|
|
112
|
+
let data = originData;
|
|
113
|
+
//对轴类图表进行自动排序
|
|
114
|
+
// if(axes){
|
|
115
|
+
// const xAxis = axes.find(d=>d.axisType=="x");
|
|
116
|
+
// if(xAxis){
|
|
117
|
+
// const { config:{ label:{ autoSort, format:{ type } } } } = xAxis;
|
|
118
|
+
// if(type=="date" && autoSort){
|
|
119
|
+
// const groupBySeries = group(data, (d) => d.s);
|
|
120
|
+
// data=[...groupBySeries].flatMap(d=>{
|
|
121
|
+
// return d[1].sort((a,b)=>a.x>b.x?1:-1)
|
|
122
|
+
// });
|
|
123
|
+
// }
|
|
124
|
+
// }
|
|
125
|
+
// }
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<chartContext.Provider value={context}>
|
|
129
|
+
{type == 'pie' ? (
|
|
130
|
+
<PieChart id={id} config={config} data={data} active={active} {...props} />
|
|
131
|
+
) : (
|
|
132
|
+
<CartesianChart id={id} config={config} data={data} active={active} {...props} />
|
|
133
|
+
)}
|
|
134
|
+
</chartContext.Provider>
|
|
135
|
+
|
|
136
|
+
);
|
|
137
|
+
//获取大屏缩放系数
|
|
138
|
+
function getScreenScale(){
|
|
139
|
+
setTimeout(()=>{
|
|
140
|
+
//获取大屏缩放系数
|
|
141
|
+
let dom = document.getElementById("bigscreen-container") || document.getElementById("m-simulator");
|
|
142
|
+
if(dom){
|
|
143
|
+
const transform = dom.style.transform;
|
|
144
|
+
const scale = transform?transform.match(/^scale\((.+)\)$/)[1]:"1,1";
|
|
145
|
+
const arr = scale.split(",");
|
|
146
|
+
scaleRef.current = [1/arr[0],1/(arr.length===1?arr[0]:arr[1])]; //这里做一次除法,后面就可以用乘法计算值了
|
|
147
|
+
}
|
|
148
|
+
},50);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
export default Chart;
|