From f042e36ad9e136d60dc06b3074c6ac6f8e00541c Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 20 Aug 2024 17:58:06 +0800 Subject: [PATCH] problem: merits chart slice remains active after mouseout resolve https://github.com/nostrocket/hypergolic/issues/115 --- src/components/Pie.svelte | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/Pie.svelte b/src/components/Pie.svelte index afef815..71f88a6 100644 --- a/src/components/Pie.svelte +++ b/src/components/Pie.svelte @@ -127,14 +127,26 @@ }); } - $: { - if (chartInstance && hoveredPubkey !== null) { - const index = data.findIndex((item) => item.pubkey === hoveredPubkey); - if (index !== -1) { - chartInstance.toggleDataPointSelection(index); + let prehoverdPubkey: string | null = null; + + $: if (chartInstance) { + if (hoveredPubkey !== null) { + selectSlice(hoveredPubkey); + prehoverdPubkey = hoveredPubkey; + } else { + if (prehoverdPubkey) { + selectSlice(prehoverdPubkey); + prehoverdPubkey = null; } } } + + function selectSlice(pubkey: string) { + const index = data.findIndex((item) => item.pubkey === pubkey); + if (index !== -1) { + chartInstance.toggleDataPointSelection(index); + } + }