From af9e2739acba2dc2e233fca9d9fb7b4883f258fc Mon Sep 17 00:00:00 2001 From: Maarten Date: Tue, 1 Oct 2024 19:49:49 +0200 Subject: [PATCH] Basic tooltips --- src/lib/components/Bubble.svelte | 40 ++++++++++++++++++++++++++++++ src/lib/components/Timeline.svelte | 31 ++++++++++++++++++++--- src/lib/components/Tooltip.svelte | 32 ++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 src/lib/components/Bubble.svelte create mode 100644 src/lib/components/Tooltip.svelte diff --git a/src/lib/components/Bubble.svelte b/src/lib/components/Bubble.svelte new file mode 100644 index 0000000..2d0b906 --- /dev/null +++ b/src/lib/components/Bubble.svelte @@ -0,0 +1,40 @@ + + + + + diff --git a/src/lib/components/Timeline.svelte b/src/lib/components/Timeline.svelte index b690822..a49df3f 100644 --- a/src/lib/components/Timeline.svelte +++ b/src/lib/components/Timeline.svelte @@ -3,6 +3,8 @@ import { extent } from 'd3-array'; import { utcFormat } from 'd3-time-format'; import { fade } from 'svelte/transition'; + import Bubble from '$lib/components/Bubble.svelte'; + import Tooltip from '$lib/components/Tooltip.svelte'; export let cases; @@ -44,6 +46,21 @@ let yScale = scalePoint(actorNations, [height - margins.bottom - margins.top, 0]).padding(1); let colorScale = scaleOrdinal(actorNations, colors); + + let showTooltip = false; + let tooltipContent; + let tooltipX; + let tooltipY; + + function handleMouseOver(event) { + showTooltip = true; + tooltipX = event.clientX; + tooltipY = event.clientY; + tooltipContent = ttContent; + } + function handleMouseOut() { + showTooltip = false; + }
@@ -87,14 +104,19 @@ {#each cases as attrCase} {#if attrCase.show} - + ttContent={`

${attrCase.short_description}

`} + bind:tooltipContent + bind:tooltipX + bind:tooltipY + bind:showTooltip + >
{/if} {/each} @@ -123,6 +145,9 @@ {/if} + {#if showTooltip} + + {/if}
+ \ No newline at end of file