Skip to content

Commit fce65f5

Browse files
committed
Make tooltip for fingerprint feel better by using polling intervals
1 parent e55d644 commit fce65f5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/components/ui/recording/Fingerprint.svelte

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
-->
66
<script lang="ts">
77
import { stores } from "../../../lib/stores/Stores";
8+
import { onDestroy } from "svelte";
89
910
export let fingerprint: number[];
1011
export let title: string;
@@ -13,12 +14,14 @@
1314
// Tooltip state
1415
let tooltipVisible = false;
1516
let tooltipLabel = "";
17+
let tooltipIndex = 0;
1618
let tooltipValue = 0;
1719
let containerElement: HTMLDivElement;
1820
let tooltipX = 0;
1921
let tooltipXOffset = -80;
2022
let tooltipY = 0;
2123
let tooltipYOffset = -60;
24+
let tooltipInterval: NodeJS.Timeout | null = null;
2225
2326
// Function to convert value (0-1) to viridis-like color
2427
const getViridisColor = (value: number): string => {
@@ -56,6 +59,7 @@
5659
// Tooltip handlers
5760
const showTooltip = (index: number, value: number) => {
5861
tooltipLabel = filterLabels[index] || `Cell ${index}`;
62+
tooltipIndex = index;
5963
tooltipValue = value;
6064
6165
// Calculate fixed position relative to the visualization container
@@ -66,11 +70,34 @@
6670
}
6771
6872
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);
6983
};
7084
7185
const hideTooltip = () => {
7286
tooltipVisible = false;
87+
88+
// Clear the polling interval
89+
if (tooltipInterval) {
90+
clearInterval(tooltipInterval);
91+
tooltipInterval = null;
92+
}
7393
};
94+
95+
// Cleanup on component destroy
96+
onDestroy(() => {
97+
if (tooltipInterval) {
98+
clearInterval(tooltipInterval);
99+
}
100+
});
74101
</script>
75102

76103
<div class="flex flex-col font-sans w-full h-full" bind:this={containerElement}>

0 commit comments

Comments
 (0)