|
1 | 1 | <script setup> |
2 | 2 | import { computed, watch, Fragment, useAttrs, useSlots, useTemplateRef, onMounted, reactive, provide } from 'vue' |
3 | | -import { reactiveComputed, useElementSize } from '@vueuse/core' |
| 3 | +import { reactiveComputed, useResizeObserver } from '@vueuse/core' |
4 | 4 | import { baseParse } from '@vue/compiler-core' |
5 | 5 | import { theme_base, theme_default, themeBuild, themeMerge, themePreprocess } from '../js/theme' |
6 | 6 | import { str_c, serializeSVG } from '../js/utils' |
@@ -479,12 +479,14 @@ onMounted(() => { |
479 | 479 | wrapperRef.value.style.height = str_c(v, 'px') ?? null |
480 | 480 | }, { immediate: true }) |
481 | 481 | }) |
482 | | -const { width: w, height: h } = useElementSize(plotRef) |
483 | | -watch([w, h], ([w, h], [ow, oh]) => { |
| 482 | +let oldSize = { width: 0, height: 0 } |
| 483 | +useResizeObserver(plotRef, (e) => { |
| 484 | + let { width: w, height: h } = e[0].contentRect |
484 | 485 | if (wrapperRef.value.style.width) width.value = w |
485 | 486 | if (wrapperRef.value.style.height) height.value = h |
486 | | - if ((w > 0 || h > 0) && (ow > 0 || oh > 0)) |
487 | | - emit('resize', { width: w, height: h }, { width: ow, height: oh }) |
| 487 | + if ((w > 0 || h > 0) && (oldSize.width > 0 || oldSize.height > 0)) |
| 488 | + emit('resize', { width: w, height: h }, oldSize) |
| 489 | + oldSize = { width: w, height: h } |
488 | 490 | }) |
489 | 491 | const panelStyle = computed(() => { |
490 | 492 | return { |
@@ -520,7 +522,8 @@ defineExpose({ |
520 | 522 | :coord-levels="coordLevels" :levels="levels" :scales="$scales" :axes="axes" :theme="theme" |
521 | 523 | :selections="selections" v-model:transition="transition" v-bind="vBind.plot" |
522 | 524 | v-model:selection-preview="selectionPreview" v-model:selection-preview-theme="selectionPreviewTheme" |
523 | | - :action="action" :clip="clip" :render="render" :legendTeleport="legendTeleport" @select="(d, e) => emit('select', d, e)" /> |
| 525 | + :action="action" :clip="clip" :render="render" :legendTeleport="legendTeleport" |
| 526 | + @select="(d, e) => emit('select', d, e)" /> |
524 | 527 | <div class="vvplot-panel-container" :style="panelStyle"> |
525 | 528 | <div class="vvplot-panel" v-if="vnodes.dom.panel?.length"> |
526 | 529 | <component v-for="c in vnodes.dom.panel" :is="c" /> |
|
0 commit comments