forge
Explore
Log in

Don't you dare go Hollow

📊 paged chart bars and progress-ring legends

Browse files at this commit

5be46926974a73ae7e6027e6a614134eb4a7fa6eBurak BoduroğluParent: c866b7e
  • feat
    • 📊 paged chart bars and progress-ring legends
Show full message
feat: 📊 paged chart bars and progress-ring legends
- itemsPerPage prop on ChartBar and ChartProgressRing pages long lists
  with the shared TablePagination; scale stays computed over every item
  so bars don't rescale while paging, refetch clamps the page index
- bar tooltip is permanently mounted and toggled via CSS group-hover
  opacity, removing the hover reflow jump
- dashboard applies paging to course averages, capacities, and splits
src/components/ui/chart-bar.tsxmodified+59 -31
@@ -1,5 +1,6 @@
1-import { For, Show, createSignal, type Component } from "solid-js";1+import { For, Show, createEffect, createMemo, createSignal, type Component } from "solid-js";
2 import { cn } from "@/lib/cn";2 import { cn } from "@/lib/cn";
3+import { TablePagination } from "@/components/ui/table-pagination";
3 import { useT } from "@/stores/preferences-context";4 import { useT } from "@/stores/preferences-context";
4 5
5 export type ChartBarItem = {6 export type ChartBarItem = {
@@ -17,18 +18,35 @@ export type ChartBarProps = {
17 items: ChartBarItem[];18 items: ChartBarItem[];
18 maxScale?: number;19 maxScale?: number;
19 class?: string;20 class?: string;
21+ /** When set and items.length exceeds it, the list is paged with Prev/Next controls. */
22+ itemsPerPage?: number;
20 };23 };
21 24
22 export const ChartBar: Component<ChartBarProps> = (props) => {25 export const ChartBar: Component<ChartBarProps> = (props) => {
23- const [hoveredId, setHoveredId] = createSignal<string | null>(null);26+ const [pageIndex, setPageIndex] = createSignal(0);
24 const t = useT();27 const t = useT();
25 28
29+ // The scale is computed off every item, not just the visible page, so bars
30+ // don't rescale as the reader pages through them.
26 const maxValue = () => {31 const maxValue = () => {
27 if (props.maxScale != null && props.maxScale > 0) return props.maxScale;32 if (props.maxScale != null && props.maxScale > 0) return props.maxScale;
28 const itemMax = Math.max(...props.items.map((i) => i.value), 1);33 const itemMax = Math.max(...props.items.map((i) => i.value), 1);
29 return itemMax;34 return itemMax;
30 };35 };
31 36
37+ const pageCount = createMemo(() =>
38+ props.itemsPerPage ? Math.max(1, Math.ceil(props.items.length / props.itemsPerPage)) : 1,
39+ );
40+ // A refetch can shrink the item count out from under the current page.
41+ createEffect(() => {
42+ if (pageIndex() >= pageCount()) setPageIndex(Math.max(0, pageCount() - 1));
43+ });
44+ const visibleItems = createMemo(() => {
45+ if (!props.itemsPerPage) return props.items;
46+ const start = pageIndex() * props.itemsPerPage;
47+ return props.items.slice(start, start + props.itemsPerPage);
48+ });
49+
32 return (50 return (
33 <div class={cn("flex flex-col gap-4 rounded-lg border border-border bg-card p-4 shadow-sm", props.class)}>51 <div class={cn("flex flex-col gap-4 rounded-lg border border-border bg-card p-4 shadow-sm", props.class)}>
34 <Show when={props.title}>52 <Show when={props.title}>
@@ -52,47 +70,57 @@ export const ChartBar: Component<ChartBarProps> = (props) => {
52 }70 }
53 >71 >
54 <div class="space-y-3 pt-1">72 <div class="space-y-3 pt-1">
55- <For each={props.items}>73+ <For each={visibleItems()}>
56 {(item) => {74 {(item) => {
57 const pct = () => Math.min(100, Math.max(0, (item.value / maxValue()) * 100));75 const pct = () => Math.min(100, Math.max(0, (item.value / maxValue()) * 100));
58- const isHovered = () => hoveredId() === item.id;
59 76
60 return (77 return (
61- <div78+ // Tooltip stays permanently mounted and toggles via CSS group-hover
62- class="group relative space-y-1.5"79+ // opacity rather than a JS-driven Show — mounting/unmounting it on
63- onMouseEnter={() => setHoveredId(item.id)}80+ // every hover was the source of a visible jump for whichever item
64- onMouseLeave={() => setHoveredId(null)}81+ // sits at the bottom of the list, since that insert/remove briefly
65- >82+ // altered the card's content.
66- <div class="flex items-center justify-between text-xs">83+ <div class="group relative">
67- <span class="font-medium text-foreground/90 truncate max-w-[70%]">84+ <div class="space-y-1.5">
68- {item.label}85+ <div class="flex items-center justify-between text-xs">
69- </span>86+ <span class="font-medium text-foreground/90 truncate max-w-[70%]">
70- <span class="font-mono text-xs font-semibold tabular-nums text-foreground">87+ {item.label}
71- {item.formattedValue ?? item.value}88+ </span>
72- </span>89+ <span class="font-mono text-xs font-semibold tabular-nums text-foreground">
73- </div>90+ {item.formattedValue ?? item.value}
91+ </span>
92+ </div>
74 93
75- <div class="relative h-2.5 w-full overflow-hidden rounded-full bg-muted/60 dark:bg-muted/40">94+ <div class="relative h-2.5 w-full overflow-hidden rounded-full bg-muted/60 dark:bg-muted/40">
76- <div95+ <div
77- class={cn(96+ class={cn(
78- "h-full rounded-full transition-all duration-500 ease-out",97+ "h-full rounded-full transition-all duration-500 ease-out",
79- item.colorClass ?? "bg-primary",98+ item.colorClass ?? "bg-primary",
80- isHovered() && "brightness-110 shadow-xs",99+ "group-hover:brightness-110 group-hover:shadow-xs",
81- )}100+ )}
82- style={{ width: `${pct()}%` }}101+ style={{ width: `${pct()}%` }}
83- />102+ />
103+ </div>
84 </div>104 </div>
85 105
86- <Show when={isHovered()}>106+ <div class="pointer-events-none absolute -top-7 right-0 z-20 rounded-lg bg-popover px-2.5 py-1 text-[11px] font-medium text-popover-foreground opacity-0 shadow-md border border-border transition-opacity group-hover:opacity-100">
87- <div class="absolute -top-7 right-0 z-20 rounded-lg bg-popover px-2.5 py-1 text-[11px] font-medium text-popover-foreground shadow-md border border-border">107+ {item.label}: {item.formattedValue ?? item.value} ({Math.round(pct())}%)
88- {item.label}: {item.formattedValue ?? item.value} ({Math.round(pct())}%)108+ </div>
89- </div>
90- </Show>
91 </div>109 </div>
92 );110 );
93 }}111 }}
94 </For>112 </For>
95 </div>113 </div>
114+
115+ <Show when={props.itemsPerPage && pageCount() > 1}>
116+ <TablePagination
117+ pageIndex={pageIndex()}
118+ pageCount={pageCount()}
119+ pageSize={props.itemsPerPage!}
120+ total={props.items.length}
121+ onPageChange={setPageIndex}
122+ />
123+ </Show>
96 </Show>124 </Show>
97 </div>125 </div>
98 );126 );
src/components/ui/chart-progress-ring.tsxmodified+30 -2
@@ -1,5 +1,6 @@
1-import { For, Show, type Component } from "solid-js";1+import { For, Show, createEffect, createMemo, createSignal, type Component } from "solid-js";
2 import { cn } from "@/lib/cn";2 import { cn } from "@/lib/cn";
3+import { TablePagination } from "@/components/ui/table-pagination";
3 import { useT } from "@/stores/preferences-context";4 import { useT } from "@/stores/preferences-context";
4 5
5 export type ProgressRingSegment = {6 export type ProgressRingSegment = {
@@ -17,12 +18,29 @@ export type ChartProgressRingProps = {
17 segments: ProgressRingSegment[];18 segments: ProgressRingSegment[];
18 total?: number;19 total?: number;
19 class?: string;20 class?: string;
21+ /** When set and segments.length exceeds it, the legend is paged with Prev/Next controls. */
22+ itemsPerPage?: number;
20 };23 };
21 24
22 export const ChartProgressRing: Component<ChartProgressRingProps> = (props) => {25 export const ChartProgressRing: Component<ChartProgressRingProps> = (props) => {
23 const t = useT();26 const t = useT();
27+ const [pageIndex, setPageIndex] = createSignal(0);
28+ // The gauge bar above always renders every segment's share of the total —
29+ // only the legend cards below it are paged.
24 const calculatedTotal = () => props.total ?? props.segments.reduce((acc, s) => acc + s.value, 0);30 const calculatedTotal = () => props.total ?? props.segments.reduce((acc, s) => acc + s.value, 0);
25 31
32+ const pageCount = createMemo(() =>
33+ props.itemsPerPage ? Math.max(1, Math.ceil(props.segments.length / props.itemsPerPage)) : 1,
34+ );
35+ createEffect(() => {
36+ if (pageIndex() >= pageCount()) setPageIndex(Math.max(0, pageCount() - 1));
37+ });
38+ const visibleSegments = createMemo(() => {
39+ if (!props.itemsPerPage) return props.segments;
40+ const start = pageIndex() * props.itemsPerPage;
41+ return props.segments.slice(start, start + props.itemsPerPage);
42+ });
43+
26 return (44 return (
27 <div class={cn("flex flex-col gap-4 rounded-lg border border-border bg-card p-4 shadow-sm", props.class)}>45 <div class={cn("flex flex-col gap-4 rounded-lg border border-border bg-card p-4 shadow-sm", props.class)}>
28 <Show when={props.title}>46 <Show when={props.title}>
@@ -76,7 +94,7 @@ export const ChartProgressRing: Component<ChartProgressRingProps> = (props) => {
76 94
77 {/* Legend Grid */}95 {/* Legend Grid */}
78 <div class="grid grid-cols-2 gap-2 pt-1 sm:grid-cols-2">96 <div class="grid grid-cols-2 gap-2 pt-1 sm:grid-cols-2">
79- <For each={props.segments}>97+ <For each={visibleSegments()}>
80 {(segment) => (98 {(segment) => (
81 <div class="flex items-center justify-between rounded-xl border border-border/40 bg-muted/30 px-3 py-2 text-xs">99 <div class="flex items-center justify-between rounded-xl border border-border/40 bg-muted/30 px-3 py-2 text-xs">
82 <div class="flex items-center gap-2 truncate">100 <div class="flex items-center gap-2 truncate">
@@ -88,6 +106,16 @@ export const ChartProgressRing: Component<ChartProgressRingProps> = (props) => {
88 )}106 )}
89 </For>107 </For>
90 </div>108 </div>
109+
110+ <Show when={props.itemsPerPage && pageCount() > 1}>
111+ <TablePagination
112+ pageIndex={pageIndex()}
113+ pageCount={pageCount()}
114+ pageSize={props.itemsPerPage!}
115+ total={props.segments.length}
116+ onPageChange={setPageIndex}
117+ />
118+ </Show>
91 </div>119 </div>
92 </Show>120 </Show>
93 </div>121 </div>
src/pages/dashboard-page.tsxmodified+4 -0
@@ -352,6 +352,7 @@ function DashboardContent() {
352 subtitle={t("dashboard.courseAverages")}352 subtitle={t("dashboard.courseAverages")}
353 items={courseAverages()}353 items={courseAverages()}
354 maxScale={100}354 maxScale={100}
355+ itemsPerPage={5}
355 />356 />
356 </Show>357 </Show>
357 <Show when={role() !== "student"}>358 <Show when={role() !== "student"}>
@@ -360,6 +361,7 @@ function DashboardContent() {
360 title={t("dashboard.progressOverview")}361 title={t("dashboard.progressOverview")}
361 subtitle={t("dashboard.courseCapacities")}362 subtitle={t("dashboard.courseCapacities")}
362 items={courseCapacities()}363 items={courseCapacities()}
364+ itemsPerPage={5}
363 />365 />
364 </Show>366 </Show>
365 <Show when={role() === "student"}>367 <Show when={role() === "student"}>
@@ -367,6 +369,7 @@ function DashboardContent() {
367 title={t("dashboard.activitySplit")}369 title={t("dashboard.activitySplit")}
368 subtitle={t("dashboard.activitySplitDesc")}370 subtitle={t("dashboard.activitySplitDesc")}
369 segments={attendanceSegments()}371 segments={attendanceSegments()}
372+ itemsPerPage={3}
370 />373 />
371 </Show>374 </Show>
372 <Show when={role() !== "student"}>375 <Show when={role() !== "student"}>
@@ -374,6 +377,7 @@ function DashboardContent() {
374 title={t("dashboard.workloadSplit")}377 title={t("dashboard.workloadSplit")}
375 subtitle={t("dashboard.workloadSplitDesc")}378 subtitle={t("dashboard.workloadSplitDesc")}
376 segments={workloadSegments()}379 segments={workloadSegments()}
380+ itemsPerPage={3}
377 />381 />
378 </Show>382 </Show>
379 </div>383 </div>