|
1 | 1 | <script setup lang="ts">
|
2 | 2 | import { useElementSize } from '@vueuse/core'
|
3 | 3 | 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' |
6 | 6 |
|
7 | 7 | export type { ChartColor, KV }
|
8 | 8 |
|
@@ -30,7 +30,7 @@ const props = withDefaults(defineProps<{
|
30 | 30 | tooltipFormat: (d: KV) => `${d.key} – ${d.value}`
|
31 | 31 | })
|
32 | 32 |
|
33 |
| -const chartRef = ref<HTMLElement>() |
| 33 | +const chartRef = useTemplateRef('chart') |
34 | 34 | const { width, height } = useElementSize(chartRef)
|
35 | 35 |
|
36 | 36 | // Function to render the chart
|
@@ -218,12 +218,17 @@ function renderChart({
|
218 | 218 | }
|
219 | 219 |
|
220 | 220 | if (props.tooltip) {
|
221 |
| - // Create a tooltip |
| 221 | + // Create a tooltip |
222 | 222 | const Tooltip = d3
|
223 | 223 | .select(chartRef.value)
|
224 | 224 | .append('div')
|
225 | 225 | .attr('class', 'tooltip')
|
226 | 226 |
|
| 227 | + if (shouldDisableTransitions()) { |
| 228 | + Tooltip |
| 229 | + .style('transition', 'none') |
| 230 | + } |
| 231 | +
|
227 | 232 | // Add interactivity
|
228 | 233 | bars
|
229 | 234 | .on('mouseover', (_, d) => {
|
@@ -275,7 +280,7 @@ watch(
|
275 | 280 | </script>
|
276 | 281 |
|
277 | 282 | <template>
|
278 |
| - <div ref="chartRef" class="SChartBar" :class="mode" /> |
| 283 | + <div ref="chart" class="SChartBar" /> |
279 | 284 | </template>
|
280 | 285 |
|
281 | 286 | <style scoped lang="postcss">
|
|
0 commit comments