aggre based time week, month, year renamed to daily, weekly, monthly
This commit is contained in:
@@ -130,7 +130,7 @@ export default function Dashboard() {
|
|||||||
<HistoryChart
|
<HistoryChart
|
||||||
header={`${mode === "expense" ? "Expense" : "Income"} Breakdown`}
|
header={`${mode === "expense" ? "Expense" : "Income"} Breakdown`}
|
||||||
summary="Interactive chronological tracking"
|
summary="Interactive chronological tracking"
|
||||||
tabs={["Week", "Month", "Year"]}
|
tabs={["Daily", "Weekly", "Monthly"]}
|
||||||
data={currentData?.chartData || {}}
|
data={currentData?.chartData || {}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -44,14 +44,14 @@ export default function HistoryChart({
|
|||||||
|
|
||||||
if (amount === 0) return "";
|
if (amount === 0) return "";
|
||||||
|
|
||||||
if (tab === "year") {
|
if (tab === "monthly") {
|
||||||
if (amount >= 100000) {
|
if (amount >= 100000) {
|
||||||
return `₹ ${(amount / 100000).toFixed(2)} L`;
|
return `₹ ${(amount / 100000).toFixed(2)} L`;
|
||||||
}
|
}
|
||||||
return `₹ ${amount.toLocaleString("en-IN")}`;
|
return `₹ ${amount.toLocaleString("en-IN")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tab === "month") {
|
if (tab === "weekly") {
|
||||||
if (amount >= 1000) {
|
if (amount >= 1000) {
|
||||||
return `₹ ${(amount / 1000).toFixed(1)} K`;
|
return `₹ ${(amount / 1000).toFixed(1)} K`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export async function fetchAggregatedData(
|
|||||||
const normalize = (amt: number) => Math.abs(amt);
|
const normalize = (amt: number) => Math.abs(amt);
|
||||||
|
|
||||||
// ---------------- WEEK ----------------
|
// ---------------- WEEK ----------------
|
||||||
const weekBuckets: Record<string, number> = {
|
const dailyBuckets: Record<string, number> = {
|
||||||
Mon: 0, Tue: 0, Wed: 0, Thu: 0,
|
Mon: 0, Tue: 0, Wed: 0, Thu: 0,
|
||||||
Fri: 0, Sat: 0, Sun: 0
|
Fri: 0, Sat: 0, Sun: 0
|
||||||
};
|
};
|
||||||
@@ -105,7 +105,7 @@ export async function fetchAggregatedData(
|
|||||||
const weekEnd = endOfDay(new Date(weekStart.getTime() + 6 * 86400000));
|
const weekEnd = endOfDay(new Date(weekStart.getTime() + 6 * 86400000));
|
||||||
|
|
||||||
// ---------------- MONTH (rolling 5 weeks, Mon–Sun aligned) ----------------
|
// ---------------- MONTH (rolling 5 weeks, Mon–Sun aligned) ----------------
|
||||||
const monthBuckets: {
|
const weeklyBuckets: {
|
||||||
label: string;
|
label: string;
|
||||||
start: Date;
|
start: Date;
|
||||||
end: Date;
|
end: Date;
|
||||||
@@ -118,7 +118,7 @@ export async function fetchAggregatedData(
|
|||||||
const start = new Date(currentWeekStart.getTime() - i * 7 * 86400000);
|
const start = new Date(currentWeekStart.getTime() - i * 7 * 86400000);
|
||||||
const end = endOfDay(new Date(start.getTime() + 6 * 86400000));
|
const end = endOfDay(new Date(start.getTime() + 6 * 86400000));
|
||||||
|
|
||||||
monthBuckets.push({
|
weeklyBuckets.push({
|
||||||
label: `${format(start)} - ${format(end)}`,
|
label: `${format(start)} - ${format(end)}`,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
@@ -127,7 +127,7 @@ export async function fetchAggregatedData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------- YEAR (rolling 12 months) ----------------
|
// ---------------- YEAR (rolling 12 months) ----------------
|
||||||
const yearBuckets: {
|
const monthlyBuckets: {
|
||||||
label: string;
|
label: string;
|
||||||
start: Date;
|
start: Date;
|
||||||
end: Date;
|
end: Date;
|
||||||
@@ -149,7 +149,7 @@ export async function fetchAggregatedData(
|
|||||||
month: "short"
|
month: "short"
|
||||||
})}-${String(d.getFullYear()).slice(2)}`;
|
})}-${String(d.getFullYear()).slice(2)}`;
|
||||||
|
|
||||||
yearBuckets.push({
|
monthlyBuckets.push({
|
||||||
label,
|
label,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
@@ -176,20 +176,20 @@ export async function fetchAggregatedData(
|
|||||||
// WEEK
|
// WEEK
|
||||||
if (d >= weekStart && d <= weekEnd) {
|
if (d >= weekStart && d <= weekEnd) {
|
||||||
const day = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][d.getDay()];
|
const day = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][d.getDay()];
|
||||||
if (weekBuckets[day] !== undefined) {
|
if (dailyBuckets[day] !== undefined) {
|
||||||
weekBuckets[day] += amt;
|
dailyBuckets[day] += amt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MONTH (rolling weeks)
|
// MONTH (rolling weeks)
|
||||||
for (const b of monthBuckets) {
|
for (const b of weeklyBuckets) {
|
||||||
if (d >= b.start && d <= b.end) {
|
if (d >= b.start && d <= b.end) {
|
||||||
b.amount += amt;
|
b.amount += amt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// YEAR (rolling months)
|
// YEAR (rolling months)
|
||||||
for (const b of yearBuckets) {
|
for (const b of monthlyBuckets) {
|
||||||
if (d >= b.start && d <= b.end) {
|
if (d >= b.start && d <= b.end) {
|
||||||
b.amount += amt;
|
b.amount += amt;
|
||||||
}
|
}
|
||||||
@@ -208,9 +208,9 @@ export async function fetchAggregatedData(
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const chartData = {
|
const chartData = {
|
||||||
week: toPoints(weekBuckets),
|
daily: toPoints(dailyBuckets),
|
||||||
month: toPoints(monthBuckets),
|
weekly: toPoints(weeklyBuckets),
|
||||||
year: toPoints(yearBuckets)
|
monthly: toPoints(monthlyBuckets)
|
||||||
};
|
};
|
||||||
|
|
||||||
// highlight max
|
// highlight max
|
||||||
|
|||||||
Reference in New Issue
Block a user