|
4 | 4 | SPDX-License-Identifier: MIT |
5 | 5 | --> |
6 | 6 | <script lang="ts"> |
7 | | - import { stores } from "../../../lib/stores/Stores"; |
8 | | - import { onDestroy } from "svelte"; |
| 7 | + import { onDestroy } from 'svelte'; |
9 | 8 |
|
10 | 9 | export let fingerprint: number[]; |
11 | 10 | export let title: string; |
12 | 11 | export let filterLabels: string[]; |
13 | 12 |
|
14 | 13 | // Tooltip state |
15 | 14 | let tooltipVisible = false; |
16 | | - let tooltipLabel = ""; |
| 15 | + let tooltipLabel = ''; |
17 | 16 | let tooltipIndex = 0; |
18 | 17 | let tooltipValue = 0; |
19 | 18 | let containerElement: HTMLDivElement; |
20 | 19 | let tooltipX = 0; |
21 | 20 | let tooltipXOffset = -80; |
22 | 21 | let tooltipY = 0; |
23 | | - let tooltipYOffset = -60; |
| 22 | + let tooltipYOffset = -85; |
24 | 23 | let tooltipInterval: NodeJS.Timeout | null = null; |
25 | 24 |
|
26 | 25 | // Function to convert value (0-1) to viridis-like color |
|
61 | 60 | tooltipLabel = filterLabels[index] || `Cell ${index}`; |
62 | 61 | tooltipIndex = index; |
63 | 62 | tooltipValue = value; |
64 | | - |
| 63 | +
|
65 | 64 | // Calculate fixed position relative to the visualization container |
66 | 65 | if (containerElement) { |
67 | 66 | const rect = containerElement.getBoundingClientRect(); |
68 | 67 | tooltipX = rect.right + tooltipXOffset; // Position near the right edge of the container |
69 | 68 | tooltipY = rect.top + tooltipYOffset; // Position near the top of the container |
70 | 69 | } |
71 | | - |
| 70 | +
|
72 | 71 | tooltipVisible = true; |
73 | | - |
| 72 | +
|
74 | 73 | // Start polling the value every 200ms |
75 | 74 | if (tooltipInterval) { |
76 | 75 | clearInterval(tooltipInterval); |
|
84 | 83 |
|
85 | 84 | const hideTooltip = () => { |
86 | 85 | tooltipVisible = false; |
87 | | - |
| 86 | +
|
88 | 87 | // Clear the polling interval |
89 | 88 | if (tooltipInterval) { |
90 | 89 | clearInterval(tooltipInterval); |
|
103 | 102 | <div class="flex flex-col font-sans w-full h-full" bind:this={containerElement}> |
104 | 103 | <div class="flex flex-col border border-gray-300 flex-1"> |
105 | 104 | {#each fingerprint as value, index} |
106 | | - <div |
107 | | - class="border-b border-white border-opacity-10 transition-opacity duration-200 hover:opacity-80 cursor-pointer last:border-b-0 flex-1" |
108 | | - style="background-color: {getViridisColor(value)};" |
109 | | - on:mouseenter={() => showTooltip(index, value)} |
110 | | - on:mouseleave={hideTooltip} |
111 | | - on:click|stopPropagation |
112 | | - role="button" |
113 | | - tabindex="0"/> |
| 105 | + <div |
| 106 | + class="border-b border-white border-opacity-10 transition-opacity duration-200 hover:opacity-80 cursor-pointer last:border-b-0 flex-1" |
| 107 | + style="background-color: {getViridisColor(value)};" |
| 108 | + on:mouseenter={() => showTooltip(index, value)} |
| 109 | + on:mouseleave={hideTooltip} |
| 110 | + on:click|stopPropagation |
| 111 | + role="button" |
| 112 | + tabindex="0" /> |
114 | 113 | {/each} |
115 | 114 | </div> |
116 | 115 | </div> |
117 | 116 |
|
118 | 117 | <!-- Fixed tooltip positioned globally but relative to the visualization --> |
119 | 118 | {#if tooltipVisible} |
120 | | - <div |
| 119 | + <div |
121 | 120 | class="fixed bg-white shadow-md text-primarytext text-sm px-3 py-2 rounded z-50 pointer-events-none whitespace-nowrap" |
122 | 121 | style="left: {tooltipX}px; top: {tooltipY}px;"> |
| 122 | + <div class="font-semibold text-md">{title}</div> |
123 | 123 | <div class="font-semibold">{tooltipLabel}</div> |
124 | 124 | <div>Value: {tooltipValue.toFixed(3)}</div> |
125 | 125 | </div> |
|
0 commit comments