Skip to content

Commit e07627c

Browse files
committed
fuck safari
1 parent c2c5c98 commit e07627c

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

lib/components/SChartBar.vue

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { useElementSize } from '@vueuse/core'
33
import * as d3 from 'd3'
44
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'
66
77
export type { ChartColor, KV }
88
@@ -33,6 +33,9 @@ const props = withDefaults(defineProps<{
3333
const chartRef = useTemplateRef('chart')
3434
const { width, height } = useElementSize(chartRef)
3535
36+
let hideTimeout: number = 0
37+
let animationFrame: number = 0
38+
3639
// Function to render the chart
3740
function renderChart({
3841
clientWidth,
@@ -224,26 +227,29 @@ function renderChart({
224227
.append('div')
225228
.attr('class', 'tooltip')
226229
227-
if (shouldDisableTransitions()) {
228-
Tooltip
229-
.style('transition', 'none')
230-
}
231-
232230
// Add interactivity
233231
bars
234-
.on('mouseover', (_, d) => {
232+
.on('mouseenter', (_, d) => {
233+
clearTimeout(hideTimeout)
235234
Tooltip
236235
.html(props.tooltipFormat(d, color(d)))
237236
.style('visibility', 'visible')
238237
})
239238
.on('mousemove', (event: PointerEvent) => {
240239
const [x, y] = d3.pointer(event, chartRef.value)
241-
Tooltip
242-
.style('transform', `translate3d(${x + 14}px,${y + 14}px,0)`)
240+
if (!animationFrame) {
241+
animationFrame = requestAnimationFrame(() => {
242+
Tooltip
243+
.style('transform', `translate3d(${x + 14}px,${y + 14}px,0)`)
244+
animationFrame = 0
245+
})
246+
}
243247
})
244248
.on('mouseleave', () => {
245-
Tooltip
246-
.style('visibility', 'hidden')
249+
hideTimeout = setTimeout(() => {
250+
Tooltip
251+
.style('visibility', 'hidden')
252+
}, 750) as unknown as number
247253
})
248254
}
249255
@@ -298,7 +304,7 @@ watch(
298304
top: 0;
299305
left: 0;
300306
padding: 2px 8px;
301-
transition: transform 0.4s ease-out, visibility 0s 0.75s;
307+
transition: transform 0.4s ease-out;
302308
background-color: var(--c-bg-elv-2);
303309
border: 1px solid var(--c-divider);
304310
border-radius: 6px;

lib/components/SChartPie.vue

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { useElementSize } from '@vueuse/core'
33
import * as d3 from 'd3'
44
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'
66
77
export type { ChartColor, KV }
88
@@ -42,6 +42,9 @@ const props = withDefaults(defineProps<{
4242
const chartRef = useTemplateRef('chart')
4343
const { width, height } = useElementSize(chartRef)
4444
45+
let hideTimeout: number = 0
46+
let animationFrame: number = 0
47+
4548
// Function to render the chart
4649
function renderChart({
4750
clientWidth,
@@ -277,26 +280,29 @@ function renderChart({
277280
.append('div')
278281
.attr('class', 'tooltip')
279282
280-
if (shouldDisableTransitions()) {
281-
Tooltip
282-
.style('transition', 'none')
283-
}
284-
285283
// Add interactivity
286284
arcs
287-
.on('mouseover', (_, d) => {
285+
.on('mouseenter', (_, d) => {
286+
clearTimeout(hideTimeout)
288287
Tooltip
289288
.html(props.tooltipFormat(d.data, color(d.data)))
290289
.style('visibility', 'visible')
291290
})
292291
.on('mousemove', (event: PointerEvent) => {
293292
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+
}
296300
})
297301
.on('mouseleave', () => {
298-
Tooltip
299-
.style('visibility', 'hidden')
302+
hideTimeout = setTimeout(() => {
303+
Tooltip
304+
.style('visibility', 'hidden')
305+
}, 750) as unknown as number
300306
})
301307
}
302308
@@ -351,7 +357,7 @@ watch(
351357
top: 0;
352358
left: 0;
353359
padding: 2px 8px;
354-
transition: transform 0.4s ease-out, visibility 0s 0.75s;
360+
transition: transform 0.4s ease-out;
355361
background-color: var(--c-bg-elv-2);
356362
border: 1px solid var(--c-divider);
357363
border-radius: 6px;

lib/support/Chart.ts

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
import FileSaver from 'file-saver'
1010
import html2canvas from 'html2canvas'
1111

12-
export function shouldDisableTransitions(): boolean {
13-
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
14-
}
15-
1612
export const c = {
1713
text1: 'light-dark(#1c2024, #edeef0)',
1814
text2: 'light-dark(#5d616b, #abafb7)',

0 commit comments

Comments
 (0)