Skip to content

Commit 2ee5a45

Browse files
committed
all lines now have invisible line to handle interaction, invisibles tier removed
1 parent 50b79c6 commit 2ee5a45

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
onMouseEnter,
4141
onMouseLeave,
4242
halo,
43-
haloColor = "#d1aad1",
43+
chartBackgroundColor,
44+
invisibleStrokeWidth,
45+
interactive,
4446
// onClickMarker,
4547
// onMouseEnterMarker,
4648
// onMouseLeaveMarker,
@@ -113,20 +115,18 @@
113115
<path d={areaFunction(dataArray)} fill={areaFillColor}></path>
114116
{/if}
115117
{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}
118+
<path
119+
d={lineFunction(dataArray)}
120+
fill="none"
121+
stroke="invisible"
122+
stroke-width={invisibleStrokeWidth}
123+
pointer-events={interactive ? "stroke" : "none"}
124+
></path>
125125
{#if halo}
126126
<path
127127
d={lineFunction(dataArray)}
128128
fill={pathFillColor}
129-
stroke={haloColor}
129+
stroke={chartBackgroundColor}
130130
stroke-width={pathStrokeWidth * 1.2}
131131
stroke-dasharray={pathStrokeDashArray}
132132
pointer-events="none"

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
lineHovered = $bindable(),
2121
lineClicked = $bindable(),
2222
chartHeight,
23-
colors,
24-
showAllData,
2523
defaultLineParams,
2624
globalTierRules,
2725
chartBackgroundColor,
@@ -114,7 +112,7 @@
114112
defaultLineParams,
115113
tier,
116114
)}
117-
<Line {...lineAttributes} {tier} />
115+
<Line {...lineAttributes} {tier} {chartBackgroundColor} />
118116
{/each}
119117
</g>
120118

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
let englandMedian = $state("E06000040");
9393
let similarAreas = $state("E07000224");
9494
95+
let interactiveLines = $state(["primary", "secondary"]);
96+
9597
function handleClickOutside(event) {
9698
if (
9799
lineClicked != event.target.parentElement.dataset.id ||
@@ -145,7 +147,7 @@
145147
146148
let dataArray = $derived(
147149
data.lines.map((el, i) => {
148-
const tiers = ["invisibles"];
150+
const tiers = [];
149151
el.areaCode == lineClicked
150152
? tiers.push("clicked")
151153
: el.areaCode == lineHovered
@@ -167,27 +169,25 @@
167169
pathStrokeColor: colors.black,
168170
pathStrokeWidth: 1,
169171
opacity: 0.05,
172+
interactive: interactiveLines.includes("secondary"),
170173
},
171174
primary: {
172175
halo: true,
173176
pathStrokeWidth: 5,
174177
pathStrokeColor: colors.darkgrey,
178+
interactive: interactiveLines.includes("primary"),
175179
},
176180
clicked: {
177181
pathStrokeColor: colors.ochre,
178182
pathStrokeWidth: 7,
179183
halo: true,
184+
interactive: true,
180185
},
181186
hover: {
182187
pathStrokeColor: colors.ochre,
183188
pathStrokeWidth: 5,
184189
halo: true,
185-
},
186-
187-
invisibles: {
188-
// listenForOnHoverEvents: true, //PASS THESE THROUGH TO LINE
189-
// "pointer-events": "visibleStroke",
190-
// pathStrokeWidth: 5,
190+
interactive: true,
191191
},
192192
});
193193
@@ -200,7 +200,7 @@
200200
onMouseEnter: onMouseEnter,
201201
onMouseLeave: onMouseLeave,
202202
haloColor: chartBackgroundColor,
203-
"pointer-events": "none",
203+
invisibleStrokeWidth: 20,
204204
});
205205
206206
let defaultLineParams = $derived(
@@ -219,7 +219,11 @@
219219
if (key === "primary") {
220220
return primaryLines.includes(el.areaCode);
221221
}
222-
if (key === "secondary" && showAllData) {
222+
if (
223+
key === "secondary" &&
224+
showAllData &&
225+
!primaryLines.includes(el.areaCode)
226+
) {
223227
return true;
224228
}
225229
if (key === "hover") {
@@ -246,7 +250,6 @@
246250
247251
let globalTierRules = $derived({
248252
otherTier: {},
249-
invisibles: { opacity: 0 },
250253
secondary: {
251254
opacity: nothingSelected ? 1 : 0.5,
252255
},

0 commit comments

Comments
 (0)