@easyv/charts 1.6.20 → 1.6.21
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 +55 -31
- package/lib/components/Brush.js +2 -2
- package/lib/components/CartesianChart.js +3 -1
- package/lib/components/Chart.js +2 -3
- 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 +2 -2
- 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/css/index.module.css +42 -42
- package/lib/css/piechart.module.css +26 -26
- package/lib/hooks/useAnimateData.js +6 -6
- package/lib/hooks/useAxes.js +20 -16
- 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 +321 -302
- package/src/components/Brush.js +159 -159
- package/src/components/CartesianChart.js +1 -1
- package/src/components/Chart.js +153 -153
- 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 -59
- 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/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/useAxes.js +20 -16
- 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
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
import React, { forwardRef, memo, useRef, useContext } from "react";
|
|
2
|
-
import { chartContext } from "../context";
|
|
3
|
-
import { scaleLinear } from "d3-scale";
|
|
4
|
-
import { mathR } from "../utils";
|
|
5
|
-
|
|
6
|
-
export default memo(forwardRef((props, ref) => {
|
|
7
|
-
const {
|
|
8
|
-
actions:{ setX, setWorking, setControlWidth },
|
|
9
|
-
props: {
|
|
10
|
-
control:{ height, color, gap, drag:{ color:dragColor }, margin:{ left } },
|
|
11
|
-
controlInfo:{ cWidth, cBarWidth },
|
|
12
|
-
axes, series, top, bandLength
|
|
13
|
-
}
|
|
14
|
-
} = props;
|
|
15
|
-
const context = useContext(chartContext);
|
|
16
|
-
const scale = context.scale;
|
|
17
|
-
const xAxis = axes.get("x");
|
|
18
|
-
const barRef = useRef();
|
|
19
|
-
|
|
20
|
-
const barStyle={
|
|
21
|
-
position:"absolute",
|
|
22
|
-
top:0,
|
|
23
|
-
width:cBarWidth,
|
|
24
|
-
display:"flex",
|
|
25
|
-
justifyContent:"space-between",
|
|
26
|
-
background:dragColor
|
|
27
|
-
}
|
|
28
|
-
const dragStyle={
|
|
29
|
-
height,
|
|
30
|
-
flex:1,
|
|
31
|
-
cursor:"move"
|
|
32
|
-
}
|
|
33
|
-
const controllerStyle={
|
|
34
|
-
position:"relative",
|
|
35
|
-
width:12,
|
|
36
|
-
height,
|
|
37
|
-
padding:"0 5px",
|
|
38
|
-
cursor:"col-resize",
|
|
39
|
-
background:"rgb(2, 176, 249)",
|
|
40
|
-
WebkitBackgroundClip:"content-box",
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//左手柄的鼠标按下逻辑
|
|
44
|
-
const leftDown=()=>{
|
|
45
|
-
const transform = ref.current.style.transform;
|
|
46
|
-
let initX = 0;
|
|
47
|
-
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
48
|
-
const rightX = rawTranslateX+cBarWidth;
|
|
49
|
-
const move=(e)=>{
|
|
50
|
-
const { movementX:ex } = e;
|
|
51
|
-
const movementX = ex * scale.current[0];
|
|
52
|
-
initX = mathR(initX+movementX,[-rawTranslateX, rightX-rawTranslateX]);
|
|
53
|
-
setControlWidth((pre)=>{
|
|
54
|
-
const { cWidth, cBarWidth } = pre;
|
|
55
|
-
const nextBarWidth = mathR(cBarWidth-movementX,[1,rightX]);
|
|
56
|
-
return {
|
|
57
|
-
...pre,
|
|
58
|
-
cBarWidth:nextBarWidth,
|
|
59
|
-
cPercent:nextBarWidth/cWidth,
|
|
60
|
-
cBarX:initX+rawTranslateX
|
|
61
|
-
}
|
|
62
|
-
}, true);
|
|
63
|
-
}
|
|
64
|
-
const up=()=>{
|
|
65
|
-
document.removeEventListener("mousemove",move);
|
|
66
|
-
document.removeEventListener("mouseup",up);
|
|
67
|
-
}
|
|
68
|
-
document.addEventListener("mousemove",move);
|
|
69
|
-
document.addEventListener("mouseup",up);
|
|
70
|
-
}
|
|
71
|
-
//左手手柄的移动端适配
|
|
72
|
-
const leftTouchStart = (e)=>{
|
|
73
|
-
const transform = ref.current.style.transform;
|
|
74
|
-
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
75
|
-
let initX = 0;
|
|
76
|
-
const rightX = rawTranslateX+cBarWidth;
|
|
77
|
-
let startX = e.touches[0].clientX;
|
|
78
|
-
let currentX = 0;
|
|
79
|
-
let movementX = 0;
|
|
80
|
-
const move = (e)=>{
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
currentX = e.touches[0].clientX;
|
|
83
|
-
movementX = currentX - startX;
|
|
84
|
-
startX = currentX;
|
|
85
|
-
initX = mathR(initX+movementX,[-rawTranslateX, rightX-rawTranslateX]);
|
|
86
|
-
setControlWidth((pre)=>{
|
|
87
|
-
const { cWidth, cBarWidth } = pre;
|
|
88
|
-
const nextBarWidth = mathR(cBarWidth-movementX,[1,rightX]);
|
|
89
|
-
return {
|
|
90
|
-
...pre,
|
|
91
|
-
cBarWidth:nextBarWidth,
|
|
92
|
-
cPercent:nextBarWidth/cWidth,
|
|
93
|
-
cBarX:initX+rawTranslateX
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
const up = (e) => {
|
|
98
|
-
document.removeEventListener("touchmove", move);
|
|
99
|
-
document.removeEventListener("touchend", up);
|
|
100
|
-
};
|
|
101
|
-
document.addEventListener("touchmove", move, {passive:false});
|
|
102
|
-
document.addEventListener("touchend", up);
|
|
103
|
-
}
|
|
104
|
-
//滑块的鼠标按下操作
|
|
105
|
-
const down=()=>{
|
|
106
|
-
const transform = ref.current.style.transform;
|
|
107
|
-
let movementX = 0;
|
|
108
|
-
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
109
|
-
const mouseMoveHandle = (e) => {
|
|
110
|
-
//当前位移的距离
|
|
111
|
-
movementX += e.movementX * scale.current[0];
|
|
112
|
-
setX(movementX + rawTranslateX,true);
|
|
113
|
-
};
|
|
114
|
-
const mouseUpHandle = (e) => {
|
|
115
|
-
setWorking(false);
|
|
116
|
-
document.removeEventListener("mousemove", mouseMoveHandle);
|
|
117
|
-
document.removeEventListener("mouseup", mouseUpHandle);
|
|
118
|
-
};
|
|
119
|
-
document.addEventListener("mousemove", mouseMoveHandle);
|
|
120
|
-
document.addEventListener("mouseup", mouseUpHandle);
|
|
121
|
-
setWorking(true);
|
|
122
|
-
}
|
|
123
|
-
//移动端适配
|
|
124
|
-
const touchStart=(e)=>{
|
|
125
|
-
const transform = ref.current.style.transform;
|
|
126
|
-
let startX = e.touches[0].clientX;
|
|
127
|
-
let currentX = 0;
|
|
128
|
-
let movementX = 0;
|
|
129
|
-
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
130
|
-
const mouseMoveHandle = (e)=>{
|
|
131
|
-
e.preventDefault();
|
|
132
|
-
currentX = e.touches[0].clientX;
|
|
133
|
-
movementX += currentX - startX;
|
|
134
|
-
startX = currentX;
|
|
135
|
-
setX(movementX + rawTranslateX, true);
|
|
136
|
-
}
|
|
137
|
-
const mouseUpHandle = (e) => {
|
|
138
|
-
setWorking(false);
|
|
139
|
-
document.removeEventListener("touchmove", mouseMoveHandle);
|
|
140
|
-
document.removeEventListener("touchend", mouseUpHandle);
|
|
141
|
-
};
|
|
142
|
-
document.addEventListener("touchmove", mouseMoveHandle, {passive:false});
|
|
143
|
-
document.addEventListener("touchend", mouseUpHandle);
|
|
144
|
-
setWorking(true);
|
|
145
|
-
}
|
|
146
|
-
//右手柄的鼠标按下逻辑
|
|
147
|
-
const rightDown=()=>{
|
|
148
|
-
const transform = ref.current.style.transform;
|
|
149
|
-
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
150
|
-
const move=(e)=>{
|
|
151
|
-
const { movementX:ex } = e;
|
|
152
|
-
const movementX = ex * scale.current[0];
|
|
153
|
-
setControlWidth((pre)=>{
|
|
154
|
-
const { cWidth, cBarWidth } = pre;
|
|
155
|
-
const maxWidth = cWidth-rawTranslateX;
|
|
156
|
-
const nextBarWidth = mathR(cBarWidth+movementX,[1,maxWidth]);
|
|
157
|
-
return {
|
|
158
|
-
...pre,
|
|
159
|
-
cBarWidth:nextBarWidth,
|
|
160
|
-
cPercent:nextBarWidth/cWidth
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
const up=()=>{
|
|
165
|
-
document.removeEventListener("mousemove",move);
|
|
166
|
-
document.removeEventListener("mouseup",up);
|
|
167
|
-
}
|
|
168
|
-
document.addEventListener("mousemove",move);
|
|
169
|
-
document.addEventListener("mouseup",up);
|
|
170
|
-
}
|
|
171
|
-
//右手手柄的移动端适配
|
|
172
|
-
const rightTouchStart = (e)=>{
|
|
173
|
-
const transform = ref.current.style.transform;
|
|
174
|
-
let startX = e.touches[0].clientX;
|
|
175
|
-
let currentX = 0;
|
|
176
|
-
let movementX = 0;
|
|
177
|
-
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
178
|
-
const move = (e)=>{
|
|
179
|
-
e.preventDefault();
|
|
180
|
-
currentX = e.touches[0].clientX;
|
|
181
|
-
movementX = currentX - startX;
|
|
182
|
-
startX = currentX;
|
|
183
|
-
setControlWidth((pre)=>{
|
|
184
|
-
const { cWidth, cBarWidth } = pre;
|
|
185
|
-
const maxWidth = cWidth-rawTranslateX;
|
|
186
|
-
const nextBarWidth = mathR(cBarWidth+movementX,[1,maxWidth]);
|
|
187
|
-
return {
|
|
188
|
-
...pre,
|
|
189
|
-
cBarWidth:nextBarWidth,
|
|
190
|
-
cPercent:nextBarWidth/cWidth
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
const up = (e) => {
|
|
195
|
-
document.removeEventListener("touchmove", move);
|
|
196
|
-
document.removeEventListener("touchend", up);
|
|
197
|
-
};
|
|
198
|
-
document.addEventListener("touchmove", move, {passive:false});
|
|
199
|
-
document.addEventListener("touchend", up);
|
|
200
|
-
}
|
|
201
|
-
return (
|
|
202
|
-
<div
|
|
203
|
-
style={{
|
|
204
|
-
width:cWidth,
|
|
205
|
-
height: height,
|
|
206
|
-
backgroundColor: color,
|
|
207
|
-
transform: `translate(${left}px,${top-height+gap}px)`,
|
|
208
|
-
}}
|
|
209
|
-
>
|
|
210
|
-
<svg width="100%" height="100%">
|
|
211
|
-
{series.map(({ Component, yOrZ, ...config }, index) => {
|
|
212
|
-
const yAxis = axes.get(yOrZ);
|
|
213
|
-
const cloneYAxis = JSON.parse(JSON.stringify(yAxis));
|
|
214
|
-
//todo range
|
|
215
|
-
cloneYAxis.scaler = scaleLinear()
|
|
216
|
-
.domain(yAxis.domain)
|
|
217
|
-
.range([height, 0]);
|
|
218
|
-
return (
|
|
219
|
-
yAxis &&
|
|
220
|
-
Component && (
|
|
221
|
-
<Component
|
|
222
|
-
key={index}
|
|
223
|
-
{...config}
|
|
224
|
-
bandLength={bandLength}
|
|
225
|
-
xAxis={xAxis}
|
|
226
|
-
yAxis={cloneYAxis}
|
|
227
|
-
/>
|
|
228
|
-
)
|
|
229
|
-
);
|
|
230
|
-
})}
|
|
231
|
-
</svg>
|
|
232
|
-
{/* 控制条 */}
|
|
233
|
-
<div ref={ref} style={barStyle}>
|
|
234
|
-
<div style={{...controllerStyle,transform:"translateX(-6px)"}} onMouseDown={leftDown} onTouchStart={leftTouchStart}></div>
|
|
235
|
-
<div style={dragStyle} onMouseDown={down} onTouchStart={touchStart} ref={barRef}></div>
|
|
236
|
-
<div style={{...controllerStyle,transform:`translateX(6px)`}} onMouseDown={rightDown} onTouchStart={rightTouchStart}></div>
|
|
237
|
-
</div>
|
|
238
|
-
</div>
|
|
239
|
-
);
|
|
240
|
-
}))
|
|
241
|
-
|
|
1
|
+
import React, { forwardRef, memo, useRef, useContext } from "react";
|
|
2
|
+
import { chartContext } from "../context";
|
|
3
|
+
import { scaleLinear } from "d3-scale";
|
|
4
|
+
import { mathR } from "../utils";
|
|
5
|
+
|
|
6
|
+
export default memo(forwardRef((props, ref) => {
|
|
7
|
+
const {
|
|
8
|
+
actions:{ setX, setWorking, setControlWidth },
|
|
9
|
+
props: {
|
|
10
|
+
control:{ height, color, gap, drag:{ color:dragColor }, margin:{ left } },
|
|
11
|
+
controlInfo:{ cWidth, cBarWidth },
|
|
12
|
+
axes, series, top, bandLength
|
|
13
|
+
}
|
|
14
|
+
} = props;
|
|
15
|
+
const context = useContext(chartContext);
|
|
16
|
+
const scale = context.scale;
|
|
17
|
+
const xAxis = axes.get("x");
|
|
18
|
+
const barRef = useRef();
|
|
19
|
+
|
|
20
|
+
const barStyle={
|
|
21
|
+
position:"absolute",
|
|
22
|
+
top:0,
|
|
23
|
+
width:cBarWidth,
|
|
24
|
+
display:"flex",
|
|
25
|
+
justifyContent:"space-between",
|
|
26
|
+
background:dragColor
|
|
27
|
+
}
|
|
28
|
+
const dragStyle={
|
|
29
|
+
height,
|
|
30
|
+
flex:1,
|
|
31
|
+
cursor:"move"
|
|
32
|
+
}
|
|
33
|
+
const controllerStyle={
|
|
34
|
+
position:"relative",
|
|
35
|
+
width:12,
|
|
36
|
+
height,
|
|
37
|
+
padding:"0 5px",
|
|
38
|
+
cursor:"col-resize",
|
|
39
|
+
background:"rgb(2, 176, 249)",
|
|
40
|
+
WebkitBackgroundClip:"content-box",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//左手柄的鼠标按下逻辑
|
|
44
|
+
const leftDown=()=>{
|
|
45
|
+
const transform = ref.current.style.transform;
|
|
46
|
+
let initX = 0;
|
|
47
|
+
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
48
|
+
const rightX = rawTranslateX+cBarWidth;
|
|
49
|
+
const move=(e)=>{
|
|
50
|
+
const { movementX:ex } = e;
|
|
51
|
+
const movementX = ex * scale.current[0];
|
|
52
|
+
initX = mathR(initX+movementX,[-rawTranslateX, rightX-rawTranslateX]);
|
|
53
|
+
setControlWidth((pre)=>{
|
|
54
|
+
const { cWidth, cBarWidth } = pre;
|
|
55
|
+
const nextBarWidth = mathR(cBarWidth-movementX,[1,rightX]);
|
|
56
|
+
return {
|
|
57
|
+
...pre,
|
|
58
|
+
cBarWidth:nextBarWidth,
|
|
59
|
+
cPercent:nextBarWidth/cWidth,
|
|
60
|
+
cBarX:initX+rawTranslateX
|
|
61
|
+
}
|
|
62
|
+
}, true);
|
|
63
|
+
}
|
|
64
|
+
const up=()=>{
|
|
65
|
+
document.removeEventListener("mousemove",move);
|
|
66
|
+
document.removeEventListener("mouseup",up);
|
|
67
|
+
}
|
|
68
|
+
document.addEventListener("mousemove",move);
|
|
69
|
+
document.addEventListener("mouseup",up);
|
|
70
|
+
}
|
|
71
|
+
//左手手柄的移动端适配
|
|
72
|
+
const leftTouchStart = (e)=>{
|
|
73
|
+
const transform = ref.current.style.transform;
|
|
74
|
+
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
75
|
+
let initX = 0;
|
|
76
|
+
const rightX = rawTranslateX+cBarWidth;
|
|
77
|
+
let startX = e.touches[0].clientX;
|
|
78
|
+
let currentX = 0;
|
|
79
|
+
let movementX = 0;
|
|
80
|
+
const move = (e)=>{
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
currentX = e.touches[0].clientX;
|
|
83
|
+
movementX = currentX - startX;
|
|
84
|
+
startX = currentX;
|
|
85
|
+
initX = mathR(initX+movementX,[-rawTranslateX, rightX-rawTranslateX]);
|
|
86
|
+
setControlWidth((pre)=>{
|
|
87
|
+
const { cWidth, cBarWidth } = pre;
|
|
88
|
+
const nextBarWidth = mathR(cBarWidth-movementX,[1,rightX]);
|
|
89
|
+
return {
|
|
90
|
+
...pre,
|
|
91
|
+
cBarWidth:nextBarWidth,
|
|
92
|
+
cPercent:nextBarWidth/cWidth,
|
|
93
|
+
cBarX:initX+rawTranslateX
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const up = (e) => {
|
|
98
|
+
document.removeEventListener("touchmove", move);
|
|
99
|
+
document.removeEventListener("touchend", up);
|
|
100
|
+
};
|
|
101
|
+
document.addEventListener("touchmove", move, {passive:false});
|
|
102
|
+
document.addEventListener("touchend", up);
|
|
103
|
+
}
|
|
104
|
+
//滑块的鼠标按下操作
|
|
105
|
+
const down=()=>{
|
|
106
|
+
const transform = ref.current.style.transform;
|
|
107
|
+
let movementX = 0;
|
|
108
|
+
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
109
|
+
const mouseMoveHandle = (e) => {
|
|
110
|
+
//当前位移的距离
|
|
111
|
+
movementX += e.movementX * scale.current[0];
|
|
112
|
+
setX(movementX + rawTranslateX,true);
|
|
113
|
+
};
|
|
114
|
+
const mouseUpHandle = (e) => {
|
|
115
|
+
setWorking(false);
|
|
116
|
+
document.removeEventListener("mousemove", mouseMoveHandle);
|
|
117
|
+
document.removeEventListener("mouseup", mouseUpHandle);
|
|
118
|
+
};
|
|
119
|
+
document.addEventListener("mousemove", mouseMoveHandle);
|
|
120
|
+
document.addEventListener("mouseup", mouseUpHandle);
|
|
121
|
+
setWorking(true);
|
|
122
|
+
}
|
|
123
|
+
//移动端适配
|
|
124
|
+
const touchStart=(e)=>{
|
|
125
|
+
const transform = ref.current.style.transform;
|
|
126
|
+
let startX = e.touches[0].clientX;
|
|
127
|
+
let currentX = 0;
|
|
128
|
+
let movementX = 0;
|
|
129
|
+
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
130
|
+
const mouseMoveHandle = (e)=>{
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
currentX = e.touches[0].clientX;
|
|
133
|
+
movementX += currentX - startX;
|
|
134
|
+
startX = currentX;
|
|
135
|
+
setX(movementX + rawTranslateX, true);
|
|
136
|
+
}
|
|
137
|
+
const mouseUpHandle = (e) => {
|
|
138
|
+
setWorking(false);
|
|
139
|
+
document.removeEventListener("touchmove", mouseMoveHandle);
|
|
140
|
+
document.removeEventListener("touchend", mouseUpHandle);
|
|
141
|
+
};
|
|
142
|
+
document.addEventListener("touchmove", mouseMoveHandle, {passive:false});
|
|
143
|
+
document.addEventListener("touchend", mouseUpHandle);
|
|
144
|
+
setWorking(true);
|
|
145
|
+
}
|
|
146
|
+
//右手柄的鼠标按下逻辑
|
|
147
|
+
const rightDown=()=>{
|
|
148
|
+
const transform = ref.current.style.transform;
|
|
149
|
+
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
150
|
+
const move=(e)=>{
|
|
151
|
+
const { movementX:ex } = e;
|
|
152
|
+
const movementX = ex * scale.current[0];
|
|
153
|
+
setControlWidth((pre)=>{
|
|
154
|
+
const { cWidth, cBarWidth } = pre;
|
|
155
|
+
const maxWidth = cWidth-rawTranslateX;
|
|
156
|
+
const nextBarWidth = mathR(cBarWidth+movementX,[1,maxWidth]);
|
|
157
|
+
return {
|
|
158
|
+
...pre,
|
|
159
|
+
cBarWidth:nextBarWidth,
|
|
160
|
+
cPercent:nextBarWidth/cWidth
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const up=()=>{
|
|
165
|
+
document.removeEventListener("mousemove",move);
|
|
166
|
+
document.removeEventListener("mouseup",up);
|
|
167
|
+
}
|
|
168
|
+
document.addEventListener("mousemove",move);
|
|
169
|
+
document.addEventListener("mouseup",up);
|
|
170
|
+
}
|
|
171
|
+
//右手手柄的移动端适配
|
|
172
|
+
const rightTouchStart = (e)=>{
|
|
173
|
+
const transform = ref.current.style.transform;
|
|
174
|
+
let startX = e.touches[0].clientX;
|
|
175
|
+
let currentX = 0;
|
|
176
|
+
let movementX = 0;
|
|
177
|
+
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
178
|
+
const move = (e)=>{
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
currentX = e.touches[0].clientX;
|
|
181
|
+
movementX = currentX - startX;
|
|
182
|
+
startX = currentX;
|
|
183
|
+
setControlWidth((pre)=>{
|
|
184
|
+
const { cWidth, cBarWidth } = pre;
|
|
185
|
+
const maxWidth = cWidth-rawTranslateX;
|
|
186
|
+
const nextBarWidth = mathR(cBarWidth+movementX,[1,maxWidth]);
|
|
187
|
+
return {
|
|
188
|
+
...pre,
|
|
189
|
+
cBarWidth:nextBarWidth,
|
|
190
|
+
cPercent:nextBarWidth/cWidth
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const up = (e) => {
|
|
195
|
+
document.removeEventListener("touchmove", move);
|
|
196
|
+
document.removeEventListener("touchend", up);
|
|
197
|
+
};
|
|
198
|
+
document.addEventListener("touchmove", move, {passive:false});
|
|
199
|
+
document.addEventListener("touchend", up);
|
|
200
|
+
}
|
|
201
|
+
return (
|
|
202
|
+
<div
|
|
203
|
+
style={{
|
|
204
|
+
width:cWidth,
|
|
205
|
+
height: height,
|
|
206
|
+
backgroundColor: color,
|
|
207
|
+
transform: `translate(${left}px,${top-height+gap}px)`,
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
<svg width="100%" height="100%">
|
|
211
|
+
{series.map(({ Component, yOrZ, ...config }, index) => {
|
|
212
|
+
const yAxis = axes.get(yOrZ);
|
|
213
|
+
const cloneYAxis = JSON.parse(JSON.stringify(yAxis));
|
|
214
|
+
//todo range
|
|
215
|
+
cloneYAxis.scaler = scaleLinear()
|
|
216
|
+
.domain(yAxis.domain)
|
|
217
|
+
.range([height, 0]);
|
|
218
|
+
return (
|
|
219
|
+
yAxis &&
|
|
220
|
+
Component && (
|
|
221
|
+
<Component
|
|
222
|
+
key={index}
|
|
223
|
+
{...config}
|
|
224
|
+
bandLength={bandLength}
|
|
225
|
+
xAxis={xAxis}
|
|
226
|
+
yAxis={cloneYAxis}
|
|
227
|
+
/>
|
|
228
|
+
)
|
|
229
|
+
);
|
|
230
|
+
})}
|
|
231
|
+
</svg>
|
|
232
|
+
{/* 控制条 */}
|
|
233
|
+
<div ref={ref} style={barStyle}>
|
|
234
|
+
<div style={{...controllerStyle,transform:"translateX(-6px)"}} onMouseDown={leftDown} onTouchStart={leftTouchStart}></div>
|
|
235
|
+
<div style={dragStyle} onMouseDown={down} onTouchStart={touchStart} ref={barRef}></div>
|
|
236
|
+
<div style={{...controllerStyle,transform:`translateX(6px)`}} onMouseDown={rightDown} onTouchStart={rightTouchStart}></div>
|
|
237
|
+
</div>
|
|
238
|
+
</div>
|
|
239
|
+
);
|
|
240
|
+
}))
|
|
241
|
+
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 计算X/Y/Z轴的domain,具体的逻辑在useExtentData(HOC)
|
|
3
|
-
*/
|
|
4
|
-
import { memo } from 'react';
|
|
5
|
-
import { useExtentData } from '../hooks';
|
|
6
|
-
export default (Component) =>
|
|
7
|
-
memo(({ config: { axes, series, ...config }, data, ...props }) => {
|
|
8
|
-
return <Component
|
|
9
|
-
{...props}
|
|
10
|
-
config={{
|
|
11
|
-
...config,
|
|
12
|
-
axes: useExtentData({ series, axes, data }),
|
|
13
|
-
series,
|
|
14
|
-
}}
|
|
15
|
-
data={data}
|
|
16
|
-
/>
|
|
17
|
-
}
|
|
18
|
-
);
|
|
1
|
+
/**
|
|
2
|
+
* 计算X/Y/Z轴的domain,具体的逻辑在useExtentData(HOC)
|
|
3
|
+
*/
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { useExtentData } from '../hooks';
|
|
6
|
+
export default (Component) =>
|
|
7
|
+
memo(({ config: { axes, series, ...config }, data, ...props }) => {
|
|
8
|
+
return <Component
|
|
9
|
+
{...props}
|
|
10
|
+
config={{
|
|
11
|
+
...config,
|
|
12
|
+
axes: useExtentData({ series, axes, data }),
|
|
13
|
+
series,
|
|
14
|
+
}}
|
|
15
|
+
data={data}
|
|
16
|
+
/>
|
|
17
|
+
}
|
|
18
|
+
);
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 轴类图表移上去的指示框背景
|
|
3
|
-
*/
|
|
4
|
-
import { useState } from "react";
|
|
5
|
-
export default ({
|
|
6
|
-
color,
|
|
7
|
-
height,
|
|
8
|
-
width,
|
|
9
|
-
x = 0,
|
|
10
|
-
y = 0,
|
|
11
|
-
isControlChart = false,
|
|
12
|
-
xName = null,
|
|
13
|
-
ctlIndicatorList,
|
|
14
|
-
setCtlTip,
|
|
15
|
-
manual
|
|
16
|
-
}) => {
|
|
17
|
-
let isShow = true;
|
|
18
|
-
if (isControlChart && ctlIndicatorList) {
|
|
19
|
-
isShow = ctlIndicatorList.find(
|
|
20
|
-
(item) => item.tick === xName
|
|
21
|
-
).isShow;
|
|
22
|
-
}
|
|
23
|
-
return manual?(
|
|
24
|
-
<rect
|
|
25
|
-
width={width}
|
|
26
|
-
height={height}
|
|
27
|
-
x={x}
|
|
28
|
-
onMouseEnter={() => {
|
|
29
|
-
if (isControlChart) {
|
|
30
|
-
setCtlTip((pre)=>({
|
|
31
|
-
show:true, x:x+width/2, xName,
|
|
32
|
-
indicatorList:pre.indicatorList.map((item)=>{
|
|
33
|
-
if (item.tick === xName) {
|
|
34
|
-
return { ...item, isShow: true };
|
|
35
|
-
} else {
|
|
36
|
-
return item;
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
}))
|
|
40
|
-
}
|
|
41
|
-
}}
|
|
42
|
-
onMouseLeave={() => {
|
|
43
|
-
if (isControlChart) {
|
|
44
|
-
setCtlTip((pre)=>({
|
|
45
|
-
show:false,
|
|
46
|
-
x:undefined,
|
|
47
|
-
xName:undefined,
|
|
48
|
-
indicatorList:pre.indicatorList.map((item)=>{
|
|
49
|
-
return { ...item, isShow:false }
|
|
50
|
-
})
|
|
51
|
-
}))
|
|
52
|
-
}
|
|
53
|
-
}}
|
|
54
|
-
fill={isShow ? color : "transparent"}
|
|
55
|
-
y={y}
|
|
56
|
-
stroke="none"
|
|
57
|
-
/>
|
|
58
|
-
):"";
|
|
59
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* 轴类图表移上去的指示框背景
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
export default ({
|
|
6
|
+
color,
|
|
7
|
+
height,
|
|
8
|
+
width,
|
|
9
|
+
x = 0,
|
|
10
|
+
y = 0,
|
|
11
|
+
isControlChart = false,
|
|
12
|
+
xName = null,
|
|
13
|
+
ctlIndicatorList,
|
|
14
|
+
setCtlTip,
|
|
15
|
+
manual
|
|
16
|
+
}) => {
|
|
17
|
+
let isShow = true;
|
|
18
|
+
if (isControlChart && ctlIndicatorList) {
|
|
19
|
+
isShow = ctlIndicatorList.find(
|
|
20
|
+
(item) => item.tick === xName
|
|
21
|
+
).isShow;
|
|
22
|
+
}
|
|
23
|
+
return manual?(
|
|
24
|
+
<rect
|
|
25
|
+
width={width}
|
|
26
|
+
height={height}
|
|
27
|
+
x={x}
|
|
28
|
+
onMouseEnter={() => {
|
|
29
|
+
if (isControlChart) {
|
|
30
|
+
setCtlTip((pre)=>({
|
|
31
|
+
show:true, x:x+width/2, xName,
|
|
32
|
+
indicatorList:pre.indicatorList.map((item)=>{
|
|
33
|
+
if (item.tick === xName) {
|
|
34
|
+
return { ...item, isShow: true };
|
|
35
|
+
} else {
|
|
36
|
+
return item;
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
}))
|
|
40
|
+
}
|
|
41
|
+
}}
|
|
42
|
+
onMouseLeave={() => {
|
|
43
|
+
if (isControlChart) {
|
|
44
|
+
setCtlTip((pre)=>({
|
|
45
|
+
show:false,
|
|
46
|
+
x:undefined,
|
|
47
|
+
xName:undefined,
|
|
48
|
+
indicatorList:pre.indicatorList.map((item)=>{
|
|
49
|
+
return { ...item, isShow:false }
|
|
50
|
+
})
|
|
51
|
+
}))
|
|
52
|
+
}
|
|
53
|
+
}}
|
|
54
|
+
fill={isShow ? color : "transparent"}
|
|
55
|
+
y={y}
|
|
56
|
+
stroke="none"
|
|
57
|
+
/>
|
|
58
|
+
):"";
|
|
59
|
+
};
|