File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ const props = withDefaults(defineProps<{
33
33
const chartRef = useTemplateRef (' chart' )
34
34
const { width, height } = useElementSize (chartRef )
35
35
36
+ let tooltipTimeout = 0
37
+
36
38
// Function to render the chart
37
39
function renderChart({
38
40
clientWidth ,
@@ -255,15 +257,19 @@ function renderChart({
255
257
256
258
barGroups
257
259
.on (' pointerenter' , (event : PointerEvent , d ) => {
260
+ window .clearTimeout (tooltipTimeout )
258
261
Tooltip
259
262
.html (props .tooltipFormat (d , color (d )))
260
263
.style (' opacity' , ' 1' )
261
264
updatePos (event )
262
265
})
263
266
.on (' pointermove' , updatePos )
264
267
.on (' pointerleave' , () => {
265
- Tooltip
266
- .style (' opacity' , ' 0' )
268
+ window .clearTimeout (tooltipTimeout )
269
+ tooltipTimeout = window .setTimeout (() => {
270
+ Tooltip
271
+ .style (' opacity' , ' 0' )
272
+ }, 400 )
267
273
})
268
274
}
269
275
Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ const props = withDefaults(defineProps<{
42
42
const chartRef = useTemplateRef (' chart' )
43
43
const { width, height } = useElementSize (chartRef )
44
44
45
+ let tooltipTimeout = 0
46
+
45
47
// Function to render the chart
46
48
function renderChart({
47
49
clientWidth ,
@@ -285,15 +287,19 @@ function renderChart({
285
287
286
288
arcs
287
289
.on (' pointerenter' , (event : PointerEvent , { data : d }) => {
290
+ window .clearTimeout (tooltipTimeout )
288
291
Tooltip
289
292
.html (props .tooltipFormat (d , color (d )))
290
293
.style (' opacity' , ' 1' )
291
294
updatePos (event )
292
295
})
293
296
.on (' pointermove' , updatePos )
294
297
.on (' pointerleave' , () => {
295
- Tooltip
296
- .style (' opacity' , ' 0' )
298
+ window .clearTimeout (tooltipTimeout )
299
+ tooltipTimeout = window .setTimeout (() => {
300
+ Tooltip
301
+ .style (' opacity' , ' 0' )
302
+ }, 400 )
297
303
})
298
304
}
299
305
You can’t perform that action at this time.
0 commit comments