From 39c42e7bd5de17186d056375850fcb1d7b156265 Mon Sep 17 00:00:00 2001 From: Emily Date: Fri, 20 Dec 2024 15:56:06 +0100 Subject: [PATCH] fix cards index --- dashboard/components/dashboard/CountCard.vue | 31 ++++------- dashboard/components/dashboard/TopCards.vue | 57 ++++++++++---------- dashboard/pages/analyst.vue | 15 ++++-- dashboard/pages/index.vue | 4 -- dashboard/pages/project_creation.vue | 6 ++- 5 files changed, 53 insertions(+), 60 deletions(-) diff --git a/dashboard/components/dashboard/CountCard.vue b/dashboard/components/dashboard/CountCard.vue index 1f13a29..9dec9d6 100644 --- a/dashboard/components/dashboard/CountCard.vue +++ b/dashboard/components/dashboard/CountCard.vue @@ -5,24 +5,18 @@ const props = defineProps<{ value: string, text: string, avg?: string, - trend?: number, color: string, data?: number[], labels?: string[], ready?: boolean, slow?: boolean, - todayIndex: number + todayIndex: number, + tooltipText: string }>(); const { snapshotDuration } = useSnapshot() -const uTooltipText = computed(() => { - const duration = snapshotDuration.value; - if (!duration) return ''; - if (duration > 25) return 'Monthly trend'; - if (duration > 7) return 'Weekly trend'; - return 'Daily trend'; -}) +const { showDrawer } = useDrawer(); @@ -42,25 +36,18 @@ const uTooltipText = computed(() => {
{{ text }}
-
- -
- -
- {{ trend.toFixed(0) }} % -
-
+ +
+ + -
- +
diff --git a/dashboard/components/dashboard/TopCards.vue b/dashboard/components/dashboard/TopCards.vue index c8b77ff..7a80eb6 100644 --- a/dashboard/components/dashboard/TopCards.vue +++ b/dashboard/components/dashboard/TopCards.vue @@ -13,24 +13,19 @@ const chartSlice = computed(() => { }); +function findFirstZeroOrNullIndex(arr: (number | null)[]) { + for (let i = 0; i < arr.length; i++) { + if (arr.slice(i).every(val => val === 0 || val === null)) return i; + } + return -1; +} + function transformResponse(input: { _id: string, count: number }[]) { const data = input.map(e => e.count || 0); + const labels = input.map(e => DateService.getChartLabelFromISO(e._id, new Date().getTimezoneOffset(), chartSlice.value)); - const labels = input.map(e => DateService.getChartLabelFromISO(e._id, new Date().getTimezoneOffset(), chartSlice.value)); - - const pool = [...input.map(e => e.count || 0)]; - - const avg = pool.reduce((a, e) => a + e, 0) / pool.length; - - const targets = input.slice(Math.floor(input.length / 4 * 3)); - const targetAvg = targets.reduce((a, e) => a + e.count, 0) / targets.length; - - const diffPercent: number = (100 / avg * (targetAvg)) - 100; - - const trend = Math.max(Math.min(diffPercent, 99), -99); - - return { data, labels, trend, input } + return { data, labels, input } } @@ -91,7 +86,7 @@ const avgSessionDuration = computed(() => { return `${hours > 0 ? hours + 'h ' : ''}${minutes}m ${seconds.toFixed()}s` }); -const todayIndex = computed(()=>{ +const todayIndex = computed(() => { if (!visitsData.data.value) return -1; return visitsData.data.value.input.findIndex(e => new Date(e._id).getTime() > (Date.now() - new Date().getTimezoneOffset() * 1000 * 60)); }) @@ -103,29 +98,33 @@ const todayIndex = computed(()=>{