Skip to content

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

Enhance layout and responsiveness of MainPage and Chart components

Bill Yangbfeaa916c364
diff --git a/client/src/app/[site]/main/components/MainSection/Chart.tsx b/client/src/app/[site]/main/components/MainSection/Chart.tsx
index 6cf8c08bd..4379f4be6 100644
--- a/client/src/app/[site]/main/components/MainSection/Chart.tsx
+++ b/client/src/app/[site]/main/components/MainSection/Chart.tsx
@@ -7,6 +7,7 @@ import { formatSecondsAsMinutesAndSeconds } from "../../../../../lib/utils";
import { APIResponse } from "../../../../../api/types";
import { GetOverviewBucketedResponse } from "../../../../../api/analytics/useGetOverviewBucketed";
import { Time } from "../../../../../components/DateSelector/types";
+import { useWindowSize } from "@uidotdev/usehooks";
export const formatter = Intl.NumberFormat("en", { notation: "compact" });
@@ -97,6 +98,9 @@ export function Chart({
max: number;
}) {
const { time, bucket, selectedStat } = useStore();
+ const { width } = useWindowSize();
+
+ const maxTicks = Math.round((width ?? Infinity) / 75);
// When the current period has more datapoints than the previous period,
// we need to shift the previous datapoints to the right by the difference in length
@@ -135,7 +139,7 @@ export function Chart({
},
]}
theme={nivoTheme}
- margin={{ top: 10, right: 15, bottom: 20, left: 40 }}
+ margin={{ top: 10, right: 10, bottom: 20, left: 35 }}
xScale={{
type: "time",
format: "%Y-%m-%d %H:%M:%S",
@@ -162,8 +166,10 @@ export function Chart({
tickPadding: 10,
tickRotation: 0,
truncateTickAt: 0,
- tickValues:
- time.mode === "day" ? 24 : Math.min(12, data?.data?.length ?? 0),
+ tickValues: Math.min(
+ maxTicks,
+ time.mode === "day" ? 24 : Math.min(12, data?.data?.length ?? 0)
+ ),
format: (value) => {
if (time.mode === "day") {
return DateTime.fromJSDate(value).toFormat("ha");
diff --git a/client/src/app/[site]/main/components/MainSection/MainSection.tsx b/client/src/app/[site]/main/components/MainSection/MainSection.tsx
index fc3771363..fe9e94dbc 100644
--- a/client/src/app/[site]/main/components/MainSection/MainSection.tsx
+++ b/client/src/app/[site]/main/components/MainSection/MainSection.tsx
@@ -47,15 +47,15 @@ export function MainSection() {
</Card>
<Card>
{(isFetching || isPreviousFetching) && <CardLoader />}
- <CardContent className="pt-3 w-full">
- <div className="flex items-center justify-between ">
+ <CardContent className="p-2 md:p-4 py-3 w-full">
+ <div className="flex items-center justify-between px-2 md:px-0">
<span className="w-24" />
<span className="text-sm text-neutral-200">
{SELECTED_STAT_MAP[selectedStat]}
</span>
<BucketSelection />
</div>
- <div className="h-[290px] relative">
+ <div className="h-[200px] md:h-[290px] relative">
<div className="absolute top-0 left-0 w-full h-full">
<PreviousChart
data={previousData}
diff --git a/client/src/app/[site]/main/components/MainSection/Overview.tsx b/client/src/app/[site]/main/components/MainSection/Overview.tsx
index c183870a5..aa74332a6 100644
--- a/client/src/app/[site]/main/components/MainSection/Overview.tsx
+++ b/client/src/app/[site]/main/components/MainSection/Overview.tsx
@@ -154,7 +154,7 @@ export function Overview() {
overviewDataPrevious?.data?.session_duration ?? 0;
return (
- <div className="grid grid-cols-6 gap-0 items-center">
+ <div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-0 items-center">
<Stat
title="Unique Users"
id="users"
diff --git a/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx b/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
index 756290289..669758a10 100644
--- a/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
+++ b/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
@@ -54,7 +54,7 @@ export function PreviousChart({
},
]}
theme={nivoTheme}
- margin={{ top: 10, right: 15, bottom: 20, left: 40 }}
+ margin={{ top: 10, right: 10, bottom: 20, left: 35 }}
xScale={{
type: "time",
format: "%Y-%m-%d %H:%M:%S",
diff --git a/client/src/app/[site]/main/page.tsx b/client/src/app/[site]/main/page.tsx
index 8767475be..ec3de0d6f 100644
--- a/client/src/app/[site]/main/page.tsx
+++ b/client/src/app/[site]/main/page.tsx
@@ -28,10 +28,10 @@ function MainPageContent() {
}
return (
- <div className="p-4 max-w-[1100px] mx-auto space-y-3">
+ <div className="p-2 md:p-3 max-w-[1100px] mx-auto space-y-3 ">
<SubHeader />
<MainSection />
- <div className="grid grid-cols-2 gap-4 mt-4">
+ <div className="grid grid-cols-1 lg:grid-cols-2 gap-3 mt-4">
<Devices />
<Pages />
<Referrers />