Skip to content

Commit 9969253

Browse files
committed
feat(graph-ui): type-in node budget with live loading progress
Add a node-budget control next to Refresh: type any count (snapped to 5,000 steps, 5,000 default, 10M max) and the graph reloads with that many nodes plus every edge between them. The choice persists per project. Loading gets real feedback: the layout response streams with a live MB counter under an animated constellation (static under prefers-reduced-motion), replacing the bare spinner. Rendering scales with the budget: instance matrices are rebuilt only when the node set or highlight changes instead of every frame, sphere tessellation steps down as counts grow, and past 75k nodes the cloud switches to soft point sprites — one position per node — so six-figure budgets stay interactive. The truncation notice now names the loaded edge count and points at the budget control. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 926e818 commit 9969253

7 files changed

Lines changed: 528 additions & 57 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import type { LoadProgress } from "../hooks/useGraphData";
2+
3+
/* Small constellation whose nodes pulse and whose edges draw themselves in a
4+
* staggered loop — a miniature of the graph being loaded. Pure SVG/CSS
5+
* (keyframes in globals.css) so it costs nothing while the real payload
6+
* streams in, and it degrades to a static constellation under
7+
* prefers-reduced-motion. */
8+
9+
const LOADER_NODES: Array<{ cx: number; cy: number; r: number; delay: string }> = [
10+
{ cx: 60, cy: 18, r: 5, delay: "0s" },
11+
{ cx: 22, cy: 42, r: 4, delay: "0.35s" },
12+
{ cx: 98, cy: 40, r: 4, delay: "0.7s" },
13+
{ cx: 42, cy: 78, r: 4.5, delay: "1.05s" },
14+
{ cx: 84, cy: 82, r: 3.5, delay: "1.4s" },
15+
{ cx: 60, cy: 52, r: 6, delay: "0.15s" },
16+
{ cx: 14, cy: 88, r: 3, delay: "1.75s" },
17+
];
18+
19+
const LOADER_EDGES: Array<{ x1: number; y1: number; x2: number; y2: number; delay: string }> = [
20+
{ x1: 60, y1: 18, x2: 60, y2: 52, delay: "0s" },
21+
{ x1: 22, y1: 42, x2: 60, y2: 52, delay: "0.3s" },
22+
{ x1: 98, y1: 40, x2: 60, y2: 52, delay: "0.6s" },
23+
{ x1: 42, y1: 78, x2: 60, y2: 52, delay: "0.9s" },
24+
{ x1: 84, y1: 82, x2: 60, y2: 52, delay: "1.2s" },
25+
{ x1: 42, y1: 78, x2: 14, y2: 88, delay: "1.5s" },
26+
{ x1: 22, y1: 42, x2: 60, y2: 18, delay: "1.8s" },
27+
];
28+
29+
function formatMegabytes(bytes: number): string {
30+
return (bytes / (1024 * 1024)).toFixed(1);
31+
}
32+
33+
interface GraphLoaderProps {
34+
nodeBudget: number;
35+
progress: LoadProgress;
36+
}
37+
38+
export function GraphLoader({ nodeBudget, progress }: GraphLoaderProps) {
39+
const receiving = progress.receivedBytes > 0;
40+
return (
41+
<div className="text-center" role="status" aria-live="polite">
42+
<svg
43+
width="120"
44+
height="104"
45+
viewBox="0 0 120 104"
46+
className="mx-auto"
47+
aria-hidden="true"
48+
>
49+
{LOADER_EDGES.map((e, i) => (
50+
<line
51+
key={`e${i}`}
52+
x1={e.x1}
53+
y1={e.y1}
54+
x2={e.x2}
55+
y2={e.y2}
56+
className="graph-loader-edge"
57+
style={{ animationDelay: e.delay }}
58+
/>
59+
))}
60+
{LOADER_NODES.map((n, i) => (
61+
<circle
62+
key={`n${i}`}
63+
cx={n.cx}
64+
cy={n.cy}
65+
r={n.r}
66+
className="graph-loader-node"
67+
style={{ animationDelay: n.delay }}
68+
/>
69+
))}
70+
</svg>
71+
<p className="text-white/50 text-sm mt-4">
72+
{receiving ? "Receiving graph" : "Computing layout"} — up to{" "}
73+
{nodeBudget.toLocaleString("en-US")} nodes
74+
</p>
75+
<p className="text-cyan-300/60 text-xs font-mono mt-1 h-4">
76+
{receiving
77+
? progress.totalBytes
78+
? `${formatMegabytes(progress.receivedBytes)} of ${formatMegabytes(progress.totalBytes)} MB`
79+
: `${formatMegabytes(progress.receivedBytes)} MB received`
80+
: " "}
81+
</p>
82+
</div>
83+
);
84+
}

