@easyv/charts 1.10.7 → 1.10.9
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/CartesianChart.js +34 -17
- package/lib/components/Legend.js +6 -6
- package/lib/components/Line.js +5 -5
- package/lib/hooks/useAxes.js +10 -5
- package/lib/hooks/useCarouselAxisX.js +18 -16
- package/package.json +2 -2
- package/src/components/CartesianChart.js +39 -21
- package/src/components/Legend.js +27 -27
- package/src/components/Line.js +61 -38
- package/src/hooks/useAxes.js +18 -8
- package/src/hooks/useCarouselAxisX.js +320 -318
package/src/components/Line.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 折线图
|
|
3
3
|
*/
|
|
4
|
-
import React, { memo, useMemo } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import React, { memo, useMemo } from "react";
|
|
5
|
+
import {
|
|
6
|
+
line as d3Line,
|
|
7
|
+
area as d3Area,
|
|
8
|
+
curveCatmullRom,
|
|
9
|
+
curveMonotoneX,
|
|
10
|
+
} from "d3v7";
|
|
11
|
+
import { getColorList } from "../utils";
|
|
12
|
+
import { Lighter, LinearGradient } from ".";
|
|
8
13
|
|
|
9
14
|
const defined = (d) => d.data.y != null;
|
|
10
|
-
const getLineData = (data, connectNulls) =>{
|
|
11
|
-
return data.flatMap(d=>{
|
|
15
|
+
const getLineData = (data, connectNulls) => {
|
|
16
|
+
return data.flatMap((d) => {
|
|
12
17
|
const y = d.data.y;
|
|
13
|
-
return isNaN(y)
|
|
14
|
-
connectNulls
|
|
15
|
-
[]
|
|
16
|
-
{...d,data:{...d.data,y:null}}
|
|
17
|
-
d
|
|
18
|
+
return isNaN(y)
|
|
19
|
+
? connectNulls
|
|
20
|
+
? []
|
|
21
|
+
: { ...d, data: { ...d.data, y: null } }
|
|
22
|
+
: d;
|
|
18
23
|
});
|
|
19
|
-
}
|
|
20
|
-
|
|
24
|
+
};
|
|
21
25
|
|
|
22
26
|
const Area = ({
|
|
23
27
|
data,
|
|
@@ -30,11 +34,11 @@ const Area = ({
|
|
|
30
34
|
opacity,
|
|
31
35
|
size: { width: patternW, height: patternH },
|
|
32
36
|
curve,
|
|
33
|
-
tension
|
|
37
|
+
tension,
|
|
34
38
|
},
|
|
35
39
|
xScaler,
|
|
36
40
|
yScaler,
|
|
37
|
-
opacity:Areaopacity
|
|
41
|
+
opacity: Areaopacity,
|
|
38
42
|
}) => {
|
|
39
43
|
const [height] = yScaler.range();
|
|
40
44
|
const area = useMemo(() => getColorList(fill), [fill]);
|
|
@@ -43,7 +47,7 @@ const Area = ({
|
|
|
43
47
|
const areaGen = d3Area()
|
|
44
48
|
.x(({ data: { x } }) => xScaler(x))
|
|
45
49
|
.y1(({ data: { y } }) => yScaler(y))
|
|
46
|
-
.y0(({})=>yScaler(0))
|
|
50
|
+
.y0(({}) => yScaler(0))
|
|
47
51
|
.defined(defined);
|
|
48
52
|
curve && areaGen.curve(curveCatmullRom.alpha(tension));
|
|
49
53
|
curve && areaGen.curve(curveMonotoneX);
|
|
@@ -52,11 +56,28 @@ const Area = ({
|
|
|
52
56
|
|
|
53
57
|
return (
|
|
54
58
|
<>
|
|
55
|
-
<path
|
|
59
|
+
<path
|
|
60
|
+
d={areaGen(data)}
|
|
61
|
+
style={{ pointerEvents: "none", opacity: Areaopacity }}
|
|
62
|
+
stroke="none"
|
|
63
|
+
fill={"url(#" + id + ")"}
|
|
64
|
+
/>
|
|
56
65
|
<defs>
|
|
57
|
-
{type && type ==
|
|
58
|
-
<pattern
|
|
59
|
-
|
|
66
|
+
{type && type == "pattern" ? (
|
|
67
|
+
<pattern
|
|
68
|
+
id={id}
|
|
69
|
+
patternUnits="userSpaceOnUse"
|
|
70
|
+
width={patternW}
|
|
71
|
+
height={patternH}
|
|
72
|
+
>
|
|
73
|
+
{url && (
|
|
74
|
+
<image
|
|
75
|
+
opacity={opacity}
|
|
76
|
+
width={patternW}
|
|
77
|
+
height={patternH}
|
|
78
|
+
xlinkHref={window.appConfig.ASSETS_URL + url}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
60
81
|
</pattern>
|
|
61
82
|
) : (
|
|
62
83
|
<LinearGradient id={id} colors={area} rotate={0} />
|
|
@@ -91,32 +112,32 @@ export default memo(
|
|
|
91
112
|
}) => {
|
|
92
113
|
if (!data.length) return null;
|
|
93
114
|
const ticks = xScaler.domain();
|
|
94
|
-
|
|
115
|
+
|
|
95
116
|
const sortData = useMemo(() => {
|
|
96
117
|
const usefulData = data.filter(
|
|
97
|
-
({ data: { x } }) => ticks.indexOf(x) > -1
|
|
118
|
+
({ data: { x } }) => ticks.indexOf(x) > -1,
|
|
98
119
|
);
|
|
99
120
|
return usefulData.sort(
|
|
100
121
|
({ data: { x: a } }, { data: { x: b } }) =>
|
|
101
|
-
ticks.indexOf(a) - ticks.indexOf(b)
|
|
122
|
+
ticks.indexOf(a) - ticks.indexOf(b),
|
|
102
123
|
);
|
|
103
124
|
}, [data, ticks]);
|
|
104
|
-
|
|
125
|
+
|
|
105
126
|
const _data = useMemo(
|
|
106
127
|
() => getLineData(sortData, connectNulls),
|
|
107
|
-
[sortData, connectNulls]
|
|
128
|
+
[sortData, connectNulls],
|
|
108
129
|
);
|
|
109
130
|
const lineGen = useMemo(() => {
|
|
110
|
-
const isVertical = direction ===
|
|
131
|
+
const isVertical = direction === "vertical";
|
|
111
132
|
|
|
112
133
|
let lineGen = (
|
|
113
134
|
isVertical
|
|
114
135
|
? d3Line()
|
|
115
|
-
|
|
116
|
-
|
|
136
|
+
.y(({ data: { x } }) => xScaler(x))
|
|
137
|
+
.x(({ data: { y } }) => yScaler(y))
|
|
117
138
|
: d3Line()
|
|
118
|
-
|
|
119
|
-
|
|
139
|
+
.x(({ data: { x } }) => xScaler(x))
|
|
140
|
+
.y(({ data: { y } }) => yScaler(y))
|
|
120
141
|
).defined(defined);
|
|
121
142
|
curve && lineGen.curve(curveCatmullRom.alpha(tension));
|
|
122
143
|
curve && lineGen.curve(curveMonotoneX);
|
|
@@ -128,29 +149,31 @@ export default memo(
|
|
|
128
149
|
const show = lineShadow && lineShadow.show;
|
|
129
150
|
const shadow = lineShadow && lineShadow.shadow;
|
|
130
151
|
return (
|
|
131
|
-
<g className=
|
|
152
|
+
<g className="__easyv-line">
|
|
132
153
|
<path
|
|
133
154
|
d={path}
|
|
134
155
|
stroke={stroke}
|
|
135
156
|
style={{
|
|
136
|
-
filter:show
|
|
137
|
-
|
|
157
|
+
filter: show
|
|
158
|
+
? `drop-shadow(${shadow.hShadow}px ${shadow.vShadow}px ${shadow.blur}px ${shadow.color})`
|
|
159
|
+
: "none",
|
|
160
|
+
pointerEvents: "none",
|
|
138
161
|
}}
|
|
139
|
-
fill=
|
|
140
|
-
strokeDasharray={lineType ===
|
|
162
|
+
fill="none"
|
|
163
|
+
strokeDasharray={lineType === "dash" ? "3 3" : null}
|
|
141
164
|
strokeWidth={lineWidth}
|
|
142
165
|
/>
|
|
143
|
-
{type ==
|
|
166
|
+
{type == "area" && (
|
|
144
167
|
<Area
|
|
145
168
|
data={_data}
|
|
146
169
|
config={{ ...area, curve, tension }}
|
|
147
170
|
xScaler={xScaler}
|
|
148
171
|
yScaler={yScaler}
|
|
149
|
-
opacity={areaColor?areaColor.linear.opacity:1}
|
|
172
|
+
opacity={areaColor ? areaColor.linear.opacity : 1}
|
|
150
173
|
/>
|
|
151
174
|
)}
|
|
152
175
|
{showLighter && <Lighter path={path} config={lighter} />}
|
|
153
176
|
</g>
|
|
154
177
|
);
|
|
155
|
-
}
|
|
178
|
+
},
|
|
156
179
|
);
|
package/src/hooks/useAxes.js
CHANGED
|
@@ -372,8 +372,12 @@ export default ({
|
|
|
372
372
|
clipAxisRange,
|
|
373
373
|
lengthWithoutPaddingOuter,
|
|
374
374
|
step: [
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
clipAxisAllTicks[0].length > 0
|
|
376
|
+
? lengthWithoutPaddingOuter / clipAxisAllTicks[0].length
|
|
377
|
+
: 0,
|
|
378
|
+
clipAxisAllTicks[1].length > 0
|
|
379
|
+
? lengthWithoutPaddingOuter / clipAxisAllTicks[1].length
|
|
380
|
+
: 0,
|
|
377
381
|
],
|
|
378
382
|
allTicks: clipAxisAllTicks,
|
|
379
383
|
ticks: clipAxisTicks,
|
|
@@ -454,16 +458,22 @@ export default ({
|
|
|
454
458
|
// }
|
|
455
459
|
// }
|
|
456
460
|
// }
|
|
457
|
-
|
|
461
|
+
const tickLen = allTicks.length;
|
|
462
|
+
let step =
|
|
463
|
+
tickLen > 0 ? lengthWithoutPaddingOuter / tickLen : 0;
|
|
458
464
|
const controlCfg = {
|
|
459
465
|
controlStep: 0,
|
|
460
466
|
controlDragScaler: null,
|
|
461
467
|
};
|
|
462
468
|
if (isC) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
.
|
|
466
|
-
|
|
469
|
+
if (tickLen > 0 && cPercent > 0) {
|
|
470
|
+
controlCfg.controlStep = step / cPercent;
|
|
471
|
+
controlCfg.controlDragScaler = scaler
|
|
472
|
+
.copy()
|
|
473
|
+
.range([start / cPercent, end / cPercent]);
|
|
474
|
+
} else {
|
|
475
|
+
controlCfg.controlDragScaler = scaler.copy();
|
|
476
|
+
}
|
|
467
477
|
const {
|
|
468
478
|
start: start_,
|
|
469
479
|
end: end_,
|
|
@@ -480,7 +490,7 @@ export default ({
|
|
|
480
490
|
scaler = scales[type]().domain(newDomain).range(range);
|
|
481
491
|
scaler.type = type;
|
|
482
492
|
const controlOuter = len - outer;
|
|
483
|
-
step = controlOuter /
|
|
493
|
+
step = tickLen > 0 ? controlOuter / tickLen : 0;
|
|
484
494
|
}
|
|
485
495
|
tmp.set(axisType, {
|
|
486
496
|
...item,
|