Skip to content

Commit 4e6c005

Browse files
committed
don't hide immediately when over padding
1 parent 8c64cc6 commit 4e6c005

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/components/SChartBar.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const props = withDefaults(defineProps<{
3333
const chartRef = useTemplateRef('chart')
3434
const { width, height } = useElementSize(chartRef)
3535
36+
let tooltipTimeout = 0
37+
3638
// Function to render the chart
3739
function renderChart({
3840
clientWidth,
@@ -255,15 +257,19 @@ function renderChart({
255257
256258
barGroups
257259
.on('pointerenter', (event: PointerEvent, d) => {
260+
window.clearTimeout(tooltipTimeout)
258261
Tooltip
259262
.html(props.tooltipFormat(d, color(d)))
260263
.style('opacity', '1')
261264
updatePos(event)
262265
})
263266
.on('pointermove', updatePos)
264267
.on('pointerleave', () => {
265-
Tooltip
266-
.style('opacity', '0')
268+
window.clearTimeout(tooltipTimeout)
269+
tooltipTimeout = window.setTimeout(() => {
270+
Tooltip
271+
.style('opacity', '0')
272+
}, 400)
267273
})
268274
}
269275

lib/components/SChartPie.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const props = withDefaults(defineProps<{
4242
const chartRef = useTemplateRef('chart')
4343
const { width, height } = useElementSize(chartRef)
4444
45+
let tooltipTimeout = 0
46+
4547
// Function to render the chart
4648
function renderChart({
4749
clientWidth,
@@ -285,15 +287,19 @@ function renderChart({
285287
286288
arcs
287289
.on('pointerenter', (event: PointerEvent, { data: d }) => {
290+
window.clearTimeout(tooltipTimeout)
288291
Tooltip
289292
.html(props.tooltipFormat(d, color(d)))
290293
.style('opacity', '1')
291294
updatePos(event)
292295
})
293296
.on('pointermove', updatePos)
294297
.on('pointerleave', () => {
295-
Tooltip
296-
.style('opacity', '0')
298+
window.clearTimeout(tooltipTimeout)
299+
tooltipTimeout = window.setTimeout(() => {
300+
Tooltip
301+
.style('opacity', '0')
302+
}, 400)
297303
})
298304
}
299305

0 commit comments

Comments
 (0)