|
1 | 1 | <script setup> |
2 | | -import { |
3 | | - ref, |
4 | | - computed, |
5 | | - onMounted, |
6 | | - onBeforeUnmount, |
7 | | - watch, |
8 | | - defineAsyncComponent, |
9 | | - shallowRef, |
10 | | - toRefs, |
11 | | - nextTick |
12 | | -} from "vue"; |
| 2 | +import { ref, computed, onMounted, onBeforeUnmount, watch, defineAsyncComponent, shallowRef, watchEffect, toRefs, nextTick } from "vue"; |
13 | 3 | import { |
14 | 4 | applyDataLabel, |
15 | 5 | calculateNiceScale, |
@@ -44,7 +34,6 @@ import { useNestedProp } from "../useNestedProp"; |
44 | 34 | import { useUserOptionState } from "../useUserOptionState"; |
45 | 35 | import { useChartAccessibility } from "../useChartAccessibility"; |
46 | 36 | import { useTimeLabelCollision } from "../useTimeLabelCollider"; |
47 | | -import { useResizeObserverEffect } from "../useResizeObserverEffect"; |
48 | 37 | import themes from "../themes.json"; |
49 | 38 | import Title from "../atoms/Title.vue"; // Must be ready in responsive mode |
50 | 39 | import Legend from "../atoms/Legend.vue"; // Must be ready in responsive mode |
@@ -366,8 +355,22 @@ const WIDTH = computed(() => chartDimensions.value.width); |
366 | 355 | const HEIGHT = computed(() => chartDimensions.value.height); |
367 | 356 |
|
368 | 357 | const topLabelsHeight = ref(0); |
369 | | -const updateTopLabelsHeight = throttle((h) => { topLabelsHeight.value = h }, 100); |
370 | | -useResizeObserverEffect({ elementRef: xAxisLabels, callback: updateTopLabelsHeight, attr: 'height' }); |
| 358 | +
|
| 359 | +const updateTopLabelsHeight = throttle((h) => { |
| 360 | + topLabelsHeight.value = h |
| 361 | +}, 100); |
| 362 | +
|
| 363 | +// Track time label height to update drawing area when they rotate |
| 364 | +watchEffect((onInvalidate) => { |
| 365 | + const el = xAxisLabels.value |
| 366 | + if (!el) return |
| 367 | +
|
| 368 | + const observer = new ResizeObserver(entries => { |
| 369 | + updateTopLabelsHeight(entries[0].contentRect.height) |
| 370 | + }) |
| 371 | + observer.observe(el) |
| 372 | + onInvalidate(() => observer.disconnect()) |
| 373 | +}); |
371 | 374 |
|
372 | 375 | const drawingArea = computed(() => { |
373 | 376 | const { top: p_top, right: p_right, bottom: p_bottom, left: p_left } = FINAL_CONFIG.value.style.chart.padding; |
|
0 commit comments