|
2 | 2 | import { useElementSize } from '@vueuse/core'
|
3 | 3 | import * as d3 from 'd3'
|
4 | 4 | import { useTemplateRef, watch } from 'vue'
|
5 |
| -import { type ChartColor, type KV, c, scheme, shouldDisableTransitions } from '../support/Chart' |
| 5 | +import { type ChartColor, type KV, c, scheme } from '../support/Chart' |
6 | 6 |
|
7 | 7 | export type { ChartColor, KV }
|
8 | 8 |
|
@@ -42,6 +42,9 @@ const props = withDefaults(defineProps<{
|
42 | 42 | const chartRef = useTemplateRef('chart')
|
43 | 43 | const { width, height } = useElementSize(chartRef)
|
44 | 44 |
|
| 45 | +let hideTimeout: number = 0 |
| 46 | +let animationFrame: number = 0 |
| 47 | +
|
45 | 48 | // Function to render the chart
|
46 | 49 | function renderChart({
|
47 | 50 | clientWidth,
|
@@ -277,26 +280,29 @@ function renderChart({
|
277 | 280 | .append('div')
|
278 | 281 | .attr('class', 'tooltip')
|
279 | 282 |
|
280 |
| - if (shouldDisableTransitions()) { |
281 |
| - Tooltip |
282 |
| - .style('transition', 'none') |
283 |
| - } |
284 |
| -
|
285 | 283 | // Add interactivity
|
286 | 284 | arcs
|
287 |
| - .on('mouseover', (_, d) => { |
| 285 | + .on('mouseenter', (_, d) => { |
| 286 | + clearTimeout(hideTimeout) |
288 | 287 | Tooltip
|
289 | 288 | .html(props.tooltipFormat(d.data, color(d.data)))
|
290 | 289 | .style('visibility', 'visible')
|
291 | 290 | })
|
292 | 291 | .on('mousemove', (event: PointerEvent) => {
|
293 | 292 | const [x, y] = d3.pointer(event, chartRef.value)
|
294 |
| - Tooltip |
295 |
| - .style('transform', `translate3d(${x + 14}px,${y + 14}px,0)`) |
| 293 | + if (!animationFrame) { |
| 294 | + animationFrame = requestAnimationFrame(() => { |
| 295 | + Tooltip |
| 296 | + .style('transform', `translate3d(${x + 14}px,${y + 14}px,0)`) |
| 297 | + animationFrame = 0 |
| 298 | + }) |
| 299 | + } |
296 | 300 | })
|
297 | 301 | .on('mouseleave', () => {
|
298 |
| - Tooltip |
299 |
| - .style('visibility', 'hidden') |
| 302 | + hideTimeout = setTimeout(() => { |
| 303 | + Tooltip |
| 304 | + .style('visibility', 'hidden') |
| 305 | + }, 750) as unknown as number |
300 | 306 | })
|
301 | 307 | }
|
302 | 308 |
|
@@ -351,7 +357,7 @@ watch(
|
351 | 357 | top: 0;
|
352 | 358 | left: 0;
|
353 | 359 | padding: 2px 8px;
|
354 |
| - transition: transform 0.4s ease-out, visibility 0s 0.75s; |
| 360 | + transition: transform 0.4s ease-out; |
355 | 361 | background-color: var(--c-bg-elv-2);
|
356 | 362 | border: 1px solid var(--c-divider);
|
357 | 363 | border-radius: 6px;
|
|
0 commit comments