Skip to content

Commit ed73a8b

Browse files
graphierosautofix-ci[bot]danielroe
authored
fix: rtl issues on large downloads chart (#424)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent f01da04 commit ed73a8b

20 files changed

Lines changed: 35 additions & 8 deletions

app/components/PackageDownloadAnalytics.vue

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ function formatXyDataset(
138138
color: accent.value,
139139
},
140140
],
141-
dates: dataset.map(d => `${d.weekStart}\nto ${d.weekEnd}`),
141+
dates: dataset.map(d =>
142+
$t('package.downloads.date_range_multiline', {
143+
start: d.weekStart,
144+
end: d.weekEnd,
145+
}),
146+
),
142147
}
143148
}
144149
if (selectedGranularity === 'daily' && isDailyDataset(dataset)) {
@@ -199,14 +204,16 @@ function safeMax(a: string, b: string): string {
199204
return a.localeCompare(b) >= 0 ? a : b
200205
}
201206
202-
function extractDates(dateLabel: string) {
203-
if (typeof dateLabel !== 'string') return []
207+
function extractDates(dateLabel: string): [string, string] | null {
208+
const matches = dateLabel.match(/\b(\d{4}(?:-\d{2}-\d{2})?)\b/g) // either yyyy or yyyy-mm-dd
209+
if (!matches) return null
204210
205-
const parts = dateLabel.trim().split(/\s+/).filter(Boolean)
211+
const first = matches.at(0)
212+
const last = matches.at(-1)
206213
207-
if (parts.length < 2) return []
214+
if (!first || !last || first === last) return null
208215
209-
return [parts[0], parts[parts.length - 1]]
216+
return [first, last]
210217
}
211218
212219
/**
@@ -553,7 +560,8 @@ const config = computed(() => {
553560
? undefined
554561
: ({ absoluteIndex, side }: { absoluteIndex: number; side: 'left' | 'right' }) => {
555562
const parts = extractDates(chartData.value.dates[absoluteIndex] ?? '')
556-
return side === 'left' ? parts[0] : parts.at(-1)
563+
if (!parts) return ''
564+
return side === 'left' ? parts[0] : parts[1]
557565
},
558566
highlightColor: colors.value.bgElevated,
559567
minimap: {
@@ -670,7 +678,7 @@ const config = computed(() => {
670678
</div>
671679

672680
<ClientOnly v-if="inModal && chartData.dataset">
673-
<VueUiXy :dataset="chartData.dataset" :config="config">
681+
<VueUiXy :dataset="chartData.dataset" :config="config" class="[direction:ltr]">
674682
<template #menuIcon="{ isOpen }">
675683
<span v-if="isOpen" class="i-carbon:close w-6 h-6" aria-hidden="true" />
676684
<span v-else class="i-carbon:overflow-menu-vertical w-6 h-6" aria-hidden="true" />

i18n/locales/ar.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
"downloads": {
214214
"title": "التنزيلات الأسبوعية",
215215
"date_range": "من {start} إلى {end}",
216+
"date_range_multiline": "من {start}\nإلى {end}",
216217
"analyze": "تحليل التنزيلات",
217218
"modal_title": "التنزيلات",
218219
"granularity": "مستوى التفصيل",

i18n/locales/de-DE.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
"downloads": {
227227
"title": "Wöchentliche Downloads",
228228
"date_range": "{start} bis {end}",
229+
"date_range_multiline": "{start}\nbis {end}",
229230
"analyze": "Downloads analysieren",
230231
"modal_title": "Downloads",
231232
"granularity": "Granularität",

i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
"downloads": {
227227
"title": "Weekly Downloads",
228228
"date_range": "{start} to {end}",
229+
"date_range_multiline": "{start}\nto {end}",
229230
"analyze": "Analyze downloads",
230231
"modal_title": "Downloads",
231232
"granularity": "Granularity",

i18n/locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
"downloads": {
214214
"title": "Descargas Semanales",
215215
"date_range": "{start} a {end}",
216+
"date_range_multiline": "{start}\na {end}",
216217
"analyze": "Analizar descargas",
217218
"modal_title": "Descargas",
218219
"granularity": "Granularidad",

i18n/locales/fr-FR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
"downloads": {
214214
"title": "Téléchargements hebdomadaires",
215215
"date_range": "{start} au {end}",
216+
"date_range_multiline": "{start}\nau {end}",
216217
"analyze": "Analyser les téléchargements",
217218
"modal_title": "Téléchargements",
218219
"granularity": "Granularité",

i18n/locales/it-IT.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
"downloads": {
214214
"title": "Downloads settimanali",
215215
"date_range": "{start} a {end}",
216+
"date_range_multiline": "{start}\na {end}",
216217
"analyze": "Analizza downloads",
217218
"modal_title": "Downloads",
218219
"granularity": "Granularità",

i18n/locales/ja-JP.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
"downloads": {
214214
"title": "週間ダウンロード数",
215215
"date_range": "{start} から {end}",
216+
"date_range_multiline": "{start}\nから {end}",
216217
"analyze": "ダウンロード数を分析",
217218
"modal_title": "ダウンロード数",
218219
"granularity": "粒度",

i18n/locales/ru-RU.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
"downloads": {
223223
"title": "Загрузки за неделю",
224224
"date_range": "С {start} по {end}",
225+
"date_range_multiline": "С {start}\nпо {end}",
225226
"analyze": "Анализировать загрузки",
226227
"modal_title": "Загрузки",
227228
"granularity": "Детализация",

i18n/locales/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
"downloads": {
227227
"title": "每周下载量",
228228
"date_range": "{start} 到 {end}",
229+
"date_range_multiline": "{start}\n到 {end}",
229230
"analyze": "分析下载量",
230231
"modal_title": "下载量",
231232
"granularity": "周期",

0 commit comments

Comments
 (0)