Skip to content

Commit 6a1f49b

Browse files
committed
handle Click on lines
1 parent 2d2dba0 commit 6a1f49b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
labelClicked = $bindable(),
1919
labelHovered = $bindable(),
2020
lineHovered = $bindable(),
21+
lineClicked = $bindable(),
2122
chartHeight,
2223
colors,
2324
showAllData,
@@ -60,8 +61,8 @@
6061
);
6162
return {
6263
...merged,
63-
dataId: line.areaCode, // should I just use areaCode in the component itself?
64-
dataArray: line.data, // should I just rename data in the original object so it's not repeated?
64+
dataId: line.areaCode,
65+
dataArray: line.data, // rename in the original to avoid this
6566
};
6667
}
6768
</script>
@@ -109,7 +110,10 @@
109110
110111
<g>
111112
{#each tieredDataObject[tier] as line, i}
112-
{#if (!lineHovered && tier === "primary") || (lineHovered && tier === "hover")}
113+
{#if tier == "hover"}
114+
{console.log(line.areaCode == lineClicked)}
115+
{/if}
116+
{#if (!lineHovered && tier === "primary") || [lineClicked, lineHovered].includes(line.areaCode)}
113117
{@render categoryLabelSnippet(
114118
line,
115119
labelsPlaced.find((el) => el.datum.areaCode === line.areaCode).y,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292
9393
function handleClickOutside(event) {
9494
if (
95-
(labelClicked || lineClicked) &&
96-
!event.target.closest('[id^="label"]')
95+
lineClicked != event.target.parentElement.dataset.id ||
96+
(labelClicked && !event.target.closest('[id^="label"]'))
9797
) {
9898
labelClicked = null;
9999
lineClicked = null;
@@ -175,7 +175,7 @@
175175
},
176176
hover: {
177177
pathStrokeColor: colors.ochre,
178-
pathStrokeWidth: 5,
178+
pathStrokeWidth: lineClicked ? 8 : 5,
179179
halo: true,
180180
},
181181
});
@@ -285,6 +285,7 @@
285285
bind:labelClicked
286286
bind:labelHovered
287287
bind:lineHovered
288+
bind:lineClicked
288289
{chartHeight}
289290
{colorPalette}
290291
{defaultLineParams}

0 commit comments

Comments
 (0)