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