1
1
import FindReplaceIcon from "@mui/icons-material/FindReplace" ;
2
2
import styled from "@emotion/styled" ;
3
3
4
-
5
-
6
-
7
4
const LabelsContainer = styled ( "div" ) `
8
- position:absolute;
9
- display: flex;
5
+ position: absolute;
6
+ display: flex;
10
7
flex-wrap: wrap;
11
8
max-height: calc(100% - 300px);
12
9
overflow-y: auto;
@@ -23,22 +20,21 @@ const LabelsContainer = styled("div")`
23
20
24
21
const ChartLabel = styled ( "div" ) `
25
22
font-size: 12px;
26
- color: #ddd ;
23
+ color: #aaa ;
27
24
font-family: sans-serif;
28
25
display: flex;
29
26
align-items: center;
30
-
27
+
31
28
padding-right: 10px;
32
29
cursor: pointer;
33
- opacity: ${ ( props ) => ( ! props . isVisible ? "1" : ".5" ) } ;
30
+ opacity: ${ ( props ) => ( props . isVisible ? "1" : ".5" ) } ;
34
31
border-radius: 3px;
35
- height:20px !important;
32
+ height: 20px !important;
36
33
&:hover {
37
34
background: black;
38
35
}
39
36
` ;
40
37
41
-
42
38
const ColorLabel = styled ( "div" ) `
43
39
height: 4px;
44
40
width: 16px;
@@ -48,32 +44,35 @@ const ColorLabel = styled("div")`
48
44
` ;
49
45
50
46
export const ChartLabelList = ( props ) => {
47
+ const labelsSelected = JSON . parse ( localStorage . getItem ( "labelsSelected" ) ) ;
48
+
49
+ const isLabelsSelected = labelsSelected . length > 0 ;
51
50
52
51
const matchHeight = ( length ) => {
53
- if ( length <= 12 ) {
54
- return 150
52
+ if ( length <= 12 ) {
53
+ return 150 ;
55
54
} else if ( length <= 20 ) {
56
- return 250
57
- } else if ( length <= 15 ) {
58
- return 175
59
- } else if ( length > 0 ) {
60
- return 450
55
+ return 250 ;
56
+ } else if ( length <= 15 ) {
57
+ return 175 ;
58
+ } else if ( length > 0 ) {
59
+ return 450 ;
61
60
}
62
-
63
- }
61
+ } ;
64
62
63
+ function setIsVisible ( label ) {
64
+ return labelsSelected ?. some ( ( f ) => f . id === label . id ) ;
65
+ }
65
66
const handleLabelClick = ( val ) => {
66
- val . isVisible = ! val . isVisible ;
67
+ val . isVisible = val . isVisible ? false : true ;
67
68
props . onLabelClick ( props . labels , val ) ;
68
69
} ;
69
70
return (
70
- < LabelsContainer
71
- divHeight = { matchHeight ( props . labels . length ) }
72
- >
71
+ < LabelsContainer divHeight = { matchHeight ( props . labels . length ) } >
73
72
{ props . labels . length &&
74
73
props . labels . map ( ( val , idx ) => (
75
74
< ChartLabel
76
- isVisible = { val . isVisible }
75
+ isVisible = { ! isLabelsSelected ? true : setIsVisible ( val ) }
77
76
key = { idx }
78
77
onClick = { ( e ) => handleLabelClick ( val ) }
79
78
>
0 commit comments