fixes for correct labels
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { api } from "../../react-openapi";
|
import { api } from "../../react-openapi";
|
||||||
import { LatestItem } from "../components/LatestItemsList";
|
import { LatestItem } from "../components/LatestItemsList";
|
||||||
import { ChartDataPoint } from "../components/HistoryChart";
|
import { ChartDataPoint } from "../types/historyChart";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { format } from "./dateUtils";
|
import { format } from "./dateUtils";
|
||||||
import MonetizationOnIcon from "@mui/icons-material/MonetizationOn";
|
import MonetizationOnIcon from "@mui/icons-material/MonetizationOn";
|
||||||
@@ -126,15 +126,29 @@ export async function fetchAggregatedData(
|
|||||||
apply(monthlyCalendar);
|
apply(monthlyCalendar);
|
||||||
}
|
}
|
||||||
|
|
||||||
const toPoints = (arr: any[]): ChartDataPoint[] =>
|
const toPoints = (arr: any[], type: "weekly" | "monthly"): ChartDataPoint[] =>
|
||||||
arr.map((x) => ({
|
arr.map((x) => {
|
||||||
id: x.label,
|
let compareLabel: string | undefined;
|
||||||
amount: x.amount,
|
|
||||||
compareAmount: x.compare,
|
if (x.prevStart && x.prevEnd) {
|
||||||
compareLabel: x.prevStart && x.prevEnd
|
if (type === "monthly") {
|
||||||
? `${format(x.prevStart)} - ${format(x.prevEnd)}`
|
const year = String(x.prevStart.getFullYear()).slice(2);
|
||||||
: undefined
|
compareLabel = `${x.prevStart.toLocaleString("default", {
|
||||||
}));
|
month: "short"
|
||||||
|
})}-${year}`;
|
||||||
|
} else {
|
||||||
|
const year = String(x.prevEnd.getFullYear()).slice(2);
|
||||||
|
compareLabel = `${format(x.prevStart)} - ${format(x.prevEnd)} ${year}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: x.label,
|
||||||
|
amount: x.amount,
|
||||||
|
compareAmount: x.compare,
|
||||||
|
compareLabel
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const chartData = {
|
const chartData = {
|
||||||
daily: Object.entries(dailyBuckets).map(([k, v]: any) => ({
|
daily: Object.entries(dailyBuckets).map(([k, v]: any) => ({
|
||||||
@@ -143,12 +157,12 @@ export async function fetchAggregatedData(
|
|||||||
compareAmount: v.compare
|
compareAmount: v.compare
|
||||||
})),
|
})),
|
||||||
weekly: {
|
weekly: {
|
||||||
rolling: toPoints(weeklyRolling),
|
rolling: toPoints(weeklyRolling, "weekly"),
|
||||||
calendar: toPoints(weeklyCalendar)
|
calendar: toPoints(weeklyCalendar, "weekly")
|
||||||
},
|
},
|
||||||
monthly: {
|
monthly: {
|
||||||
rolling: toPoints(monthlyRolling),
|
rolling: toPoints(monthlyRolling, "monthly"),
|
||||||
calendar: toPoints(monthlyCalendar)
|
calendar: toPoints(monthlyCalendar, "monthly")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user