@easyv/charts 1.4.35 → 1.4.36
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/lib/components/Axis.js +7 -7
- package/lib/components/Band.js +28 -26
- package/lib/components/CartesianChart.js +208 -175
- package/lib/components/Control.js +78 -30
- package/lib/components/Indicator.js +30 -34
- package/lib/components/Label.js +1 -41
- package/lib/hooks/useAxes.js +43 -12
- package/lib/hooks/useCarouselAxisX.js +15 -16
- package/package.json +1 -1
- package/src/components/Axis.tsx +6 -7
- package/src/components/Band.tsx +27 -34
- package/src/components/CartesianChart.js +186 -196
- package/src/components/Control.jsx +87 -43
- package/src/components/Indicator.js +17 -20
- package/src/components/Label.js +1 -34
- package/src/components/Tooltip.js +0 -1
- package/src/hooks/useAxes.js +34 -16
- package/src/hooks/useCarouselAxisX.js +14 -18
|
@@ -10,15 +10,12 @@ export default ({
|
|
|
10
10
|
y = 0,
|
|
11
11
|
isControlChart = false,
|
|
12
12
|
xName = null,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
setControlChartTooltipX = null,
|
|
16
|
-
setControlChartIndicatorList = null,
|
|
17
|
-
controlChartIndicatorList = null,
|
|
13
|
+
ctlIndicatorList,
|
|
14
|
+
setCtlTip
|
|
18
15
|
}) => {
|
|
19
16
|
let isShow = true;
|
|
20
|
-
if (isControlChart &&
|
|
21
|
-
isShow =
|
|
17
|
+
if (isControlChart && ctlIndicatorList) {
|
|
18
|
+
isShow = ctlIndicatorList.find(
|
|
22
19
|
(item) => item.tick === xName
|
|
23
20
|
).isShow;
|
|
24
21
|
}
|
|
@@ -29,28 +26,28 @@ export default ({
|
|
|
29
26
|
x={x}
|
|
30
27
|
onMouseEnter={() => {
|
|
31
28
|
if (isControlChart) {
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
setCtlTip((pre)=>({
|
|
30
|
+
show:true, x:x+width/2, xName,
|
|
31
|
+
indicatorList:pre.indicatorList.map((item)=>{
|
|
34
32
|
if (item.tick === xName) {
|
|
35
33
|
return { ...item, isShow: true };
|
|
36
34
|
} else {
|
|
37
35
|
return item;
|
|
38
36
|
}
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
setControlChartTooltipShow(true);
|
|
42
|
-
setControlChartTooltipXName(xName);
|
|
43
|
-
setControlChartTooltipX(x);
|
|
37
|
+
})
|
|
38
|
+
}))
|
|
44
39
|
}
|
|
45
40
|
}}
|
|
46
41
|
onMouseLeave={() => {
|
|
47
42
|
if (isControlChart) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
setCtlTip((pre)=>({
|
|
44
|
+
show:false,
|
|
45
|
+
x:undefined,
|
|
46
|
+
xName:undefined,
|
|
47
|
+
indicatorList:pre.indicatorList.map((item)=>{
|
|
48
|
+
return { ...item, isShow:false }
|
|
49
|
+
})
|
|
50
|
+
}))
|
|
54
51
|
}
|
|
55
52
|
}}
|
|
56
53
|
fill={isShow ? color : "transparent"}
|
package/src/components/Label.js
CHANGED
|
@@ -18,14 +18,7 @@ export default memo(
|
|
|
18
18
|
data,
|
|
19
19
|
xAxis: { scaler: xScaler, step, direction },
|
|
20
20
|
yAxis: { scaler: yScaler, isClipAxis, clipValue },
|
|
21
|
-
triggerClick
|
|
22
|
-
//控制图相关
|
|
23
|
-
indicatorWidth,
|
|
24
|
-
setControlChartTooltipShow,
|
|
25
|
-
setControlChartTooltipX,
|
|
26
|
-
setControlChartTooltipXName,
|
|
27
|
-
isControlChart = false,
|
|
28
|
-
setControlChartIndicatorList = null,
|
|
21
|
+
triggerClick
|
|
29
22
|
}) => {
|
|
30
23
|
const lineType = config.hasOwnProperty("line"); // 堆叠处理
|
|
31
24
|
const showIcon = icon && icon.show;
|
|
@@ -104,32 +97,6 @@ export default memo(
|
|
|
104
97
|
<g
|
|
105
98
|
key={i}
|
|
106
99
|
onClick={triggerClick}
|
|
107
|
-
onMouseEnter={() => {
|
|
108
|
-
if (isControlChart) {
|
|
109
|
-
setControlChartIndicatorList((v) => {
|
|
110
|
-
return v.map((item) => {
|
|
111
|
-
if (item.tick === data.x) {
|
|
112
|
-
return { ...item, isShow: true };
|
|
113
|
-
} else {
|
|
114
|
-
return item;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
setControlChartTooltipShow(true);
|
|
119
|
-
setControlChartTooltipX(xScaler(x) - indicatorWidth / 2);
|
|
120
|
-
setControlChartTooltipXName(data.x);
|
|
121
|
-
}
|
|
122
|
-
}}
|
|
123
|
-
onMouseLeave={() => {
|
|
124
|
-
if (isControlChart) {
|
|
125
|
-
setControlChartIndicatorList((v) =>
|
|
126
|
-
v.map((item) => ({ ...item, isShow: false }))
|
|
127
|
-
);
|
|
128
|
-
setControlChartTooltipShow(false);
|
|
129
|
-
setControlChartTooltipXName(undefined);
|
|
130
|
-
setControlChartTooltipX(undefined);
|
|
131
|
-
}
|
|
132
|
-
}}
|
|
133
100
|
style={{ cursor: "pointer" }}
|
|
134
101
|
data-data={JSON.stringify(data)}
|
|
135
102
|
>
|
|
@@ -41,7 +41,6 @@ export default memo(
|
|
|
41
41
|
...translateTip,
|
|
42
42
|
x: translateTip.x + position + marginLeft,
|
|
43
43
|
};
|
|
44
|
-
|
|
45
44
|
if (translate3d.x + tipWidth > width) {
|
|
46
45
|
const newPositon = position + marginLeft - tipWidth - translateTip.x;
|
|
47
46
|
translate3d.x = newPositon >= 0 ? newPositon : 0;
|
package/src/hooks/useAxes.js
CHANGED
|
@@ -60,10 +60,12 @@ const scales = {
|
|
|
60
60
|
|
|
61
61
|
export default ({
|
|
62
62
|
axes,
|
|
63
|
-
context: { width, height },
|
|
64
|
-
|
|
65
|
-
control: controlConfig,
|
|
63
|
+
context: { width:chartWidth, height:chartHeight },
|
|
64
|
+
controlInfo, //是否为控制图
|
|
66
65
|
}) => {
|
|
66
|
+
const { isC, cHeight, cWidth, cPercent } = controlInfo;
|
|
67
|
+
const width = chartWidth;
|
|
68
|
+
const height = chartHeight - cHeight;
|
|
67
69
|
const _axes = useMemo(() => {
|
|
68
70
|
const tmp = new Map();
|
|
69
71
|
const xAxisPositions = [];
|
|
@@ -91,9 +93,7 @@ export default ({
|
|
|
91
93
|
bottomClipAxisStep,
|
|
92
94
|
topClipAxisStep,
|
|
93
95
|
clipValue,
|
|
94
|
-
clipPosition
|
|
95
|
-
clipDifferenceValue,
|
|
96
|
-
clipAxisMode,
|
|
96
|
+
clipPosition
|
|
97
97
|
} = item;
|
|
98
98
|
//如果是断轴类型,输出一套完全不同的values
|
|
99
99
|
|
|
@@ -103,7 +103,7 @@ export default ({
|
|
|
103
103
|
* @param {*} width
|
|
104
104
|
* @param {*} height
|
|
105
105
|
* @param {*} paddingOuter
|
|
106
|
-
* @returns {start,end,direction}
|
|
106
|
+
* @returns { start, end, direction }
|
|
107
107
|
*/
|
|
108
108
|
function getChartsConfig(orientation, width, height, paddingOuter) {
|
|
109
109
|
const direction =
|
|
@@ -321,10 +321,8 @@ export default ({
|
|
|
321
321
|
});
|
|
322
322
|
} else {
|
|
323
323
|
//计算真正需要的tickCount,如果domain区间太小,不能完全按照count来,需要减少count数
|
|
324
|
-
const tickCount =
|
|
325
|
-
|
|
326
|
-
const { start, end, direction, _paddingOuter, length } =
|
|
327
|
-
getChartsConfig(orientation, width, height, paddingOuter);
|
|
324
|
+
const tickCount = type == "ordinal" ? _count : getTickCount(domain, _count, decimal);
|
|
325
|
+
const { start, end, direction, _paddingOuter, length } = getChartsConfig(orientation, width, height, paddingOuter);
|
|
328
326
|
|
|
329
327
|
let range =
|
|
330
328
|
direction === "horizontal"
|
|
@@ -336,8 +334,7 @@ export default ({
|
|
|
336
334
|
if (type !== "ordinal" && !isNaN(domain[1]) && !auto) {
|
|
337
335
|
newDomain = getNewDomain(domain, mode, _step);
|
|
338
336
|
}
|
|
339
|
-
|
|
340
|
-
const scaler = scales[type]().domain(newDomain).range(range);
|
|
337
|
+
let scaler = scales[type]().domain(newDomain).range(range);
|
|
341
338
|
|
|
342
339
|
scaler.type = type;
|
|
343
340
|
if (type !== "ordinal") scaler.clamp(true); //scaler.nice().clamp(true)
|
|
@@ -347,9 +344,9 @@ export default ({
|
|
|
347
344
|
? scaler.ticks(tickCount)
|
|
348
345
|
: scaler.domain();
|
|
349
346
|
let _ticks = allTicks;
|
|
350
|
-
|
|
347
|
+
|
|
351
348
|
if (type === "ordinal") {
|
|
352
|
-
if (carousel === false) {
|
|
349
|
+
if (carousel === false || isC) {
|
|
353
350
|
_ticks = getTicksOfAxis(_ticks, +tickCount, showLast);
|
|
354
351
|
}
|
|
355
352
|
} else {
|
|
@@ -381,6 +378,25 @@ export default ({
|
|
|
381
378
|
}
|
|
382
379
|
}
|
|
383
380
|
}
|
|
381
|
+
let step = lengthWithoutPaddingOuter / allTicks.length;
|
|
382
|
+
const controlCfg = {
|
|
383
|
+
controlStep:0,
|
|
384
|
+
controlDragScaler:null
|
|
385
|
+
}
|
|
386
|
+
if(isC){
|
|
387
|
+
controlCfg.controlStep = step / cPercent;
|
|
388
|
+
controlCfg.controlDragScaler = scaler.copy().range([start/cPercent, end/cPercent]);
|
|
389
|
+
const { start:start_, end:end_, direction:direction_, _paddingOuter:outer, length:len } = getChartsConfig(orientation, cWidth, height, paddingOuter);
|
|
390
|
+
let range = direction_ === "horizontal"
|
|
391
|
+
? [start_, end_]
|
|
392
|
+
: direction_ === "vertical"
|
|
393
|
+
? [end_, start_]
|
|
394
|
+
: [0, 0];
|
|
395
|
+
scaler = scales[type]().domain(newDomain).range(range);
|
|
396
|
+
scaler.type = type;
|
|
397
|
+
const controlOuter = len - outer;
|
|
398
|
+
step = controlOuter/allTicks.length;
|
|
399
|
+
}
|
|
384
400
|
tmp.set(axisType, {
|
|
385
401
|
...item,
|
|
386
402
|
count: _count,
|
|
@@ -393,8 +409,10 @@ export default ({
|
|
|
393
409
|
start,
|
|
394
410
|
end,
|
|
395
411
|
lengthWithoutPaddingOuter,
|
|
396
|
-
step
|
|
412
|
+
step,
|
|
413
|
+
...controlCfg,
|
|
397
414
|
allTicks,
|
|
415
|
+
rawTicks: _ticks,
|
|
398
416
|
ticks: _ticks,
|
|
399
417
|
});
|
|
400
418
|
}
|
|
@@ -17,14 +17,14 @@ export default (
|
|
|
17
17
|
axis,
|
|
18
18
|
config,
|
|
19
19
|
isHover,
|
|
20
|
-
|
|
21
|
-
controlConfig = null
|
|
20
|
+
controlInfo
|
|
22
21
|
) => {
|
|
23
22
|
const { show, interval, duration, hover } = config;
|
|
23
|
+
const { isC, cPercent } = controlInfo;
|
|
24
24
|
const time = duration + interval;
|
|
25
25
|
|
|
26
26
|
const {
|
|
27
|
-
tickCount,
|
|
27
|
+
tickCount:count,
|
|
28
28
|
allTicks,
|
|
29
29
|
scaler,
|
|
30
30
|
start,
|
|
@@ -34,12 +34,11 @@ export default (
|
|
|
34
34
|
lengthWithoutPaddingOuter,
|
|
35
35
|
} = axis;
|
|
36
36
|
const tickLength = ticks.length;
|
|
37
|
+
const tickCount = isC?allTicks.length:count;
|
|
37
38
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
: end;
|
|
42
|
-
const controlDragScaler = scaler.copy().range([start, end]);
|
|
39
|
+
const scale = isC?cPercent:1;
|
|
40
|
+
const _start = start/scale;
|
|
41
|
+
const _end = end/scale;
|
|
43
42
|
|
|
44
43
|
const [state, setState] = useState({
|
|
45
44
|
scaler,
|
|
@@ -86,7 +85,7 @@ export default (
|
|
|
86
85
|
setState({
|
|
87
86
|
step,
|
|
88
87
|
ticks: _ticks,
|
|
89
|
-
scaler: scaler.copy().domain(_ticks).range([
|
|
88
|
+
scaler: scaler.copy().domain(_ticks).range([_start, _end]),
|
|
90
89
|
});
|
|
91
90
|
} else {
|
|
92
91
|
animation = animate({
|
|
@@ -107,7 +106,7 @@ export default (
|
|
|
107
106
|
ticks: _ticks,
|
|
108
107
|
scaler: scaler
|
|
109
108
|
.copy()
|
|
110
|
-
.range([
|
|
109
|
+
.range([_start, _end + step])
|
|
111
110
|
.domain(_ticks),
|
|
112
111
|
};
|
|
113
112
|
});
|
|
@@ -119,7 +118,7 @@ export default (
|
|
|
119
118
|
...axis,
|
|
120
119
|
scaler: scaler
|
|
121
120
|
.copy()
|
|
122
|
-
.range([
|
|
121
|
+
.range([_start + step * v, _end + step + step * v]),
|
|
123
122
|
};
|
|
124
123
|
});
|
|
125
124
|
},
|
|
@@ -130,7 +129,7 @@ export default (
|
|
|
130
129
|
return {
|
|
131
130
|
...axis,
|
|
132
131
|
ticks: _ticks,
|
|
133
|
-
scaler: scaler.copy().range([
|
|
132
|
+
scaler: scaler.copy().range([_start, _end]).domain(_ticks),
|
|
134
133
|
};
|
|
135
134
|
});
|
|
136
135
|
},
|
|
@@ -140,7 +139,7 @@ export default (
|
|
|
140
139
|
const _ticks = scaler.type == "linear" ? scaler.domain() : allTicks;
|
|
141
140
|
setState({
|
|
142
141
|
step,
|
|
143
|
-
scaler: scaler.copy().domain(_ticks).range([
|
|
142
|
+
scaler: scaler.copy().domain(_ticks).range([_start, _end]),
|
|
144
143
|
ticks,
|
|
145
144
|
});
|
|
146
145
|
}
|
|
@@ -151,7 +150,7 @@ export default (
|
|
|
151
150
|
tickCount,
|
|
152
151
|
allTicks,
|
|
153
152
|
scaler,
|
|
154
|
-
|
|
153
|
+
_start,
|
|
155
154
|
_end,
|
|
156
155
|
step,
|
|
157
156
|
ticks,
|
|
@@ -163,10 +162,7 @@ export default (
|
|
|
163
162
|
return {
|
|
164
163
|
...axis,
|
|
165
164
|
...state,
|
|
166
|
-
|
|
167
|
-
controlDragScaler,
|
|
168
|
-
controlEnd: _end,
|
|
169
|
-
isControlChart,
|
|
165
|
+
controlEnd: _end
|
|
170
166
|
};
|
|
171
167
|
};
|
|
172
168
|
|