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} />