diff --git a/app/components/Chart/SplitSparkline.vue b/app/components/Chart/SplitSparkline.vue index e63ea4e4f5..7b9fee5c6f 100644 --- a/app/components/Chart/SplitSparkline.vue +++ b/app/components/Chart/SplitSparkline.vue @@ -5,7 +5,7 @@ import { type VueUiSparklineDatasetItem, } from 'vue-data-ui/vue-ui-sparkline' import { VueUiPatternSeed } from 'vue-data-ui/vue-ui-pattern-seed' -import { useCssVariables } from '~/composables/useColors' +import { useColors } from '~/composables/useColors' import type { VueUiXyDatasetItem } from 'vue-data-ui/vue-ui-xy' import { getPalette, lightenColor } from 'vue-data-ui/utils' import { CHART_PATTERN_CONFIG } from '~/utils/charts' @@ -50,23 +50,7 @@ watch( { flush: 'sync', immediate: true }, ) -const { colors } = useCssVariables( - [ - '--bg', - '--fg', - '--bg-subtle', - '--bg-elevated', - '--border-hover', - '--fg-subtle', - '--border', - '--border-subtle', - ], - { - element: rootEl, - watchHtmlAttributes: true, - watchResize: false, // set to true only if a var changes color on resize - }, -) +const { colors } = useColors(rootEl) const isDarkMode = computed(() => resolvedMode.value === 'dark') diff --git a/app/components/Compare/FacetBarChart.vue b/app/components/Compare/FacetBarChart.vue index c48f9ad8e4..f8393c14b0 100644 --- a/app/components/Compare/FacetBarChart.vue +++ b/app/components/Compare/FacetBarChart.vue @@ -9,6 +9,7 @@ import { VueUiPatternSeed } from 'vue-data-ui/vue-ui-pattern-seed' import { getFrameworkColor, isListedFramework } from '~/utils/frameworks' import { createPatternDef } from 'vue-data-ui/utils' import { drawSmallNpmxLogoAndTaglineWatermark } from '~/composables/useChartWatermark' +import { useColors } from '~/composables/useColors' import { loadFile, @@ -40,23 +41,7 @@ const isMobile = computed(() => width.value > 0 && width.value < mobileBreakpoin const chartKey = ref(0) -const { colors } = useCssVariables( - [ - '--bg', - '--fg', - '--bg-subtle', - '--bg-elevated', - '--fg-subtle', - '--fg-muted', - '--border', - '--border-subtle', - ], - { - element: rootEl, - watchHtmlAttributes: true, - watchResize: false, - }, -) +const { colors } = useColors(rootEl) const watermarkColors = computed(() => ({ fg: colors.value.fg ?? OKLCH_NEUTRAL_FALLBACK, diff --git a/app/components/Compare/FacetScatterChart.vue b/app/components/Compare/FacetScatterChart.vue index 9f3cdc332b..2d5442c3e0 100644 --- a/app/components/Compare/FacetScatterChart.vue +++ b/app/components/Compare/FacetScatterChart.vue @@ -9,6 +9,7 @@ import { } from 'vue-data-ui/vue-ui-scatter' import { buildCompareScatterChartDataset } from '~/utils/compare-scatter-chart' import { loadFile, copyAltTextForCompareScatterChart } from '~/utils/charts' +import { useColors } from '~/composables/useColors' import('vue-data-ui/style.css') @@ -26,25 +27,7 @@ const { copy, copied } = useClipboard() const mobileBreakpointWidth = 640 const isMobile = computed(() => width.value > 0 && width.value < mobileBreakpointWidth) -const { colors } = useCssVariables( - [ - '--bg', - '--fg', - '--bg-subtle', - '--bg-elevated', - '--fg-subtle', - '--fg-muted', - '--border', - '--border-subtle', - '--border-hover', - '--accent', - ], - { - element: rootEl, - watchHtmlAttributes: true, - watchResize: false, - }, -) +const { colors } = useColors(rootEl) const watermarkColors = computed(() => ({ fg: colors.value.fg ?? OKLCH_NEUTRAL_FALLBACK, diff --git a/app/components/Package/TimelineChart.vue b/app/components/Package/TimelineChart.vue index 53b0be9727..ed900fe42b 100644 --- a/app/components/Package/TimelineChart.vue +++ b/app/components/Package/TimelineChart.vue @@ -19,6 +19,7 @@ import { import type { TimelineVersion, SubEvent } from '~~/server/api/registry/timeline/[...pkg].get' import { drawSmallNpmxLogoAndTaglineWatermark } from '~/composables/useChartWatermark' import { useChartTooltipPosition } from '~/composables/useChartTooltipPosition' +import { useColors } from '~/composables/useColors' import('vue-data-ui/style.css') @@ -198,24 +199,7 @@ onMounted(async () => { resolvedMode.value = colorMode.value === 'dark' ? 'dark' : 'light' }) -const { colors } = useCssVariables( - [ - '--bg', - '--fg', - '--bg-subtle', - '--bg-elevated', - '--fg-subtle', - '--fg-muted', - '--border', - '--border-subtle', - '--accent', - ], - { - element: rootEl, - watchHtmlAttributes: true, - watchResize: false, - }, -) +const { colors } = useColors(rootEl) watch( () => colorMode.value, diff --git a/app/components/Package/TrendsChart.vue b/app/components/Package/TrendsChart.vue index 6499064a5a..995d430faf 100644 --- a/app/components/Package/TrendsChart.vue +++ b/app/components/Package/TrendsChart.vue @@ -2,7 +2,7 @@ import type { Theme as VueDataUiTheme } from 'vue-data-ui' import { VueUiXy, type VueUiXyConfig, type VueUiXyDatasetItem } from 'vue-data-ui/vue-ui-xy' import { useDebounceFn, useElementSize, useTimeoutFn } from '@vueuse/core' -import { useCssVariables } from '~/composables/useColors' +import { useColors } from '~/composables/useColors' import { OKLCH_NEUTRAL_FALLBACK, transparentizeOklch, lightenOklch } from '~/utils/colors' import { getFrameworkColor, isListedFramework } from '~/utils/frameworks' import { drawNpmxLogoAndTaglineWatermark } from '~/composables/useChartWatermark' @@ -92,23 +92,7 @@ onMounted(async () => { loadMetric(selectedMetric.value) }) -const { colors } = useCssVariables( - [ - '--bg', - '--fg', - '--bg-subtle', - '--bg-elevated', - '--fg-subtle', - '--fg-muted', - '--border', - '--border-subtle', - ], - { - element: rootEl, - watchHtmlAttributes: true, - watchResize: false, - }, -) +const { colors } = useColors(rootEl) watch( () => colorMode.value, @@ -1390,6 +1374,8 @@ watch( const tooltipPosition = useChartTooltipPosition(chartRef) +const keepZoomState = shallowRef(true) + // VueUiXy chart component configuration const chartConfig = computed(() => { return { @@ -1589,7 +1575,7 @@ const chartConfig = computed(() => { maxWidth: isMobile.value ? 350 : 500, highlightColor: colors.value.bgElevated, useResetSlot: true, - keepState: true, + keepState: keepZoomState.value, minimap: { show: true, lineColor: '#FAFAFA', @@ -1641,6 +1627,28 @@ const isSparklineLayout = computed({ chartLayout.value = v ? 'split' : 'combined' }, }) + +const { start: resetZoomState } = useTimeoutFn( + () => { + keepZoomState.value = true + }, + 1000, + { immediate: false }, +) + +async function resetZoom() { + keepZoomState.value = false + await nextTick() + chartRef.value?.resetZoom?.() + resetZoomState() +} + +onMounted(resetZoom) + +watch([selectedGranularity, startDate, endDate], async () => { + if (!isMounted.value) return + await resetZoom() +})