Add period selector for "All time" in graphs

This commit is contained in:
Brandon Presley 2024-02-07 11:42:24 +13:00
parent 31f9ddede3
commit 8fbc92920d
2 changed files with 11 additions and 4 deletions

View File

@ -31,6 +31,7 @@ export default function ViewGraph() {
else if (period === Periods.TwoMonths) difference = "-2 months";
else if (period === Periods.ThreeMonths) difference = "-3 months";
else if (period === Periods.SixMonths) difference = "-6 months";
else if (period === Periods.AllTime) difference = null;
let group = "%Y-%m-%d";
if (period === Periods.Yearly) group = "%Y-%m";
@ -40,13 +41,17 @@ export default function ViewGraph() {
.select("STRFTIME('%Y-%m-%d', created)", "created")
.addSelect("unit")
.where("name = :name", { name: params.name })
.andWhere("NOT hidden")
.andWhere("DATE(created) >= DATE('now', 'weekday 0', :difference)", {
.andWhere("NOT hidden");
if (difference) {
builder.andWhere("DATE(created) >= DATE('now', 'weekday 0', :difference)", {
difference,
})
});
}
builder
.groupBy("name")
.addGroupBy(`STRFTIME('${group}', created)`);
switch (metric) {
case Metrics.Best:
builder
@ -141,6 +146,7 @@ export default function ViewGraph() {
{ value: Periods.ThreeMonths, label: Periods.ThreeMonths },
{ value: Periods.SixMonths, label: Periods.SixMonths },
{ value: Periods.Yearly, label: Periods.Yearly },
{ value: Periods.AllTime, label: Periods.AllTime },
]}
onChange={(value) => setPeriod(value as Periods)}
value={period}

View File

@ -5,4 +5,5 @@ export enum Periods {
TwoMonths = "2 months",
ThreeMonths = "3 months",
SixMonths = "6 months",
AllTime = "All time",
}