Skip to content

Commit c2c5c98

Browse files
committed
fuck safari
1 parent 39676dc commit c2c5c98

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

lib/components/SChartBar.vue

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import { useElementSize } from '@vueuse/core'
33
import * as d3 from 'd3'
4-
import { ref, watch } from 'vue'
5-
import { type ChartColor, type KV, c, scheme } from '../support/Chart'
4+
import { useTemplateRef, watch } from 'vue'
5+
import { type ChartColor, type KV, c, scheme, shouldDisableTransitions } from '../support/Chart'
66
77
export type { ChartColor, KV }
88
@@ -30,7 +30,7 @@ const props = withDefaults(defineProps<{
3030
tooltipFormat: (d: KV) => `${d.key} – ${d.value}`
3131
})
3232
33-
const chartRef = ref<HTMLElement>()
33+
const chartRef = useTemplateRef('chart')
3434
const { width, height } = useElementSize(chartRef)
3535
3636
// Function to render the chart
@@ -218,12 +218,17 @@ function renderChart({
218218
}
219219
220220
if (props.tooltip) {
221-
// Create a tooltip
221+
// Create a tooltip
222222
const Tooltip = d3
223223
.select(chartRef.value)
224224
.append('div')
225225
.attr('class', 'tooltip')
226226
227+
if (shouldDisableTransitions()) {
228+
Tooltip
229+
.style('transition', 'none')
230+
}
231+
227232
// Add interactivity
228233
bars
229234
.on('mouseover', (_, d) => {
@@ -275,7 +280,7 @@ watch(
275280
</script>
276281

277282
<template>
278-
<div ref="chartRef" class="SChartBar" :class="mode" />
283+
<div ref="chart" class="SChartBar" />
279284
</template>
280285

281286
<style scoped lang="postcss">

lib/components/SChartPie.vue

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import { useElementSize } from '@vueuse/core'
33
import * as d3 from 'd3'
4-
import { ref, watch } from 'vue'
5-
import { type ChartColor, type KV, c, scheme } from '../support/Chart'
4+
import { useTemplateRef, watch } from 'vue'
5+
import { type ChartColor, type KV, c, scheme, shouldDisableTransitions } from '../support/Chart'
66
77
export type { ChartColor, KV }
88
@@ -39,7 +39,7 @@ const props = withDefaults(defineProps<{
3939
labelFormat: (d: KV) => `${d.key} – ${d.value}`
4040
})
4141
42-
const chartRef = ref<HTMLElement>()
42+
const chartRef = useTemplateRef('chart')
4343
const { width, height } = useElementSize(chartRef)
4444
4545
// Function to render the chart
@@ -271,12 +271,17 @@ function renderChart({
271271
}
272272
273273
if (props.tooltip) {
274-
// Create a tooltip
274+
// Create a tooltip
275275
const Tooltip = d3
276276
.select(chartRef.value)
277277
.append('div')
278278
.attr('class', 'tooltip')
279279
280+
if (shouldDisableTransitions()) {
281+
Tooltip
282+
.style('transition', 'none')
283+
}
284+
280285
// Add interactivity
281286
arcs
282287
.on('mouseover', (_, d) => {
@@ -328,7 +333,7 @@ watch(
328333
</script>
329334

330335
<template>
331-
<div ref="chartRef" class="SChartPie" />
336+
<div ref="chart" class="SChartPie" />
332337
</template>
333338

334339
<style scoped lang="postcss">

lib/support/Chart.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
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+
1216
export const c = {
1317
text1: 'light-dark(#1c2024, #edeef0)',
1418
text2: 'light-dark(#5d616b, #abafb7)',

0 commit comments

Comments
 (0)