From 5be46926974a73ae7e6027e6a614134eb4a7fa6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Sun, 2 Aug 2026 19:07:27 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=93=8A=20paged=20chart=20bars=20a?= =?UTF-8?q?nd=20progress-ring=20legends=20-=20itemsPerPage=20prop=20on=20C?= =?UTF-8?q?hartBar=20and=20ChartProgressRing=20pages=20long=20lists=20=20?= =?UTF-8?q?=20with=20the=20shared=20TablePagination;=20scale=20stays=20com?= =?UTF-8?q?puted=20over=20every=20item=20=20=20so=20bars=20don't=20rescale?= =?UTF-8?q?=20while=20paging,=20refetch=20clamps=20the=20page=20index=20-?= =?UTF-8?q?=20bar=20tooltip=20is=20permanently=20mounted=20and=20toggled?= =?UTF-8?q?=20via=20CSS=20group-hover=20=20=20opacity,=20removing=20the=20?= =?UTF-8?q?hover=20reflow=20jump=20-=20dashboard=20applies=20paging=20to?= =?UTF-8?q?=20course=20averages,=20capacities,=20and=20splits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ui/chart-bar.tsx | 90 +++++++++++++++-------- src/components/ui/chart-progress-ring.tsx | 32 +++++++- src/pages/dashboard-page.tsx | 4 + 3 files changed, 93 insertions(+), 33 deletions(-) diff --git a/src/components/ui/chart-bar.tsx b/src/components/ui/chart-bar.tsx index 9cdf8ba..a8e81c0 100644 --- a/src/components/ui/chart-bar.tsx +++ b/src/components/ui/chart-bar.tsx @@ -1,5 +1,6 @@ -import { For, Show, createSignal, type Component } from "solid-js"; +import { For, Show, createEffect, createMemo, createSignal, type Component } from "solid-js"; import { cn } from "@/lib/cn"; +import { TablePagination } from "@/components/ui/table-pagination"; import { useT } from "@/stores/preferences-context"; export type ChartBarItem = { @@ -17,18 +18,35 @@ export type ChartBarProps = { items: ChartBarItem[]; maxScale?: number; class?: string; + /** When set and items.length exceeds it, the list is paged with Prev/Next controls. */ + itemsPerPage?: number; }; export const ChartBar: Component = (props) => { - const [hoveredId, setHoveredId] = createSignal(null); + const [pageIndex, setPageIndex] = createSignal(0); const t = useT(); + // The scale is computed off every item, not just the visible page, so bars + // don't rescale as the reader pages through them. const maxValue = () => { if (props.maxScale != null && props.maxScale > 0) return props.maxScale; const itemMax = Math.max(...props.items.map((i) => i.value), 1); return itemMax; }; + const pageCount = createMemo(() => + props.itemsPerPage ? Math.max(1, Math.ceil(props.items.length / props.itemsPerPage)) : 1, + ); + // A refetch can shrink the item count out from under the current page. + createEffect(() => { + if (pageIndex() >= pageCount()) setPageIndex(Math.max(0, pageCount() - 1)); + }); + const visibleItems = createMemo(() => { + if (!props.itemsPerPage) return props.items; + const start = pageIndex() * props.itemsPerPage; + return props.items.slice(start, start + props.itemsPerPage); + }); + return (
@@ -52,47 +70,57 @@ export const ChartBar: Component = (props) => { } >
- + {(item) => { const pct = () => Math.min(100, Math.max(0, (item.value / maxValue()) * 100)); - const isHovered = () => hoveredId() === item.id; return ( -
setHoveredId(item.id)} - onMouseLeave={() => setHoveredId(null)} - > -
- - {item.label} - - - {item.formattedValue ?? item.value} - -
+ // Tooltip stays permanently mounted and toggles via CSS group-hover + // opacity rather than a JS-driven Show — mounting/unmounting it on + // every hover was the source of a visible jump for whichever item + // sits at the bottom of the list, since that insert/remove briefly + // altered the card's content. +
+
+
+ + {item.label} + + + {item.formattedValue ?? item.value} + +
-
-
+
+
+
- -
- {item.label}: {item.formattedValue ?? item.value} ({Math.round(pct())}%) -
-
+
+ {item.label}: {item.formattedValue ?? item.value} ({Math.round(pct())}%) +
); }}
+ + 1}> + +
); diff --git a/src/components/ui/chart-progress-ring.tsx b/src/components/ui/chart-progress-ring.tsx index 21f22ff..de072c6 100644 --- a/src/components/ui/chart-progress-ring.tsx +++ b/src/components/ui/chart-progress-ring.tsx @@ -1,5 +1,6 @@ -import { For, Show, type Component } from "solid-js"; +import { For, Show, createEffect, createMemo, createSignal, type Component } from "solid-js"; import { cn } from "@/lib/cn"; +import { TablePagination } from "@/components/ui/table-pagination"; import { useT } from "@/stores/preferences-context"; export type ProgressRingSegment = { @@ -17,12 +18,29 @@ export type ChartProgressRingProps = { segments: ProgressRingSegment[]; total?: number; class?: string; + /** When set and segments.length exceeds it, the legend is paged with Prev/Next controls. */ + itemsPerPage?: number; }; export const ChartProgressRing: Component = (props) => { const t = useT(); + const [pageIndex, setPageIndex] = createSignal(0); + // The gauge bar above always renders every segment's share of the total — + // only the legend cards below it are paged. const calculatedTotal = () => props.total ?? props.segments.reduce((acc, s) => acc + s.value, 0); + const pageCount = createMemo(() => + props.itemsPerPage ? Math.max(1, Math.ceil(props.segments.length / props.itemsPerPage)) : 1, + ); + createEffect(() => { + if (pageIndex() >= pageCount()) setPageIndex(Math.max(0, pageCount() - 1)); + }); + const visibleSegments = createMemo(() => { + if (!props.itemsPerPage) return props.segments; + const start = pageIndex() * props.itemsPerPage; + return props.segments.slice(start, start + props.itemsPerPage); + }); + return (
@@ -76,7 +94,7 @@ export const ChartProgressRing: Component = (props) => { {/* Legend Grid */}
- + {(segment) => (
@@ -88,6 +106,16 @@ export const ChartProgressRing: Component = (props) => { )}
+ + 1}> + +
diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index b9dd020..340ee2b 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -352,6 +352,7 @@ function DashboardContent() { subtitle={t("dashboard.courseAverages")} items={courseAverages()} maxScale={100} + itemsPerPage={5} />
@@ -360,6 +361,7 @@ function DashboardContent() { title={t("dashboard.progressOverview")} subtitle={t("dashboard.courseCapacities")} items={courseCapacities()} + itemsPerPage={5} /> @@ -367,6 +369,7 @@ function DashboardContent() { title={t("dashboard.activitySplit")} subtitle={t("dashboard.activitySplitDesc")} segments={attendanceSegments()} + itemsPerPage={3} /> @@ -374,6 +377,7 @@ function DashboardContent() { title={t("dashboard.workloadSplit")} subtitle={t("dashboard.workloadSplitDesc")} segments={workloadSegments()} + itemsPerPage={3} />