‎graph-ui/src/components/GraphTab.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("formatGraphLimitNotice", () => {
2020
} satisfies GraphData;
2121

2222
expect(formatGraphLimitNotice(data)).toBe(
23-
"Showing 2,000 of 43,729 nodes. Use filters to narrow.",
23+
"Showing 2,000 of 43,729 nodes (0 edges). Raise the node budget or use filters.",
2424
);
2525
});
2626

‎graph-ui/src/components/GraphTab.tsx‎

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { useEffect, useState, useCallback, useMemo } from "react";
22
import { Button } from "@/components/ui/button";
3-
import { useGraphData } from "../hooks/useGraphData";
3+
import {
4+
useGraphData,
5+
clampNodeBudget,
6+
GRAPH_RENDER_NODE_LIMIT,
7+
GRAPH_NODE_BUDGET_STEP,
8+
GRAPH_NODE_BUDGET_MAX,
9+
} from "../hooks/useGraphData";
10+
import { GraphLoader } from "./GraphLoader";
411
import {
512
GraphScene,
613
computeCameraTarget,
@@ -26,17 +33,32 @@ function saveWidth(key: string, value: number) {
2633
try { localStorage.setItem(key, String(Math.round(value))); } catch { /* ignore */ }
2734
}
2835

36+
/* Persist the node budget per project */
37+
function budgetKey(project: string): string {
38+
return `cbm-node-budget:${project}`;
39+
}
40+
function loadNodeBudget(project: string): number {
41+
try {
42+
const v = localStorage.getItem(budgetKey(project));
43+
if (v) return clampNodeBudget(parseInt(v, 10));
44+
} catch { /* ignore */ }
45+
return GRAPH_RENDER_NODE_LIMIT;
46+
}
47+
function saveNodeBudget(project: string, value: number) {
48+
try { localStorage.setItem(budgetKey(project), String(value)); } catch { /* ignore */ }
49+
}
50+
2951
interface GraphTabProps {
3052
project: string | null;
3153
}
3254

3355
export function formatGraphLimitNotice(data: GraphData | null): string | null {
3456
if (!data || data.total_nodes <= data.nodes.length) return null;
35-
return `Showing ${data.nodes.length.toLocaleString("en-US")} of ${data.total_nodes.toLocaleString("en-US")} nodes. Use filters to narrow.`;
57+
return `Showing ${data.nodes.length.toLocaleString("en-US")} of ${data.total_nodes.toLocaleString("en-US")} nodes (${data.edges.length.toLocaleString("en-US")} edges). Raise the node budget or use filters.`;
3658
}
3759

3860
export function GraphTab({ project }: GraphTabProps) {
39-
const { data, loading, error, fetchOverview } = useGraphData();
61+
const { data, loading, error, progress, fetchOverview } = useGraphData();
4062
const [highlightedIds, setHighlightedIds] = useState<Set<number> | null>(null);
4163
const [selectedPath, setSelectedPath] = useState<string | null>(null);
4264
const [selectedNode, setSelectedNode] = useState<GraphNode | null>(null);
@@ -47,6 +69,22 @@ export function GraphTab({ project }: GraphTabProps) {
4769
const [rightWidth, setRightWidth] = useState(() => loadWidth("cbm-right-w", 280));
4870
const limitNotice = formatGraphLimitNotice(data);
4971

72+
/* Node budget — keyed to its project so switching projects re-reads the
73+
* persisted value and triggers exactly one fetch. */
74+
const [budget, setBudget] = useState<{ project: string | null; value: number }>(
75+
{ project: null, value: GRAPH_RENDER_NODE_LIMIT },
76+
);
77+
const [budgetDraft, setBudgetDraft] = useState(String(GRAPH_RENDER_NODE_LIMIT));
78+
79+
const commitBudget = useCallback(() => {
80+
const parsed = clampNodeBudget(parseInt(budgetDraft, 10));
81+
setBudgetDraft(String(parsed));
82+
if (project && parsed !== budget.value) {
83+
saveNodeBudget(project, parsed);
84+
setBudget({ project, value: parsed });
85+
}
86+
}, [budgetDraft, project, budget.value]);
87+
5088
/* Filter state — all enabled by default */
5189
const [enabledLabels, setEnabledLabels] = useState<Set<string>>(new Set());
5290
const [enabledEdgeTypes, setEnabledEdgeTypes] = useState<Set<string>>(new Set());
@@ -121,13 +159,23 @@ export function GraphTab({ project }: GraphTabProps) {
121159
hideTests,
122160
]);
123161

162+
/* Re-read the persisted budget when the project changes… */
124163
useEffect(() => {
125164
if (project) {
126-
fetchOverview(project);
165+
const value = loadNodeBudget(project);
166+
setBudget({ project, value });
167+
setBudgetDraft(String(value));
168+
}
169+
}, [project]);
170+
171+
/* …and fetch only once budget and project agree (one fetch per change). */
172+
useEffect(() => {
173+
if (project && budget.project === project) {
174+
fetchOverview(project, budget.value);
127175
setHighlightedIds(null);
128176
setSelectedPath(null);
129177
}
130-
}, [project, fetchOverview]);
178+
}, [project, budget, fetchOverview]);
131179

