@easyv/charts 1.7.37 → 1.8.0
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/Chart.js +2 -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 +2 -2
- package/lib/components/Label.js +2 -2
- package/lib/components/Legend.js +5 -8
- package/lib/components/Lighter.js +2 -2
- package/lib/components/Line.js +2 -2
- package/lib/components/LinearGradient.js +2 -2
- package/lib/components/PieChart.js +26 -4
- package/lib/components/StereoBar.js +2 -2
- package/lib/css/index.module.css +39 -39
- 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 +54 -54
- package/src/components/Background.tsx +61 -61
- package/src/components/Band.tsx +334 -334
- package/src/components/Brush.js +159 -159
- package/src/components/Chart.js +157 -157
- package/src/components/ChartContainer.tsx +71 -71
- package/src/components/ConicalGradient.js +258 -258
- package/src/components/Control.jsx +242 -242
- package/src/components/ExtentData.js +18 -18
- package/src/components/Indicator.js +61 -61
- package/src/components/Label.js +262 -262
- package/src/components/Legend.js +286 -289
- package/src/components/Lighter.jsx +173 -173
- package/src/components/Line.js +153 -153
- package/src/components/LinearGradient.js +29 -29
- package/src/components/PieChart.js +19 -5
- package/src/components/PieTooltip.jsx +160 -160
- package/src/components/SplitText.tsx +70 -70
- package/src/components/StereoBar.tsx +307 -307
- package/src/components/index.js +61 -61
- package/src/context/index.js +2 -2
- package/src/css/index.module.css +39 -39
- 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 +122 -122
- package/src/hooks/index.js +20 -20
- package/src/hooks/useAnimateData.ts +68 -68
- package/src/hooks/useFilterData.js +77 -77
- package/src/hooks/useStackData.js +140 -140
- package/src/hooks/useTooltip.ts +103 -103
- package/src/index.js +6 -6
- package/src/types/index.d.ts +68 -68
- package/src/utils/index.js +812 -812
- package/tsconfig.json +23 -23
package/src/formatter/legend.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import css from '../css/index.module.css';
|
|
2
|
-
import { getFontStyle } from '../utils';
|
|
3
|
-
import { TextOverflow, SplitText } from '../components';
|
|
4
|
-
|
|
5
|
-
export const pieLegendFormatter = (
|
|
6
|
-
series,
|
|
7
|
-
props
|
|
8
|
-
) => {
|
|
9
|
-
const { displayName, data, percent, series: { color: seriesColor, icon="" } } = series,
|
|
10
|
-
{
|
|
11
|
-
name: { show: showName, font: nameFont, textOverflow, speed, maxWidth, translate: { x:nameX, y:nameY } },
|
|
12
|
-
value: {
|
|
13
|
-
show: showValue,
|
|
14
|
-
font: valueFont,
|
|
15
|
-
sameColor: valueSameColor,
|
|
16
|
-
gap: valueGap,
|
|
17
|
-
align: valueAlign,
|
|
18
|
-
translate: {
|
|
19
|
-
x:valueX,
|
|
20
|
-
y:valueY
|
|
21
|
-
},
|
|
22
|
-
splitConfig,
|
|
23
|
-
suffix: {
|
|
24
|
-
show: showSuffix,
|
|
25
|
-
text,
|
|
26
|
-
fontSize,
|
|
27
|
-
translate: { x, y },
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
percent: {
|
|
31
|
-
show: showPercent,
|
|
32
|
-
font: percentFont,
|
|
33
|
-
sameColor: percentSameColor,
|
|
34
|
-
gap: percentGap,
|
|
35
|
-
align: percentAlign,
|
|
36
|
-
translate: {
|
|
37
|
-
x:percentX,
|
|
38
|
-
y:percentY
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
} = props;
|
|
42
|
-
const {
|
|
43
|
-
type: seriesColorType,
|
|
44
|
-
pure,
|
|
45
|
-
linear: { stops },
|
|
46
|
-
} = seriesColor;
|
|
47
|
-
|
|
48
|
-
const _color = seriesColorType == 'pure' ? pure : stops[0].color;
|
|
49
|
-
const textMarginLeft = 5;
|
|
50
|
-
|
|
51
|
-
// 1. 计算每列宽度(加上间距)
|
|
52
|
-
const columns = [];
|
|
53
|
-
if (showName) columns.push(`${props.nameMaxWidth}px`);
|
|
54
|
-
if (showValue) columns.push(`${props.valueMaxWidth + valueGap}px`);
|
|
55
|
-
if (showPercent) columns.push(`${props.percentMaxWidth + percentGap}px`);
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<>
|
|
59
|
-
{icon &&<span style={{ ...icon, marginRight: icon.marginRight, transform:`translate(${nameX}px, ${nameY}px)` }} />}
|
|
60
|
-
<div
|
|
61
|
-
className={
|
|
62
|
-
showName && showValue && showPercent
|
|
63
|
-
? css.showAllStyle
|
|
64
|
-
: css.notShowAllStyle
|
|
65
|
-
}
|
|
66
|
-
style={{
|
|
67
|
-
width:`calc( 100% + ${textMarginLeft+valueGap+percentGap}px )`,
|
|
68
|
-
gridTemplateColumns: columns.join(' ')
|
|
69
|
-
}}
|
|
70
|
-
>
|
|
71
|
-
{showName && (
|
|
72
|
-
<TextOverflow value={displayName} type={textOverflow} speed={speed} style={{
|
|
73
|
-
width:maxWidth, marginLeft: textMarginLeft, ...getFontStyle(nameFont), transform:`translate(${nameX}px, ${nameY}px)`
|
|
74
|
-
}}></TextOverflow>
|
|
75
|
-
)}
|
|
76
|
-
{showValue && (
|
|
77
|
-
<span
|
|
78
|
-
style={{
|
|
79
|
-
whiteSpace:"nowrap",
|
|
80
|
-
...getFontStyle(valueFont),
|
|
81
|
-
marginLeft: valueGap,
|
|
82
|
-
transform:`translate(${valueX}px,${valueY}px)`,
|
|
83
|
-
color: valueSameColor ? _color : valueFont.color,
|
|
84
|
-
alignItems: 'center',
|
|
85
|
-
justifyContent: valueAlign=="left"?"flex-start":valueAlign=="right"?"flex-end":'center',
|
|
86
|
-
textAlign: valueAlign === "left" ? "left" : valueAlign === "right" ? "right" : "center",
|
|
87
|
-
}}
|
|
88
|
-
>
|
|
89
|
-
<span><SplitText value={data.y} config={splitConfig} /></span>
|
|
90
|
-
{showSuffix && (
|
|
91
|
-
<span
|
|
92
|
-
style={{
|
|
93
|
-
whiteSpace:"nowrap",
|
|
94
|
-
fontSize,
|
|
95
|
-
transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
|
|
96
|
-
}}
|
|
97
|
-
>
|
|
98
|
-
{text}
|
|
99
|
-
</span>
|
|
100
|
-
)}
|
|
101
|
-
</span>
|
|
102
|
-
)}
|
|
103
|
-
{showPercent && (
|
|
104
|
-
<span
|
|
105
|
-
style={{
|
|
106
|
-
whiteSpace:"nowrap",
|
|
107
|
-
...getFontStyle(percentFont),
|
|
108
|
-
marginLeft: percentGap,
|
|
109
|
-
transform:`translate(${percentX}px,${percentY}px)`,
|
|
110
|
-
color: percentSameColor ? _color : percentFont.color,
|
|
111
|
-
alignItems: 'center',
|
|
112
|
-
justifyContent: percentAlign=="left"?"flex-start":percentAlign=="right"?"flex-end":'center',
|
|
113
|
-
textAlign: percentAlign === "left" ? "left" : percentAlign === "right" ? "right" : "center",
|
|
114
|
-
}}
|
|
115
|
-
>
|
|
116
|
-
{percent + '%'}
|
|
117
|
-
</span>
|
|
118
|
-
)}
|
|
119
|
-
</div>
|
|
120
|
-
</>
|
|
121
|
-
);
|
|
122
|
-
};
|
|
1
|
+
import css from '../css/index.module.css';
|
|
2
|
+
import { getFontStyle } from '../utils';
|
|
3
|
+
import { TextOverflow, SplitText } from '../components';
|
|
4
|
+
|
|
5
|
+
export const pieLegendFormatter = (
|
|
6
|
+
series,
|
|
7
|
+
props
|
|
8
|
+
) => {
|
|
9
|
+
const { displayName, data, percent, series: { color: seriesColor, icon="" } } = series,
|
|
10
|
+
{
|
|
11
|
+
name: { show: showName, font: nameFont, textOverflow, speed, maxWidth, translate: { x:nameX, y:nameY } },
|
|
12
|
+
value: {
|
|
13
|
+
show: showValue,
|
|
14
|
+
font: valueFont,
|
|
15
|
+
sameColor: valueSameColor,
|
|
16
|
+
gap: valueGap,
|
|
17
|
+
align: valueAlign,
|
|
18
|
+
translate: {
|
|
19
|
+
x:valueX,
|
|
20
|
+
y:valueY
|
|
21
|
+
},
|
|
22
|
+
splitConfig,
|
|
23
|
+
suffix: {
|
|
24
|
+
show: showSuffix,
|
|
25
|
+
text,
|
|
26
|
+
fontSize,
|
|
27
|
+
translate: { x, y },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
percent: {
|
|
31
|
+
show: showPercent,
|
|
32
|
+
font: percentFont,
|
|
33
|
+
sameColor: percentSameColor,
|
|
34
|
+
gap: percentGap,
|
|
35
|
+
align: percentAlign,
|
|
36
|
+
translate: {
|
|
37
|
+
x:percentX,
|
|
38
|
+
y:percentY
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
} = props;
|
|
42
|
+
const {
|
|
43
|
+
type: seriesColorType,
|
|
44
|
+
pure,
|
|
45
|
+
linear: { stops },
|
|
46
|
+
} = seriesColor;
|
|
47
|
+
|
|
48
|
+
const _color = seriesColorType == 'pure' ? pure : stops[0].color;
|
|
49
|
+
const textMarginLeft = 5;
|
|
50
|
+
|
|
51
|
+
// 1. 计算每列宽度(加上间距)
|
|
52
|
+
const columns = [];
|
|
53
|
+
if (showName) columns.push(`${props.nameMaxWidth}px`);
|
|
54
|
+
if (showValue) columns.push(`${props.valueMaxWidth + valueGap}px`);
|
|
55
|
+
if (showPercent) columns.push(`${props.percentMaxWidth + percentGap}px`);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
{icon &&<span style={{ ...icon, marginRight: icon.marginRight, transform:`translate(${nameX}px, ${nameY}px)` }} />}
|
|
60
|
+
<div
|
|
61
|
+
className={
|
|
62
|
+
showName && showValue && showPercent
|
|
63
|
+
? css.showAllStyle
|
|
64
|
+
: css.notShowAllStyle
|
|
65
|
+
}
|
|
66
|
+
style={{
|
|
67
|
+
width:`calc( 100% + ${textMarginLeft+valueGap+percentGap}px )`,
|
|
68
|
+
gridTemplateColumns: columns.join(' ')
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
{showName && (
|
|
72
|
+
<TextOverflow value={displayName} type={textOverflow} speed={speed} style={{
|
|
73
|
+
width:maxWidth, marginLeft: textMarginLeft, ...getFontStyle(nameFont), transform:`translate(${nameX}px, ${nameY}px)`
|
|
74
|
+
}}></TextOverflow>
|
|
75
|
+
)}
|
|
76
|
+
{showValue && (
|
|
77
|
+
<span
|
|
78
|
+
style={{
|
|
79
|
+
whiteSpace:"nowrap",
|
|
80
|
+
...getFontStyle(valueFont),
|
|
81
|
+
marginLeft: valueGap,
|
|
82
|
+
transform:`translate(${valueX}px,${valueY}px)`,
|
|
83
|
+
color: valueSameColor ? _color : valueFont.color,
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
justifyContent: valueAlign=="left"?"flex-start":valueAlign=="right"?"flex-end":'center',
|
|
86
|
+
textAlign: valueAlign === "left" ? "left" : valueAlign === "right" ? "right" : "center",
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<span><SplitText value={data.y} config={splitConfig} /></span>
|
|
90
|
+
{showSuffix && (
|
|
91
|
+
<span
|
|
92
|
+
style={{
|
|
93
|
+
whiteSpace:"nowrap",
|
|
94
|
+
fontSize,
|
|
95
|
+
transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
{text}
|
|
99
|
+
</span>
|
|
100
|
+
)}
|
|
101
|
+
</span>
|
|
102
|
+
)}
|
|
103
|
+
{showPercent && (
|
|
104
|
+
<span
|
|
105
|
+
style={{
|
|
106
|
+
whiteSpace:"nowrap",
|
|
107
|
+
...getFontStyle(percentFont),
|
|
108
|
+
marginLeft: percentGap,
|
|
109
|
+
transform:`translate(${percentX}px,${percentY}px)`,
|
|
110
|
+
color: percentSameColor ? _color : percentFont.color,
|
|
111
|
+
alignItems: 'center',
|
|
112
|
+
justifyContent: percentAlign=="left"?"flex-start":percentAlign=="right"?"flex-end":'center',
|
|
113
|
+
textAlign: percentAlign === "left" ? "left" : percentAlign === "right" ? "right" : "center",
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
{percent + '%'}
|
|
117
|
+
</span>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
};
|
package/src/hooks/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import useFilterData from './useFilterData';
|
|
2
|
-
import useStackData from './useStackData';
|
|
3
|
-
import useAxes from './useAxes';
|
|
4
|
-
import useTooltip from './useTooltip';
|
|
5
|
-
import useAnimateData from './useAnimateData';
|
|
6
|
-
import useCarouselAxisX from './useCarouselAxisX';
|
|
7
|
-
import useExtentData from './useExtentData';
|
|
8
|
-
import { useAiData, useAiDataOfPie } from './useAiData';
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
useFilterData,
|
|
12
|
-
useStackData,
|
|
13
|
-
useAxes,
|
|
14
|
-
useTooltip,
|
|
15
|
-
useAnimateData,
|
|
16
|
-
useCarouselAxisX,
|
|
17
|
-
useExtentData,
|
|
18
|
-
useAiData,
|
|
19
|
-
useAiDataOfPie
|
|
20
|
-
};
|
|
1
|
+
import useFilterData from './useFilterData';
|
|
2
|
+
import useStackData from './useStackData';
|
|
3
|
+
import useAxes from './useAxes';
|
|
4
|
+
import useTooltip from './useTooltip';
|
|
5
|
+
import useAnimateData from './useAnimateData';
|
|
6
|
+
import useCarouselAxisX from './useCarouselAxisX';
|
|
7
|
+
import useExtentData from './useExtentData';
|
|
8
|
+
import { useAiData, useAiDataOfPie } from './useAiData';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
useFilterData,
|
|
12
|
+
useStackData,
|
|
13
|
+
useAxes,
|
|
14
|
+
useTooltip,
|
|
15
|
+
useAnimateData,
|
|
16
|
+
useCarouselAxisX,
|
|
17
|
+
useExtentData,
|
|
18
|
+
useAiData,
|
|
19
|
+
useAiDataOfPie
|
|
20
|
+
};
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { animate, easeIn, easeOut, linear } from 'popmotion';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 图表数据动画
|
|
6
|
-
* @param {Array} data data列表
|
|
7
|
-
* @param {boolean} dataAnimation 是否开启数据增长动画
|
|
8
|
-
* @param {boolean} active 是否处于活跃状态,false为休眠
|
|
9
|
-
* @returns 改变后的数据
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export default (data: DataType[], dataAnimation: DataAnimation, active:boolean) => {
|
|
13
|
-
const [animateData, setAnimateData] = useState<DataType[]>([]);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
let animateRef: any = null;
|
|
16
|
-
if (
|
|
17
|
-
dataAnimation &&
|
|
18
|
-
dataAnimation.show &&
|
|
19
|
-
dataAnimation.duration &&
|
|
20
|
-
data.length &&
|
|
21
|
-
active
|
|
22
|
-
) {
|
|
23
|
-
animateRef = animate({
|
|
24
|
-
autoplay: true,
|
|
25
|
-
repeat: 0,
|
|
26
|
-
from: 0,
|
|
27
|
-
to: 1,
|
|
28
|
-
duration: dataAnimation.duration * 1000,
|
|
29
|
-
ease: linear,
|
|
30
|
-
onUpdate: (v: number) => {
|
|
31
|
-
setAnimateData((oldData: DataType[]) => {
|
|
32
|
-
const oldLength = oldData.length;
|
|
33
|
-
const newLength = data.length;
|
|
34
|
-
if (oldLength >= newLength) {
|
|
35
|
-
return oldData.map(({ y }: DataType, i: number) => {
|
|
36
|
-
const current: DataType = data[i] || { y: 0 };
|
|
37
|
-
const delta: number = current.y - y;
|
|
38
|
-
return {
|
|
39
|
-
...current,
|
|
40
|
-
y: y + delta * v,
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
44
|
-
return data.map((current: DataType, i: number) => {
|
|
45
|
-
const oldCurrent: DataType = oldData[i] || { y: 0 };
|
|
46
|
-
const delta = oldCurrent.y - current.y;
|
|
47
|
-
return {
|
|
48
|
-
...current,
|
|
49
|
-
y:oldCurrent.y + delta * v,
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
onComplete: () => {
|
|
56
|
-
setAnimateData(data);
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
setAnimateData(data);
|
|
61
|
-
}
|
|
62
|
-
return () => {
|
|
63
|
-
animateRef && animateRef.stop();
|
|
64
|
-
};
|
|
65
|
-
}, [data, dataAnimation, active]);
|
|
66
|
-
|
|
67
|
-
return animateData;
|
|
68
|
-
};
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { animate, easeIn, easeOut, linear } from 'popmotion';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 图表数据动画
|
|
6
|
+
* @param {Array} data data列表
|
|
7
|
+
* @param {boolean} dataAnimation 是否开启数据增长动画
|
|
8
|
+
* @param {boolean} active 是否处于活跃状态,false为休眠
|
|
9
|
+
* @returns 改变后的数据
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default (data: DataType[], dataAnimation: DataAnimation, active:boolean) => {
|
|
13
|
+
const [animateData, setAnimateData] = useState<DataType[]>([]);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
let animateRef: any = null;
|
|
16
|
+
if (
|
|
17
|
+
dataAnimation &&
|
|
18
|
+
dataAnimation.show &&
|
|
19
|
+
dataAnimation.duration &&
|
|
20
|
+
data.length &&
|
|
21
|
+
active
|
|
22
|
+
) {
|
|
23
|
+
animateRef = animate({
|
|
24
|
+
autoplay: true,
|
|
25
|
+
repeat: 0,
|
|
26
|
+
from: 0,
|
|
27
|
+
to: 1,
|
|
28
|
+
duration: dataAnimation.duration * 1000,
|
|
29
|
+
ease: linear,
|
|
30
|
+
onUpdate: (v: number) => {
|
|
31
|
+
setAnimateData((oldData: DataType[]) => {
|
|
32
|
+
const oldLength = oldData.length;
|
|
33
|
+
const newLength = data.length;
|
|
34
|
+
if (oldLength >= newLength) {
|
|
35
|
+
return oldData.map(({ y }: DataType, i: number) => {
|
|
36
|
+
const current: DataType = data[i] || { y: 0 };
|
|
37
|
+
const delta: number = current.y - y;
|
|
38
|
+
return {
|
|
39
|
+
...current,
|
|
40
|
+
y: y + delta * v,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
return data.map((current: DataType, i: number) => {
|
|
45
|
+
const oldCurrent: DataType = oldData[i] || { y: 0 };
|
|
46
|
+
const delta = oldCurrent.y - current.y;
|
|
47
|
+
return {
|
|
48
|
+
...current,
|
|
49
|
+
y:oldCurrent.y + delta * v,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
onComplete: () => {
|
|
56
|
+
setAnimateData(data);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
setAnimateData(data);
|
|
61
|
+
}
|
|
62
|
+
return () => {
|
|
63
|
+
animateRef && animateRef.stop();
|
|
64
|
+
};
|
|
65
|
+
}, [data, dataAnimation, active]);
|
|
66
|
+
|
|
67
|
+
return animateData;
|
|
68
|
+
};
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
const getInitialSelected = (series) => {
|
|
4
|
-
const status = new Map();
|
|
5
|
-
for (let [name] of series.entries()) {
|
|
6
|
-
status.set(name, true);
|
|
7
|
-
}
|
|
8
|
-
return status;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const getSelected = (selected, name) => {
|
|
12
|
-
const tmp = new Map();
|
|
13
|
-
selected.forEach((value, key) => {
|
|
14
|
-
if (name == key) {
|
|
15
|
-
tmp.set(key, !value);
|
|
16
|
-
} else {
|
|
17
|
-
tmp.set(key, value);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return tmp;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 图例点击状态管理
|
|
25
|
-
* @param {Array} data 数据
|
|
26
|
-
* @param {Map} series 系列
|
|
27
|
-
* @returns {Array} 返回筛选后的数据和是否选中状态,及控制选中函数
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
export default ({ data, series }) => {
|
|
31
|
-
const [selected, setSelected] = useState(getInitialSelected(series));
|
|
32
|
-
|
|
33
|
-
const _series = useMemo(() => {
|
|
34
|
-
const tmp = new Map();
|
|
35
|
-
series.forEach((currentSeries, key) => {
|
|
36
|
-
const value = selected.get(key);
|
|
37
|
-
tmp.set(key, {
|
|
38
|
-
...currentSeries,
|
|
39
|
-
selected: value,
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
return tmp;
|
|
43
|
-
}, [selected, series]);
|
|
44
|
-
const _data = useMemo(() => {
|
|
45
|
-
return data.filter(({ s="" }) => {
|
|
46
|
-
return s && _series.get(s) && _series.get(s).selected;
|
|
47
|
-
});
|
|
48
|
-
}, [data, _series]);
|
|
49
|
-
|
|
50
|
-
const onClick = useCallback((name) => {
|
|
51
|
-
setSelected((selected) => getSelected(selected, name));
|
|
52
|
-
}, []);
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
const map = getInitialSelected(series);
|
|
56
|
-
for(let [ key ] of map.entries()){
|
|
57
|
-
if(selected.has(key)){
|
|
58
|
-
map.set(key, selected.get(key));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
setSelected(map);
|
|
62
|
-
}, [series]);
|
|
63
|
-
|
|
64
|
-
return [
|
|
65
|
-
{
|
|
66
|
-
series: _series,
|
|
67
|
-
data: _data.map(d=>{
|
|
68
|
-
return {
|
|
69
|
-
...d,
|
|
70
|
-
y:parseFloat(d.y),
|
|
71
|
-
showY:d.y
|
|
72
|
-
}
|
|
73
|
-
}),
|
|
74
|
-
},
|
|
75
|
-
onClick,
|
|
76
|
-
];
|
|
77
|
-
};
|
|
1
|
+
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
const getInitialSelected = (series) => {
|
|
4
|
+
const status = new Map();
|
|
5
|
+
for (let [name] of series.entries()) {
|
|
6
|
+
status.set(name, true);
|
|
7
|
+
}
|
|
8
|
+
return status;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const getSelected = (selected, name) => {
|
|
12
|
+
const tmp = new Map();
|
|
13
|
+
selected.forEach((value, key) => {
|
|
14
|
+
if (name == key) {
|
|
15
|
+
tmp.set(key, !value);
|
|
16
|
+
} else {
|
|
17
|
+
tmp.set(key, value);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return tmp;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 图例点击状态管理
|
|
25
|
+
* @param {Array} data 数据
|
|
26
|
+
* @param {Map} series 系列
|
|
27
|
+
* @returns {Array} 返回筛选后的数据和是否选中状态,及控制选中函数
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export default ({ data, series }) => {
|
|
31
|
+
const [selected, setSelected] = useState(getInitialSelected(series));
|
|
32
|
+
|
|
33
|
+
const _series = useMemo(() => {
|
|
34
|
+
const tmp = new Map();
|
|
35
|
+
series.forEach((currentSeries, key) => {
|
|
36
|
+
const value = selected.get(key);
|
|
37
|
+
tmp.set(key, {
|
|
38
|
+
...currentSeries,
|
|
39
|
+
selected: value,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
return tmp;
|
|
43
|
+
}, [selected, series]);
|
|
44
|
+
const _data = useMemo(() => {
|
|
45
|
+
return data.filter(({ s="" }) => {
|
|
46
|
+
return s && _series.get(s) && _series.get(s).selected;
|
|
47
|
+
});
|
|
48
|
+
}, [data, _series]);
|
|
49
|
+
|
|
50
|
+
const onClick = useCallback((name) => {
|
|
51
|
+
setSelected((selected) => getSelected(selected, name));
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const map = getInitialSelected(series);
|
|
56
|
+
for(let [ key ] of map.entries()){
|
|
57
|
+
if(selected.has(key)){
|
|
58
|
+
map.set(key, selected.get(key));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
setSelected(map);
|
|
62
|
+
}, [series]);
|
|
63
|
+
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
series: _series,
|
|
67
|
+
data: _data.map(d=>{
|
|
68
|
+
return {
|
|
69
|
+
...d,
|
|
70
|
+
y:parseFloat(d.y),
|
|
71
|
+
showY:d.y
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
onClick,
|
|
76
|
+
];
|
|
77
|
+
};
|