Skip to content

Commit a876d77

Browse files
committed
fix trends + stacked chart
1 parent 00e63cc commit a876d77

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

dashboard/components/dashboard/TopCards.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@ const chartSlice = computed(() => {
2121
2222
2323
function transformResponse(input: { _id: string, count: number }[]) {
24+
2425
const data = input.map(e => e.count || 0);
26+
2527
const labels = input.map(e => DateService.getChartLabelFromISO(e._id, navigator.language, chartSlice.value));
28+
2629
const pool = [...input.map(e => e.count || 0)];
27-
pool.pop();
30+
2831
const avg = pool.reduce((a, e) => a + e, 0) / pool.length;
29-
const diffPercent: number = (100 / avg * (input.at(-1)?.count || 0)) - 100;
32+
33+
const targets = input.slice(Math.floor(input.length / 4 * 3));
34+
const targetAvg = targets.reduce((a, e) => a + e.count, 0) / targets.length;
35+
36+
const diffPercent: number = (100 / avg * (targetAvg)) - 100;
37+
3038
const trend = Math.max(Math.min(diffPercent, 99), -99);
39+
3140
return { data, labels, trend }
41+
3242
}
3343
3444
const visitsData = useFetch('/api/timeline/visits', {

dashboard/components/events/EventsStackedBarChart.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ function transformResponse(input: { _id: string, name: string, count: number }[]
1414
data: input,
1515
from: input[0]._id,
1616
to: safeSnapshotDates.value.to
17-
}, slice.value, {
18-
advanced: true,
19-
advancedGroupKey: 'name'
20-
});
17+
},
18+
slice.value,
19+
{ advanced: true, advancedGroupKey: 'name' });
2120
2221
const parsedDatasets: any[] = [];
2322
@@ -62,6 +61,7 @@ function transformResponse(input: { _id: string, name: string, count: number }[]
6261
datasets: parsedDatasets,
6362
labels: fixed.labels
6463
}
64+
6565
}
6666
6767
const errorData = ref<{ errored: boolean, text: string }>({
@@ -83,7 +83,7 @@ function onResponse(e: any) {
8383
const eventsStackedData = useFetch(`/api/timeline/events_stacked`, {
8484
lazy: true, immediate: false,
8585
transform: transformResponse,
86-
headers: useComputedHeaders({slice}),
86+
headers: useComputedHeaders({ slice }),
8787
onResponseError,
8888
onResponse
8989
});

dashboard/pages/events.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const eventsData = await useFetch(`/api/data/count`, { headers: useComputedHeade
2929
</div>
3030
</div>
3131
<div>
32-
<LyxUiButton type="secondary" to="https://docs.litlyx.com/custom-events">
32+
<LyxUiButton type="secondary" target="_blank" to="https://docs.litlyx.com/custom-events">
3333
Trigger your first event
3434
</LyxUiButton>
3535
</div>

dashboard/utils/DateUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function fixMetrics(result: { data: MetricsTimeline[], from: string, to:
6262

6363
const allKeys = !options.advanced ? [] : Array.from(new Set(result.data.map((e: any) => e[options.advancedGroupKey])).values());
6464

65-
console.log({allKeys})
65+
console.log({ allKeys, allDates })
6666

6767
const fixed: any[] = allDates.map(matchDate => {
6868

@@ -102,9 +102,9 @@ console.log({allKeys})
102102
if (slice == 'hour') {
103103
return `${e._id.getHours().toString().padStart(2, '0')}:00`
104104
} else if (slice == 'day') {
105-
return `${e._id.getDate().toString().padStart(2, '0')}/${e._id.getMonth().toString().padStart(2, '0')}`
105+
return `${e._id.getDate().toString().padStart(2, '0')}/${(e._id.getMonth() + 1).toString().padStart(2, '0')}`
106106
} else if (slice == 'month') {
107-
return `${e._id.getMonth().toString().padStart(2, '0')}/${e._id.getFullYear().toString()}`
107+
return `${(e._id.getMonth() + 1).toString().padStart(2, '0')}/${e._id.getFullYear().toString()}`
108108
} else if (slice == 'year') {
109109
return `${e._id.getFullYear().toString()}`
110110
} else {

0 commit comments

Comments
 (0)