Skip to content

Commit 8302e1e

Browse files
authored
Merge pull request #71 from metrico/jacovinus-mutiple-label-tooltip
Multiple labels tooltip feature
2 parents d1e20a4 + 792f3b8 commit 8302e1e

File tree

2 files changed

+179
-88
lines changed

2 files changed

+179
-88
lines changed

Diff for: src/plugins/charts/ChartLabelList.js

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import FindReplaceIcon from "@mui/icons-material/FindReplace";
22
import styled from "@emotion/styled";
33

4-
5-
6-
74
const LabelsContainer = styled("div")`
8-
position:absolute;
9-
display: flex;
5+
position: absolute;
6+
display: flex;
107
flex-wrap: wrap;
118
max-height: calc(100% - 300px);
129
overflow-y: auto;
@@ -23,22 +20,21 @@ const LabelsContainer = styled("div")`
2320

2421
const ChartLabel = styled("div")`
2522
font-size: 12px;
26-
color: #ddd;
23+
color: #aaa;
2724
font-family: sans-serif;
2825
display: flex;
2926
align-items: center;
30-
27+
3128
padding-right: 10px;
3229
cursor: pointer;
33-
opacity: ${(props) => (!props.isVisible ? "1" : ".5")};
30+
opacity: ${(props) => (props.isVisible ? "1" : ".5")};
3431
border-radius: 3px;
35-
height:20px !important;
32+
height: 20px !important;
3633
&:hover {
3734
background: black;
3835
}
3936
`;
4037

41-
4238
const ColorLabel = styled("div")`
4339
height: 4px;
4440
width: 16px;
@@ -48,32 +44,35 @@ const ColorLabel = styled("div")`
4844
`;
4945

5046
export const ChartLabelList = (props) => {
47+
const labelsSelected = JSON.parse(localStorage.getItem("labelsSelected"));
48+
49+
const isLabelsSelected = labelsSelected.length > 0;
5150

5251
const matchHeight = (length) => {
53-
if(length <= 12) {
54-
return 150
52+
if (length <= 12) {
53+
return 150;
5554
} 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;
6160
}
62-
63-
}
61+
};
6462

63+
function setIsVisible(label) {
64+
return labelsSelected?.some((f) => f.id === label.id);
65+
}
6566
const handleLabelClick = (val) => {
66-
val.isVisible = !val.isVisible;
67+
val.isVisible = val.isVisible ? false : true;
6768
props.onLabelClick(props.labels, val);
6869
};
6970
return (
70-
<LabelsContainer
71-
divHeight={matchHeight(props.labels.length)}
72-
>
71+
<LabelsContainer divHeight={matchHeight(props.labels.length)}>
7372
{props.labels.length &&
7473
props.labels.map((val, idx) => (
7574
<ChartLabel
76-
isVisible={val.isVisible}
75+
isVisible={!isLabelsSelected ? true : setIsVisible(val)}
7776
key={idx}
7877
onClick={(e) => handleLabelClick(val)}
7978
>

0 commit comments

Comments
 (0)