Skip to content

Commit 7331083

Browse files
feat: improve charts (#214)
Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent 8498f68 commit 7331083

5 files changed

Lines changed: 121 additions & 21 deletions

File tree

app/components/ChartModal.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<script setup lang="ts">
22
const open = defineModel<boolean>('open', { default: false })
33
4+
function close() {
5+
open.value = false
6+
}
7+
48
function handleKeydown(event: KeyboardEvent) {
59
if (event.key === 'Escape') {
6-
open.value = false
10+
close()
711
}
812
}
913
</script>
@@ -53,6 +57,8 @@ function handleKeydown(event: KeyboardEvent) {
5357
<slot />
5458
</div>
5559
</div>
60+
61+
<slot name="after" v-bind="{ close }" />
5662
</div>
5763
</div>
5864
</Transition>

app/components/PackageDownloadAnalytics.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ref, computed, shallowRef, watch } from 'vue'
33
import type { VueUiXyDatasetItem } from 'vue-data-ui'
44
import { VueUiXy } from 'vue-data-ui/vue-ui-xy'
5-
import { useDebounceFn } from '@vueuse/core'
5+
import { useDebounceFn, useElementSize } from '@vueuse/core'
66
77
const {
88
weeklyDownloads,
@@ -18,8 +18,10 @@ const {
1818
1919
const { accentColors, selectedAccentColor } = useAccentColor()
2020
const colorMode = useColorMode()
21-
2221
const resolvedMode = ref<'light' | 'dark'>('light')
22+
const rootEl = shallowRef<HTMLElement | null>(null)
23+
24+
const { width } = useElementSize(rootEl)
2325
2426
onMounted(() => {
2527
resolvedMode.value = colorMode.value === 'dark' ? 'dark' : 'light'
@@ -50,6 +52,16 @@ const accent = computed(() => {
5052
return id ? (oklchToHex(accentColorValueById.value[id]!) ?? '#8A8A8A') : '#8A8A8A'
5153
})
5254
55+
const mobileBreakpointWidth = 640
56+
57+
const isMobile = computed(() => {
58+
return width.value > 0 && width.value < mobileBreakpointWidth
59+
})
60+
61+
onMounted(() => {
62+
rootEl.value = document.documentElement
63+
})
64+
5365
type ChartTimeGranularity = 'daily' | 'weekly' | 'monthly' | 'yearly'
5466
type EvolutionData =
5567
| DailyDownloadPoint[]
@@ -417,6 +429,7 @@ const formatter = ({ value }: { value: number }) => formatCompactNumber(value, {
417429
const config = computed(() => ({
418430
theme: isDarkMode.value ? 'dark' : 'default',
419431
chart: {
432+
height: isMobile.value ? 850 : 600,
420433
userOptions: {
421434
buttons: {
422435
pdf: false,
@@ -474,6 +487,7 @@ const config = computed(() => ({
474487
},
475488
},
476489
zoom: {
490+
maxWidth: 500,
477491
highlightColor: isDarkMode.value ? '#2A2A2A' : '#E1E5E8',
478492
minimap: {
479493
show: true,
@@ -699,9 +713,4 @@ const config = computed(() => ({
699713
background: var(--bg-elevated) !important;
700714
box-shadow: none !important;
701715
}
702-
703-
.vue-data-ui-zoom {
704-
max-width: 500px;
705-
margin: 0 auto;
706-
}
707716
</style>

app/components/PackageWeeklyDownloadStats.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ const config = computed(() => {
202202
:packageName="packageName"
203203
:createdIso="createdIso"
204204
/>
205+
206+
<template #after="{ close }">
207+
<div class="sm:hidden flex justify-center">
208+
<button
209+
type="button"
210+
@click="close"
211+
class="w-12 h-12 bg-bg-elevated border border-border rounded-full shadow-lg flex items-center justify-center text-fg-muted hover:text-fg transition-colors"
212+
:aria-label="$t('common.close')"
213+
>
214+
<span class="w-5 h-5 i-carbon-close" />
215+
</button>
216+
</div>
217+
</template>
205218
</ChartModal>
206219
</template>
207220

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"validate-npm-package-name": "^7.0.2",
5454
"virtua": "^0.48.3",
5555
"vue": "3.5.27",
56-
"vue-data-ui": "^3.13.2"
56+
"vue-data-ui": "^3.13.4"
5757
},
5858
"devDependencies": {
5959
"@iconify-json/carbon": "1.2.18",

pnpm-lock.yaml

Lines changed: 84 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)