Skip to content

Commit df0a68b

Browse files
committed
WIP hovering primary whilst primary is selected causes some primary lines to flicker but not others
1 parent 1c7cf98 commit df0a68b

File tree

3 files changed

+43
-30
lines changed

3 files changed

+43
-30
lines changed

src/lib/components/data-vis/line-chart/Line.svelte

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
lineEnding = null,
3535
yFunction,
3636
dataId,
37+
tier,
3738
// markersDataId,
3839
onClick,
3940
onMouseEnter,
@@ -111,21 +112,24 @@
111112
{#if includeArea}
112113
<path d={areaFunction(dataArray)} fill={areaFillColor}></path>
113114
{/if}
114-
115-
<path
116-
d={lineFunction(dataArray)}
117-
fill="none"
118-
stroke="transparent"
119-
stroke-width="20"
120-
pointer-events="stroke"
121-
></path>
115+
{console.log(tier)}
116+
{#if tier !== "invisibles"}
117+
<path
118+
d={lineFunction(dataArray)}
119+
fill="none"
120+
stroke="invisible"
121+
stroke-width="20"
122+
pointer-events="stroke"
123+
></path>
124+
{/if}
122125
{#if halo}
123126
<path
124127
d={lineFunction(dataArray)}
125128
fill={pathFillColor}
126129
stroke={haloColor}
127130
stroke-width={pathStrokeWidth * 1.2}
128131
stroke-dasharray={pathStrokeDashArray}
132+
pointer-events="none"
129133
></path>
130134
{/if}
131135
<path
@@ -134,6 +138,7 @@
134138
stroke={pathStrokeColor}
135139
stroke-width={pathStrokeWidth}
136140
stroke-dasharray={pathStrokeDashArray}
141+
pointer-events="none"
137142
></path>
138143
139144
<!-- {#if includeMarkers}

src/lib/components/data-vis/line-chart/Lines.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,20 @@
9797
9898
{#each Object.keys(tieredDataObject) as tier}
9999
<g id={tier}>
100+
{console.log(tier)}
100101
<g opacity={globalTierRules[tier].opacity}>
101102
{#each tieredDataObject[tier] as line, i}
102103
{@const lineAttributes = generateLineAttributes(
103104
line,
104105
defaultLineParams,
105106
tier,
106107
)}
107-
<Line {...lineAttributes} />
108+
<Line {...lineAttributes} {tier} />
108109
{/each}
109110
</g>
110111
111112
<g>
112113
{#each tieredDataObject[tier] as line, i}
113-
{#if tier == "hover"}
114-
{console.log(line.areaCode == lineClicked)}
115-
{/if}
116114
{#if (!lineHovered && tier === "primary") || (lineHovered && tier === "hover") || (line.areaCode == lineClicked && ["primary", "hover"].includes(tier))}
117115
{@render categoryLabelSnippet(
118116
line,

src/routes/playground/create-a-reactive-line-chart/local-lib/LineChart.svelte

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,28 @@
6565
lineClicked = dataId;
6666
};
6767
let onMouseEnter = (event, dataArray, dataId) => {
68-
lineHovered = dataId;
68+
if (lineHovered !== dataId) {
69+
lineHovered = dataId;
70+
}
6971
};
70-
let onMouseLeave = () => {
71-
lineHovered = null;
72+
let onMouseLeave = (event, dataArray, dataId) => {
73+
if (lineHovered === dataId) {
74+
lineHovered = null;
75+
}
7276
};
7377
7478
let lineHovered = $state();
7579
let lineClicked = $state();
7680
let labelHovered = $state();
7781
let labelClicked = $state();
78-
7982
let selectedLine = $derived([
8083
lineHovered,
8184
lineClicked,
8285
labelHovered,
8386
labelClicked,
8487
]);
88+
$inspect({ selectedLine });
89+
8590
let nothingSelected = $derived(selectedLine.every((item) => item == null));
8691
let selectedAreaCode = $state("E07000223");
8792
let englandMedian = $state("E07000227");
@@ -140,11 +145,12 @@
140145
141146
let dataArray = $derived(
142147
data.lines.map((el, i) => {
143-
const tiers = selectedLine.includes(el.areaCode)
144-
? ["hover", "secondary"]
148+
const tiers = ["invisibles"];
149+
selectedLine.includes(el.areaCode)
150+
? tiers.push("hover")
145151
: primaryLines.includes(el.areaCode)
146-
? ["primary"]
147-
: ["invisibles", "secondary"];
152+
? tiers.push("primary")
153+
: tiers.push("secondary");
148154
return {
149155
...el,
150156
tiers,
@@ -154,27 +160,27 @@
154160
155161
let tieredLineParams = $derived({
156162
otherTier: {},
157-
invisibles: {
158-
listenForOnHoverEvents: true,
159-
pathStrokeWidth: 1,
160-
},
161163
secondary: {
162-
"pointer-events": "none",
163164
halo: false,
164165
pathStrokeColor: colors.black,
165166
pathStrokeWidth: 1,
166167
opacity: 0.05,
167168
},
168169
primary: {
169170
halo: true,
170-
pathStrokeWidth: nothingSelected ? 5 : 2,
171+
pathStrokeWidth: nothingSelected ? 5 : 8,
171172
pathStrokeColor: colors.darkgrey,
172173
},
173174
hover: {
174175
pathStrokeColor: colors.ochre,
175-
pathStrokeWidth: lineClicked ? 8 : 5,
176+
pathStrokeWidth: 5,
176177
halo: true,
177178
},
179+
invisibles: {
180+
// listenForOnHoverEvents: true, //PASS THESE THROUGH TO LINE
181+
// "pointer-events": "visibleStroke",
182+
// pathStrokeWidth: 5,
183+
},
178184
});
179185
180186
let basicLineParams = {
@@ -186,6 +192,7 @@
186192
onMouseEnter: onMouseEnter,
187193
onMouseLeave: onMouseLeave,
188194
haloColor: chartBackgroundColor,
195+
"pointer-events": "none",
189196
};
190197
191198
let defaultLineParams = Object.fromEntries(
@@ -201,15 +208,16 @@
201208
.filter((el) => {
202209
if (key === "primary") {
203210
return primaryLines.includes(el.areaCode);
204-
} else if (key === "secondary" && showAllData) {
211+
}
212+
if (key === "secondary" && showAllData) {
205213
return true;
206-
} else if (key === "hover") {
214+
}
215+
if (key === "hover") {
207216
return selectedLine.includes(el.areaCode);
208217
}
209218
})
210219
.map((el) => ({
211220
...el,
212-
strokeWidth: "3px",
213221
includeMarkers: key === "primary" ? true : false,
214222
pathStrokeColor: ["primary", "hover"].includes(key)
215223
? getColor(
@@ -234,6 +242,8 @@
234242
},
235243
hover: { opacity: 1 },
236244
});
245+
246+
$inspect({ tieredDataObject });
237247
</script>
238248
239249
<h3>Example Usage</h3>

0 commit comments

Comments
 (0)