|
5 | 5 | --> |
6 | 6 | <script lang="ts"> |
7 | 7 | import { stores } from "../../../lib/stores/Stores"; |
| 8 | + import { onDestroy } from "svelte"; |
8 | 9 |
|
9 | 10 | export let fingerprint: number[]; |
10 | 11 | export let title: string; |
|
13 | 14 | // Tooltip state |
14 | 15 | let tooltipVisible = false; |
15 | 16 | let tooltipLabel = ""; |
| 17 | + let tooltipIndex = 0; |
16 | 18 | let tooltipValue = 0; |
17 | 19 | let containerElement: HTMLDivElement; |
18 | 20 | let tooltipX = 0; |
19 | 21 | let tooltipXOffset = -80; |
20 | 22 | let tooltipY = 0; |
21 | 23 | let tooltipYOffset = -60; |
| 24 | + let tooltipInterval: NodeJS.Timeout | null = null; |
22 | 25 |
|
23 | 26 | // Function to convert value (0-1) to viridis-like color |
24 | 27 | const getViridisColor = (value: number): string => { |
|
56 | 59 | // Tooltip handlers |
57 | 60 | const showTooltip = (index: number, value: number) => { |
58 | 61 | tooltipLabel = filterLabels[index] || `Cell ${index}`; |
| 62 | + tooltipIndex = index; |
59 | 63 | tooltipValue = value; |
60 | 64 | |
61 | 65 | // Calculate fixed position relative to the visualization container |
|
66 | 70 | } |
67 | 71 | |
68 | 72 | tooltipVisible = true; |
| 73 | + |
| 74 | + // Start polling the value every 200ms |
| 75 | + if (tooltipInterval) { |
| 76 | + clearInterval(tooltipInterval); |
| 77 | + } |
| 78 | + tooltipInterval = setInterval(() => { |
| 79 | + if (tooltipVisible && fingerprint[tooltipIndex] !== undefined) { |
| 80 | + tooltipValue = fingerprint[tooltipIndex]; |
| 81 | + } |
| 82 | + }, 200); |
69 | 83 | }; |
70 | 84 |
|
71 | 85 | const hideTooltip = () => { |
72 | 86 | tooltipVisible = false; |
| 87 | + |
| 88 | + // Clear the polling interval |
| 89 | + if (tooltipInterval) { |
| 90 | + clearInterval(tooltipInterval); |
| 91 | + tooltipInterval = null; |
| 92 | + } |
73 | 93 | }; |
| 94 | +
|
| 95 | + // Cleanup on component destroy |
| 96 | + onDestroy(() => { |
| 97 | + if (tooltipInterval) { |
| 98 | + clearInterval(tooltipInterval); |
| 99 | + } |
| 100 | + }); |
74 | 101 | </script> |
75 | 102 |
|
76 | 103 | <div class="flex flex-col font-sans w-full h-full" bind:this={containerElement}> |
|
0 commit comments