feat: split jídel
feat: graf příjmů
This commit is contained in:
1 parent
bc85a37fc0
commit
b880b36edd
32 files changed
+2048
-262
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { StatsRange } from "../enums";
|
||||
import { formatDateString, getHumanMonth } from "../Utils";
|
||||
import { formatDateString, getHumanMonth, shiftDate } from "../Utils";
|
||||
|
||||
/** Vzhled bubliny s hodnotou — recharts ji kreslí inline stylem, ne přes CSS třídu. */
|
||||
export const TOOLTIP_STYLE = {
|
||||
@@ -30,3 +30,36 @@ export function pickPeriods<T>(stats: { byDay: T[], byMonth: T[], byYear: T[] },
|
||||
if (mode === StatsRange.ROK) return stats.byMonth;
|
||||
return stats.byYear;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrátí označení všech období rozsahu, i těch bez dat — prázdný den v grafu
|
||||
* je informace sama o sobě.
|
||||
*
|
||||
* U "Vše" se začíná rokem prvního dne s daty, jinak by graf otevíralo deset let nul.
|
||||
*
|
||||
* @param range zobrazené období
|
||||
* @param mode rozsah statistik
|
||||
* @param firstDate první den s daty, YYYY-MM-DD; bez něj je u "Vše" výsledek prázdný
|
||||
*/
|
||||
export const listPeriods = (range: StatsBounds, mode: StatsRange, firstDate?: string): string[] => {
|
||||
if (mode === StatsRange.MESIC) {
|
||||
const periods: string[] = [];
|
||||
for (let date = range.from; date <= range.to; date = shiftDate(date, 1)) periods.push(date);
|
||||
return periods;
|
||||
}
|
||||
if (mode === StatsRange.ROK) {
|
||||
const year = range.from.substring(0, 4);
|
||||
return Array.from({ length: 12 }, (_, index) => `${year}-${String(index + 1).padStart(2, '0')}`);
|
||||
}
|
||||
if (!firstDate) return [];
|
||||
const first = Number(firstDate.substring(0, 4));
|
||||
const last = Number(range.to.substring(0, 4));
|
||||
return Array.from({ length: last - first + 1 }, (_, index) => String(first + index));
|
||||
};
|
||||
|
||||
/** Zkrátí datum dne na označení období grafu. */
|
||||
export const periodOf = (date: string, mode: StatsRange): string => {
|
||||
if (mode === StatsRange.MESIC) return date;
|
||||
if (mode === StatsRange.ROK) return date.substring(0, 7);
|
||||
return date.substring(0, 4);
|
||||
};
|
||||
Reference in new issue
Block a user