Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor time calculations in Chart and PreviousChart components for improved readability

Bill Yangfd1f912fc7c6
diff --git a/client/src/app/[site]/main/components/MainSection/Chart.tsx b/client/src/app/[site]/main/components/MainSection/Chart.tsx
index aa520afc2..f640cb243 100644
--- a/client/src/app/[site]/main/components/MainSection/Chart.tsx
+++ b/client/src/app/[site]/main/components/MainSection/Chart.tsx
@@ -30,23 +30,31 @@ const getMax = (time: Time, bucket: TimeBucket) => {
}
return undefined;
} else if (time.mode === "day") {
- const dayDate = DateTime.fromISO(time.day).endOf("day").minus({ minutes: getBucketMinutesOffset(bucket) });
+ const dayDate = DateTime.fromISO(time.day)
+ .endOf("day")
+ .minus({ minutes: getBucketMinutesOffset(bucket) });
return now < dayDate ? dayDate.toJSDate() : undefined;
} else if (time.mode === "range") {
if (bucket === "day" || bucket === "week" || bucket === "month" || bucket === "year") {
return undefined;
}
- const rangeDate = DateTime.fromISO(time.endDate).endOf("day").minus({ minutes: getBucketMinutesOffset(bucket) });
+ const rangeDate = DateTime.fromISO(time.endDate)
+ .endOf("day")
+ .minus({ minutes: getBucketMinutesOffset(bucket) });
return now < rangeDate ? rangeDate.toJSDate() : undefined;
} else if (time.mode === "week") {
if (bucket !== "hour" && bucket !== "fifteen_minutes") {
return undefined;
}
- const endDate = DateTime.fromISO(time.week).endOf("week").minus({ minutes: getBucketMinutesOffset(bucket) });
+ const endDate = DateTime.fromISO(time.week)
+ .endOf("week")
+ .minus({ minutes: getBucketMinutesOffset(bucket) });
return now < endDate ? endDate.toJSDate() : undefined;
} else if (time.mode === "month") {
if (bucket === "hour") {
- const endDate = DateTime.fromISO(time.month).endOf("month").minus({ minutes: getBucketMinutesOffset(bucket) });
+ const endDate = DateTime.fromISO(time.month)
+ .endOf("month")
+ .minus({ minutes: getBucketMinutesOffset(bucket) });
return now < endDate ? endDate.toJSDate() : undefined;
}
const monthDate = DateTime.fromISO(time.month).endOf("month");
diff --git a/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx b/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
index 10a49e40f..c370a66a9 100644
--- a/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
+++ b/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
@@ -64,7 +64,7 @@ export function PreviousChart({
]
: [{ id: selectedStat, dataKey: selectedStat, color: previousColors[0] }];
- const size = (data?.data.length ?? 0 / 2) + 1;
+ const size = (data?.data.length ?? 0) / 2 + 1;
const chartData = seriesConfig.map(series => {
const points =
data?.data
@@ -158,7 +158,9 @@ export function PreviousChart({
animate={false}
// motionConfig="stiff"
enableSlices={"x"}
- colors={({ id }) => colorMap[id as string] ?? (resolvedTheme === "dark" ? "hsl(var(--neutral-700))" : "hsl(var(--neutral-100))")}
+ colors={({ id }) =>
+ colorMap[id as string] ?? (resolvedTheme === "dark" ? "hsl(var(--neutral-700))" : "hsl(var(--neutral-100))")
+ }
/>
);
}