132180
/* Fetch git remote metadata for GitHub deep-links */
133181
useEffect(() => {
@@ -236,10 +284,7 @@ export function GraphTab({ project }: GraphTabProps) {
236284
if (loading) {
237285
return (
238286
<div className="flex items-center justify-center h-full">
239-
<div className="text-center">
240-
<div className="w-8 h-8 border-2 border-cyan-400/30 border-t-cyan-400 rounded-full animate-spin mx-auto mb-3" />
241-
<p className="text-white/40 text-sm">Computing layout...</p>
242-
</div>
287+
<GraphLoader nodeBudget={budget.value} progress={progress} />
243288
</div>
244289
);
245290
}
@@ -355,7 +400,7 @@ export function GraphTab({ project }: GraphTabProps) {
355400
)}
356401
</div>
357402

358-
<div className="absolute top-4 right-4 flex gap-2">
403+
<div className="absolute top-4 right-4 flex gap-2 items-center">
359404
{highlightedIds && (
360405
<Button
361406
size="sm"
@@ -369,6 +414,32 @@ export function GraphTab({ project }: GraphTabProps) {
369414
Clear selection
370415
</Button>
371416
)}
417+
<div className="flex items-center gap-1.5 h-8 px-2 rounded-md border border-border/50 bg-[#0b1920]/80 backdrop-blur-sm">
418+
<label
419+
htmlFor="node-budget"
420+
className="text-[10px] uppercase tracking-wider text-white/40"
421+
>
422+
Nodes
423+
</label>
424+
<input
425+
id="node-budget"
426+
type="number"
427+
min={GRAPH_NODE_BUDGET_STEP}
428+
max={GRAPH_NODE_BUDGET_MAX}
429+
step={GRAPH_NODE_BUDGET_STEP}
430+
value={budgetDraft}
431+
onChange={(e) => setBudgetDraft(e.target.value)}
432+
onBlur={commitBudget}
433+
onKeyDown={(e) => {
434+
if (e.key === "Enter") {
435+
e.currentTarget.blur();
436+
}
437+
}}
438+
className="w-24 bg-transparent text-right text-xs font-mono text-cyan-200/90 outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
439+
aria-label="Node budget: how many nodes to load"
440+
title="How many nodes to load (5,000 steps, edges between loaded nodes follow automatically)"
441+
/>
442+
</div>
372443
<Button
373444
variant="outline"
374445
size="sm"
@@ -377,7 +448,7 @@ export function GraphTab({ project }: GraphTabProps) {
377448
setSelectedPath(null);
378449
setSelectedNode(null);
379450
setCameraTarget(null);
380-
fetchOverview(project);
451+
fetchOverview(project, budget.value);
381452
}}
382453
>
383454
Refresh

0 commit comments

Comments
 (0)