Skip to content

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

Enhance Chart and MainSection components for improved data representation and layout

Bill Yangccaa19bdc387
diff --git a/client/src/app/[site]/main/components/MainSection/Chart.tsx b/client/src/app/[site]/main/components/MainSection/Chart.tsx
index de6735c29..6cf8c08bd 100644
--- a/client/src/app/[site]/main/components/MainSection/Chart.tsx
+++ b/client/src/app/[site]/main/components/MainSection/Chart.tsx
@@ -85,6 +85,8 @@ const formatTooltipValue = (value: number, selectedStat: StatType) => {
return value.toLocaleString();
};
+const Y_TICK_VALUES = 5;
+
export function Chart({
data,
previousData,
@@ -151,7 +153,7 @@ export function Chart({
}}
enableGridX={false}
enableGridY={true}
- gridYValues={4}
+ gridYValues={Y_TICK_VALUES}
yFormat=" >-.2f"
axisTop={null}
axisRight={null}
@@ -179,7 +181,7 @@ export function Chart({
tickPadding: 10,
tickRotation: 0,
truncateTickAt: 0,
- tickValues: 4,
+ tickValues: Y_TICK_VALUES,
format: formatter.format,
}}
enableTouchCrosshair={true}
diff --git a/client/src/app/[site]/main/components/MainSection/MainSection.tsx b/client/src/app/[site]/main/components/MainSection/MainSection.tsx
index c08caba27..fc3771363 100644
--- a/client/src/app/[site]/main/components/MainSection/MainSection.tsx
+++ b/client/src/app/[site]/main/components/MainSection/MainSection.tsx
@@ -8,6 +8,15 @@ import { useStore } from "../../../../../lib/store";
import { useGetOverviewBucketed } from "../../../../../api/analytics/useGetOverviewBucketed";
import { useGetOverview } from "../../../../../api/analytics/useGetOverview";
+const SELECTED_STAT_MAP = {
+ pageviews: "Pageviews",
+ sessions: "Sessions",
+ pages_per_session: "Pages per Session",
+ bounce_rate: "Bounce Rate",
+ session_duration: "Session Duration",
+ users: "Users",
+};
+
export function MainSection() {
const { selectedStat, time, site } = useStore();
@@ -38,7 +47,14 @@ export function MainSection() {
</Card>
<Card>
{(isFetching || isPreviousFetching) && <CardLoader />}
- <CardContent className="pt-4 w-full">
+ <CardContent className="pt-3 w-full">
+ <div className="flex items-center justify-between ">
+ <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="absolute top-0 left-0 w-full h-full">
<PreviousChart
@@ -55,9 +71,6 @@ export function MainSection() {
}
/>
</div>
- <div className="absolute top-0 right-[14px]">
- <BucketSelection />
- </div>
</div>
</CardContent>
</Card>
diff --git a/client/src/app/[site]/main/components/MainSection/Overview.tsx b/client/src/app/[site]/main/components/MainSection/Overview.tsx
index 53d0c9852..bf49502eb 100644
--- a/client/src/app/[site]/main/components/MainSection/Overview.tsx
+++ b/client/src/app/[site]/main/components/MainSection/Overview.tsx
@@ -7,6 +7,8 @@ import { useGetOverview } from "../../../../../api/analytics/useGetOverview";
import { StatType, useStore } from "../../../../../lib/store";
import { useGetOverviewBucketed } from "../../../../../api/analytics/useGetOverviewBucketed";
import { SparklinesChart } from "./SparklinesChart";
+import { TrendingDown } from "lucide-react";
+import { TrendingUp } from "lucide-react";
const ChangePercentage = ({
current,
@@ -30,10 +32,17 @@ const ChangePercentage = ({
return (
<div
- className={cn("text-sm", change > 0 ? "text-green-400" : "text-red-400")}
+ className={cn(
+ "text-sm flex items-center gap-1",
+ change > 0 ? "text-green-400" : "text-red-400"
+ )}
>
- {change > 0 ? "+" : ""}
- {change.toFixed(0)}%
+ {change > 0 ? (
+ <TrendingUp className="w-4 h-4" />
+ ) : (
+ <TrendingDown className="w-4 h-4" />
+ )}
+ {Math.abs(change).toFixed(1)}%
</div>
);
};
@@ -70,14 +79,13 @@ const Stat = ({
<div
className={cn(
"flex flex-col hover:bg-neutral-800 cursor-pointer border-r border-neutral-800 last:border-r-0 text-nowrap",
- isFetching && "opacity-50",
selectedStat === id && "bg-neutral-850"
)}
onClick={() => setSelectedStat(id)}
>
<div className={cn("flex flex-col px-3 py-2")}>
<div className="text-sm font-medium text-muted-foreground">{title}</div>
- <div className="text-2xl font-medium flex gap-2 items-center">
+ <div className="text-2xl font-medium flex gap-2 items-center justify-between">
{isLoading ? (
<>
<Skeleton className="w-[60px] h-7 rounded-md" />