Skip to content

Commit 270fd6a

Browse files
authored
Merge branch 'main' into button-butter
2 parents cd69d75 + 54e08d0 commit 270fd6a

25 files changed

Lines changed: 1908 additions & 150 deletions

app/components/Package/ChartModal.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<script setup lang="ts">
2-
defineProps<{
2+
const props = defineProps<{
33
modalTitle?: string
44
}>()
5+
6+
const emit = defineEmits<{
7+
(e: 'transitioned'): void
8+
}>()
59
</script>
610

711
<template>
812
<Modal
913
:modalTitle="modalTitle ?? $t('package.trends.title')"
1014
id="chart-modal"
1115
class="h-full sm:h-min sm:border sm:border-border sm:rounded-lg shadow-xl sm:max-h-[90vh] sm:max-w-3xl"
16+
@transitioned="emit('transitioned')"
1217
>
1318
<div class="font-mono text-sm">
1419
<slot />

app/components/Package/TrendsChart.vue

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,45 @@ import { useDebounceFn, useElementSize } from '@vueuse/core'
55
import { useCssVariables } from '~/composables/useColors'
66
import { OKLCH_NEUTRAL_FALLBACK, transparentizeOklch } from '~/utils/colors'
77
import { getFrameworkColor, isListedFramework } from '~/utils/frameworks'
8+
import { drawNpmxLogoAndTaglineWatermark } from '~/composables/useChartWatermark'
9+
import type {
10+
ChartTimeGranularity,
11+
DailyDataPoint,
12+
DateRangeFields,
13+
EvolutionData,
14+
EvolutionOptions,
15+
MonthlyDataPoint,
16+
WeeklyDataPoint,
17+
YearlyDataPoint,
18+
} from '~/types/chart'
19+
20+
const props = withDefaults(
21+
defineProps<{
22+
// For single package downloads history
23+
weeklyDownloads?: WeeklyDataPoint[]
24+
inModal?: boolean
825
9-
const props = defineProps<{
10-
// For single package downloads history
11-
weeklyDownloads?: WeeklyDataPoint[]
12-
inModal?: boolean
13-
14-
/**
15-
* Backward compatible single package mode.
16-
* Used when `weeklyDownloads` is provided.
17-
*/
18-
packageName?: string
26+
/**
27+
* Backward compatible single package mode.
28+
* Used when `weeklyDownloads` is provided.
29+
*/
30+
packageName?: string
1931
20-
/**
21-
* Multi-package mode.
22-
* Used when `weeklyDownloads` is not provided.
23-
*/
24-
packageNames?: string[]
25-
createdIso?: string | null
32+
/**
33+
* Multi-package mode.
34+
* Used when `weeklyDownloads` is not provided.
35+
*/
36+
packageNames?: string[]
37+
createdIso?: string | null
2638
27-
/** When true, shows facet selector (e.g. Downloads / Likes). */
28-
showFacetSelector?: boolean
29-
}>()
39+
/** When true, shows facet selector (e.g. Downloads / Likes). */
40+
showFacetSelector?: boolean
41+
permalink?: boolean
42+
}>(),
43+
{
44+
permalink: false,
45+
},
46+
)
3047
3148
const { locale } = useI18n()
3249
const { accentColors, selectedAccentColor } = useAccentColor()
@@ -100,17 +117,16 @@ const accent = computed(() => {
100117
: (colors.value.fgSubtle ?? OKLCH_NEUTRAL_FALLBACK)
101118
})
102119
120+
const watermarkColors = computed(() => ({
121+
fg: colors.value.fg ?? OKLCH_NEUTRAL_FALLBACK,
122+
bg: colors.value.bg ?? OKLCH_NEUTRAL_FALLBACK,
123+
fgSubtle: colors.value.fgSubtle ?? OKLCH_NEUTRAL_FALLBACK,
124+
}))
125+
103126
const mobileBreakpointWidth = 640
104127
const isMobile = computed(() => width.value > 0 && width.value < mobileBreakpointWidth)
105128
106-
type ChartTimeGranularity = 'daily' | 'weekly' | 'monthly' | 'yearly'
107129
const DEFAULT_GRANULARITY: ChartTimeGranularity = 'weekly'
108-
type EvolutionData = DailyDataPoint[] | WeeklyDataPoint[] | MonthlyDataPoint[] | YearlyDataPoint[]
109-
110-
type DateRangeFields = {
111-
startDate?: string
112-
endDate?: string
113-
}
114130
115131
function isRecord(value: unknown): value is Record<string, unknown> {
116132
return typeof value === 'object' && value !== null
@@ -315,7 +331,10 @@ const effectivePackageNames = computed<string[]>(() => {
315331
return single ? [single] : []
316332
})
317333
318-
const selectedGranularity = shallowRef<ChartTimeGranularity>(DEFAULT_GRANULARITY)
334+
const selectedGranularity = usePermalink<ChartTimeGranularity>('granularity', DEFAULT_GRANULARITY, {
335+
permanent: props.permalink,
336+
})
337+
319338
const displayedGranularity = shallowRef<ChartTimeGranularity>(DEFAULT_GRANULARITY)
320339
321340
const isEndDateOnPeriodEnd = computed(() => {
@@ -345,8 +364,13 @@ const shouldRenderEstimationOverlay = computed(
345364
() => !pending.value && isEstimationGranularity.value,
346365
)
347366
348-
const startDate = shallowRef<string>('') // YYYY-MM-DD
349-
const endDate = shallowRef<string>('') // YYYY-MM-DD
367+
const startDate = usePermalink<string>('start', '', {
368+
permanent: props.permalink,
369+
})
370+
const endDate = usePermalink<string>('end', '', {
371+
permanent: props.permalink,
372+
})
373+
350374
const hasUserEditedDates = shallowRef(false)
351375
352376
/**
@@ -571,7 +595,9 @@ const METRICS = computed<MetricDef[]>(() => [
571595
},
572596
])
573597
574-
const selectedMetric = shallowRef<MetricId>(DEFAULT_METRIC_ID)
598+
const selectedMetric = usePermalink<MetricId>('facet', DEFAULT_METRIC_ID, {
599+
permanent: props.permalink,
600+
})
575601
576602
// Per-metric state keyed by metric id
577603
const metricStates = reactive<
@@ -1241,31 +1267,6 @@ function drawSvgPrintLegend(svg: Record<string, any>) {
12411267
return seriesNames.join('\n')
12421268
}
12431269
1244-
/**
1245-
* Build and return npmx svg logo and tagline, to be injected during PNG & SVG exports
1246-
*/
1247-
function drawNpmxLogoAndTaglineWatermark(svg: Record<string, any>) {
1248-
if (!svg?.drawingArea) return ''
1249-
const npmxLogoWidthToHeight = 2.64
1250-
const npmxLogoWidth = 100
1251-
const npmxLogoHeight = npmxLogoWidth / npmxLogoWidthToHeight
1252-
1253-
return `
1254-
<svg x="${svg.drawingArea.left + svg.drawingArea.width / 2 - npmxLogoWidth / 2 - 3}" y="${svg.height - npmxLogoHeight}" width="${npmxLogoWidth}" height="${npmxLogoHeight}" viewBox="0 0 330 125" fill="none" xmlns="http://www.w3.org/2000/svg">
1255-
<path d="M22.848 97V85.288H34.752V97H22.848ZM56.4105 107.56L85.5945 25H93.2745L64.0905 107.56H56.4105ZM121.269 97V46.12H128.661L128.949 59.08L127.989 58.216C128.629 55.208 129.781 52.744 131.445 50.824C133.173 48.84 135.221 47.368 137.589 46.408C139.957 45.448 142.453 44.968 145.077 44.968C148.981 44.968 152.213 45.832 154.773 47.56C157.397 49.288 159.381 51.624 160.725 54.568C162.069 57.448 162.741 60.68 162.741 64.264V97H154.677V66.568C154.677 61.832 153.749 58.248 151.893 55.816C150.037 53.32 147.189 52.072 143.349 52.072C140.725 52.072 138.357 52.648 136.245 53.8C134.133 54.888 132.437 56.52 131.157 58.696C129.941 60.808 129.333 63.432 129.333 66.568V97H121.269ZM173.647 111.4V46.12H181.135L181.327 57.64L180.175 57.064C181.455 53.096 183.568 50.088 186.512 48.04C189.519 45.992 192.976 44.968 196.88 44.968C201.936 44.968 206.064 46.216 209.264 48.712C212.528 51.208 214.928 54.472 216.464 58.504C218 62.536 218.767 66.888 218.767 71.56C218.767 76.232 218 80.584 216.464 84.616C214.928 88.648 212.528 91.912 209.264 94.408C206.064 96.904 201.936 98.152 196.88 98.152C194.256 98.152 191.792 97.704 189.487 96.808C187.247 95.912 185.327 94.664 183.727 93.064C182.191 91.464 181.135 89.576 180.559 87.4L181.711 86.056V111.4H173.647ZM196.111 90.472C200.528 90.472 203.984 88.808 206.48 85.48C209.04 82.152 210.319 77.512 210.319 71.56C210.319 65.608 209.04 60.968 206.48 57.64C203.984 54.312 200.528 52.648 196.111 52.648C193.167 52.648 190.607 53.352 188.431 54.76C186.319 56.168 184.655 58.28 183.439 61.096C182.287 63.912 181.711 67.4 181.711 71.56C181.711 75.72 182.287 79.208 183.439 82.024C184.591 84.84 186.255 86.952 188.431 88.36C190.607 89.768 193.167 90.472 196.111 90.472ZM222.57 97V46.12H229.962L230.25 57.448L229.29 57.256C229.866 53.48 231.082 50.504 232.938 48.328C234.858 46.088 237.29 44.968 240.234 44.968C243.242 44.968 245.546 46.056 247.146 48.232C248.81 50.408 249.834 53.608 250.218 57.832H249.258C249.834 53.864 251.114 50.728 253.098 48.424C255.146 46.12 257.706 44.968 260.778 44.968C264.874 44.968 267.85 46.376 269.706 49.192C271.562 52.008 272.49 56.68 272.49 63.208V97H264.426V64.36C264.426 59.816 263.946 56.648 262.986 54.856C262.026 53 260.522 52.072 258.474 52.072C257.13 52.072 255.946 52.52 254.922 53.416C253.898 54.248 253.066 55.592 252.426 57.448C251.85 59.304 251.562 61.672 251.562 64.552V97H243.498V64.36C243.498 60.008 243.018 56.872 242.058 54.952C241.162 53.032 239.658 52.072 237.546 52.072C236.202 52.072 235.018 52.52 233.994 53.416C232.97 54.248 232.138 55.592 231.498 57.448C230.922 59.304 230.634 61.672 230.634 64.552V97H222.57ZM276.676 97L295.396 70.888L277.636 46.12H287.044L300.388 65.32L313.444 46.12H323.044L305.38 71.08L323.908 97H314.5L300.388 76.456L286.276 97H276.676Z" fill="${colors.value.fg}"/>
1256-
</svg>
1257-
<text
1258-
fill="${colors.value.fgMuted}"
1259-
x="${svg.drawingArea.left + svg.drawingArea.width / 2}"
1260-
y="${svg.height - npmxLogoHeight - 6}"
1261-
font-size="12"
1262-
text-anchor="middle"
1263-
>
1264-
${$t('tagline')}
1265-
</text>
1266-
`
1267-
}
1268-
12691270
// VueUiXy chart component configuration
12701271
const chartConfig = computed(() => {
12711272
return {
@@ -1563,7 +1564,7 @@ watch(selectedMetric, value => {
15631564
<!-- Inject npmx logo & tagline during SVG and PNG print -->
15641565
<g
15651566
v-if="svg.isPrintingSvg || svg.isPrintingImg"
1566-
v-html="drawNpmxLogoAndTaglineWatermark(svg)"
1567+
v-html="drawNpmxLogoAndTaglineWatermark(svg, watermarkColors, $t, 'bottom')"
15671568
/>
15681569

15691570
<!-- Overlay covering the chart area to hide line resizing when switching granularities recalculates VueUiXy scaleMax when estimation lines are necessary -->

0 commit comments

Comments
 (0)