Skip to content

Commit 63092dc

Browse files
committed
fix: persist zoom state when toggling controls
1 parent 6e6e6fa commit 63092dc

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

app/components/Package/TimelineChart.vue

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang="ts">
22
import { onMounted } from 'vue'
3+
import type {
4+
VueUiXy} from 'vue-data-ui/vue-ui-xy';
35
import {
4-
VueUiXy,
56
type VueUiXyConfig,
67
type VueUiXyDatasetBarItem,
78
type VueUiXyDatasetItem,
@@ -30,7 +31,7 @@ const props = defineProps<{
3031
3132
const { settings } = useSettings()
3233
const route = useRoute('timeline')
33-
34+
const chart = ref<typeof VueUiXy | null>(null)
3435
const activeVersion = computed(() => route.params.version)
3536
3637
const packageName = computed(() =>
@@ -83,6 +84,14 @@ const convertedData = computed(() => {
8384
return addEvaluationFlags(entries, props.versionSubEvents).toReversed()
8485
})
8586
87+
watch(
88+
() => convertedData.value,
89+
() => {
90+
chart.value?.resetZoom()
91+
},
92+
{ flush: 'post' },
93+
)
94+
8695
const versions = computed(() => convertedData.value.map(d => d.version))
8796
8897
const activeVersionIndex = computed(() => {
@@ -377,6 +386,7 @@ const config = computed<VueUiXyConfig>(() => {
377386
maxWidth: isMobile.value ? 350 : 500,
378387
highlightColor: colors.value.bgElevated,
379388
useResetSlot: true,
389+
keepState: true,
380390
minimap: {
381391
show: true,
382392
lineColor: '#FAFAFA',
@@ -526,7 +536,12 @@ const indexSelection = computed(() => {
526536
</div>
527537
</div>
528538
<ClientOnly>
529-
<VueUiXy :dataset="datasets[activeTab]" :config :selected-x-index="indexSelection">
539+
<VueUiXy
540+
ref="chart"
541+
:dataset="datasets[activeTab]"
542+
:config
543+
:selected-x-index="indexSelection"
544+
>
530545
<!-- Custom tooltip -->
531546
<template #tooltip="{ timeLabel }">
532547
<div class="font-mono text-xs flex flex-col">
@@ -826,12 +841,12 @@ const indexSelection = computed(() => {
826841
"
827842
/>
828843
</template>
829-
</ClientOnly>
830844

831-
<!-- Sizes loading indicator -->
832-
<div v-if="loading" class="h-0.5 rounded-full bg-bg-muted overflow-hidden">
833-
<div class="h-full w-1/3 bg-accent rounded-full animate-indeterminate" />
834-
</div>
845+
<!-- Sizes loading indicator -->
846+
<div v-if="loading" class="h-0.5 rounded-full bg-bg-muted overflow-hidden">
847+
<div class="h-full w-1/3 bg-accent rounded-full animate-indeterminate" />
848+
</div>
849+
</ClientOnly>
835850
</div>
836851
</template>
837852

0 commit comments

Comments
 (0)