diff --git a/frontend/package.json b/frontend/package.json index ee5d68a..50f02b2 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -18,6 +18,7 @@ "@codemirror/view": "^6.43.8", "@lezer/highlight": "^1.2.3", "codemirror": "^6.0.2", + "country-flag-icons": "^1.6.20", "overlayscrollbars": "^2.16.0", "transliteration": "^2.6.1", "vue": "^3.5.26", diff --git a/frontend/src/AnalyticsView.vue b/frontend/src/AnalyticsView.vue index 1099e66..966c89d 100644 --- a/frontend/src/AnalyticsView.vue +++ b/frontend/src/AnalyticsView.vue @@ -8,13 +8,8 @@ // See docs/analytics.md for the data format. import { computed, onMounted, onUnmounted, ref, watch } from 'vue' import { RANGES } from './analytics/time.js' -import { - calcTotalViews, - countByField, - countUtmTags, - formatCounts, - formatVisitRows, -} from './analytics/format.js' +import { calcTotalViews, formatVisitRows } from './analytics/format.js' +import * as flagSvgs from 'country-flag-icons/string/3x2' import TransitionGraph from './TransitionGraph.vue' import VisitorCharts from './VisitorCharts.vue' @@ -62,14 +57,19 @@ watch(range, (r) => { }) const visitRows = computed(() => formatVisitRows(visits.value, pageTree.value)) -const languageCounts = computed(() => countByField(visits.value, 'lang')) -const countryCounts = computed(() => countByField(visits.value, 'country')) -const utmTagCounts = computed(() => countUtmTags(visits.value)) -const hasBreakdowns = computed(() => - languageCounts.value.length > 0 - || countryCounts.value.length > 0 - || utmTagCounts.value.length > 0, -) + +function flagSvg(code) { + return flagSvgs[code?.toUpperCase()] || '' +} + +function countryName(code) { + if (!code) return '' + try { + return new Intl.DisplayNames(['en'], { type: 'region' }).of(code.toUpperCase()) + } catch { + return '' + } +}