Skip to content

Commit 6e118fc

Browse files
authored
Merge pull request DeusData#942 from DeusData/feat/ui-node-budget
graph-ui: node budget (up to 10M), scale rendering, and contrast controls
2 parents b2a592f + 8e65f8f commit 6e118fc

15 files changed

Lines changed: 1061 additions & 68 deletions
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { useEffect, useRef, useState } from "react";
2+
import { Button } from "@/components/ui/button";
3+
import {
4+
DEFAULT_DISPLAY_SETTINGS,
5+
DISPLAY_LIMITS,
6+
type DisplaySettings,
7+
} from "../lib/density";
8+
9+
interface DisplaySettingsMenuProps {
10+
settings: DisplaySettings;
11+
onChange: (next: DisplaySettings) => void;
12+
}
13+
14+
interface SliderRowProps {
15+
label: string;
16+
hint: string;
17+
value: number;
18+
min: number;
19+
max: number;
20+
onChange: (value: number) => void;
21+
}
22+
23+
function SliderRow({ label, hint, value, min, max, onChange }: SliderRowProps) {
24+
return (
25+
<label className="block">
26+
<div className="flex items-center justify-between mb-1">
27+
<span className="text-[11px] text-foreground/70">{label}</span>
28+
<span className="text-[10px] font-mono text-cyan-300/70 tabular-nums">
29+
{value.toFixed(2)}×
30+
</span>
31+
</div>
32+
<input
33+
type="range"
34+
min={min}
35+
max={max}
36+
step={0.05}
37+
value={value}
38+
onChange={(e) => onChange(parseFloat(e.target.value))}
39+
className="w-full accent-cyan-400 cursor-pointer"
40+
aria-label={`${label} (${hint})`}
41+
/>
42+
<p className="text-[9px] text-foreground/30 mt-0.5">{hint}</p>
43+
</label>
44+
);
45+
}
46+
47+
/* Contrast / brightness controls for the 3D graph. These ride on top of the
48+
* automatic density compensation — the defaults already adapt to graph size,
49+
* so 1.00× is "auto"; the sliders let the user push it. */
50+
export function DisplaySettingsMenu({
51+
settings,
52+
onChange,
53+
}: DisplaySettingsMenuProps) {
54+
const [open, setOpen] = useState(false);
55+
const rootRef = useRef<HTMLDivElement>(null);
56+
57+
/* Close on outside click / Escape */
58+
useEffect(() => {
59+
if (!open) return;
60+
const onDown = (e: MouseEvent) => {
61+
if (rootRef.current && !rootRef.current.contains(e.target as Node)) {
62+
setOpen(false);
63+
}
64+
};
65+
const onKey = (e: KeyboardEvent) => {
66+
if (e.key === "Escape") setOpen(false);
67+
};
68+
document.addEventListener("mousedown", onDown);
69+
document.addEventListener("keydown", onKey);
70+
return () => {
71+
document.removeEventListener("mousedown", onDown);
72+
document.removeEventListener("keydown", onKey);
73+
};
74+
}, [open]);
75+
76+
const set = (patch: Partial<DisplaySettings>) =>
77+
onChange({ ...settings, ...patch });
78+
79+
const isDefault =
80+
settings.edgeBrightness === DEFAULT_DISPLAY_SETTINGS.edgeBrightness &&
81+
settings.nodeGlow === DEFAULT_DISPLAY_SETTINGS.nodeGlow &&
82+
settings.bloom === DEFAULT_DISPLAY_SETTINGS.bloom;
83+
84+
return (
85+
<div ref={rootRef} className="relative">
86+
<Button
87+
variant="outline"
88+
size="sm"
89+
onClick={() => setOpen((v) => !v)}
90+
aria-expanded={open}
91+
aria-haspopup="dialog"
92+
title="Contrast & brightness"
93+
>
94+
Display{!isDefault && <span className="ml-1 text-cyan-300">•</span>}
95+
</Button>
96+
97+
{open && (
98+
<div
99+
role="dialog"
100+
aria-label="Display settings"
101+
className="absolute top-10 right-0 w-64 p-4 rounded-lg border border-border/60 bg-[#0b1920]/95 backdrop-blur-md shadow-xl z-20 space-y-3.5"
102+
>
103+
<div className="flex items-center justify-between">
104+
<span className="text-[11px] font-medium text-foreground/50 uppercase tracking-widest">
105+
Contrast
106+
</span>
107+
<button
108+
onClick={() => onChange(DEFAULT_DISPLAY_SETTINGS)}
109+
className="text-[10px] text-primary/70 hover:text-primary transition-colors disabled:opacity-30"
110+
disabled={isDefault}
111+
>
112+
Reset
113+
</button>
114+
</div>
115+
116+
<SliderRow
117+
label="Edge brightness"
118+
hint="Dim the web of links on dense graphs"
119+
value={settings.edgeBrightness}
120+
min={DISPLAY_LIMITS.edgeBrightness.min}
121+
max={DISPLAY_LIMITS.edgeBrightness.max}
122+
onChange={(edgeBrightness) => set({ edgeBrightness })}
123+
/>
124+
<SliderRow
125+
label="Node glow"
126+
hint="Halo boost around each node"
127+
value={settings.nodeGlow}
128+
min={DISPLAY_LIMITS.nodeGlow.min}
129+
max={DISPLAY_LIMITS.nodeGlow.max}
130+
onChange={(nodeGlow) => set({ nodeGlow })}
131+
/>
132+
<SliderRow
133+
label="Bloom"
134+
hint="Overall glow bloom strength"
135+
value={settings.bloom}
136+
min={DISPLAY_LIMITS.bloom.min}
137+
max={DISPLAY_LIMITS.bloom.max}
138+
onChange={(bloom) => set({ bloom })}
139+
/>
140+
141+
<p className="text-[9px] text-foreground/30 pt-1 border-t border-border/30">
142+
1.00× follows the automatic density compensation. Lower the
143+
edge/glow/bloom values when a large graph washes out to white.
144+
</p>
145+
</div>
146+
)}
147+
</div>
148+
);
149+
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { useMemo } from "react";
22
import * as THREE from "three";
33
import type { GraphNode, GraphEdge } from "../lib/types";
4+
import { edgeIntensityScale } from "../lib/density";
45

56
interface EdgeLinesProps {
67
nodes: GraphNode[];
78
edges: GraphEdge[];
89
highlightedIds: Set<number> | null;
910
opacity?: number;
11+
/* User edge-brightness multiplier (see DisplaySettings). Layered on top of
12+
* the automatic density scale. */
13+
brightness?: number;
1014
/* When set, edge.target is looked up in this array instead of `nodes`.
1115
* Used for cross-galaxy edges where source lives in the primary graph
1216
* and target lives in a linked project's offset-adjusted nodes. */
@@ -52,9 +56,13 @@ export function EdgeLines({
5256
edges,
5357
highlightedIds,
5458
opacity = 1.0,
59+
brightness = 1.0,
5560
targetNodes,
5661
}: EdgeLinesProps) {
5762
const geometry = useMemo(() => {
63+
/* Shrink per-edge glow as the edge count grows so the additively-blended
64+
* center doesn't saturate to white; the user multiplier rides on top. */
65+
const densityScale = edgeIntensityScale(edges.length) * brightness;
5866
const srcMap = new Map<number, number>();
5967
for (let i = 0; i < nodes.length; i++) {
6068
srcMap.set(nodes[i].id, i);
@@ -91,7 +99,11 @@ export function EdgeLines({
9199
* With additive blending + dark background, these glow nicely. */
92100
let intensity = sameCluster ? 0.25 : 0.06;
93101
if (hasHighlight) {
94-
intensity = sHL && tHL ? 0.5 : 0.04;
102+
/* A selection stays at full strength (never density-scaled) so it
103+
* pops against the dimmed rest; only the un-selected bulk is scaled. */
104+
intensity = sHL && tHL ? 0.5 : 0.04 * densityScale;
105+
} else {
106+
intensity *= densityScale;
95107
}
96108

97109
const off = validCount * 6;
@@ -125,7 +137,7 @@ export function EdgeLines({
125137
new THREE.BufferAttribute(colors.slice(0, validCount * 6), 3),
126138
);
127139
return geo;
128-
}, [nodes, edges, highlightedIds, targetNodes]);
140+
}, [nodes, edges, highlightedIds, targetNodes, brightness]);
129141

130142
return (
131143
<lineSegments geometry={geometry}>
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/GraphScene.tsx‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import { EdgeLines } from "./EdgeLines";
99
import { NodeLabels } from "./NodeLabels";
1010
import { NodeTooltip } from "./NodeTooltip";
1111
import type { GraphData, GraphNode, LinkedProject } from "../lib/types";
12+
import {
13+
DEFAULT_DISPLAY_SETTINGS,
14+
bloomIntensityScale,
15+
nodeBoostScale,
16+
type DisplaySettings,
17+
} from "../lib/density";
18+
19+
const BASE_BLOOM_INTENSITY = 1.45;
1220

1321
/* ── Camera fly-to animation ────────────────────────────── */
1422

@@ -107,6 +115,7 @@ interface GraphSceneProps {
107115
highlightedIds: Set<number> | null;
108116
cameraTarget: CameraTarget | null;
109117
showLabels: boolean;
118+
display?: DisplaySettings;
110119
onNodeClick: (node: GraphNode) => void;
111120
}
112121

@@ -117,11 +126,21 @@ export function GraphScene({
117126
highlightedIds,
118127
cameraTarget,
119128
showLabels,
129+
display = DEFAULT_DISPLAY_SETTINGS,
120130
onNodeClick,
121131
}: GraphSceneProps) {
122132
const [hovered, setHovered] = useState<GraphNode | null>(null);
123133
const controlsRef = useRef<OrbitControlsImpl | null>(null);
124134

135+
/* Adaptive density defaults × user multipliers. The automatic scale keeps
136+
* contrast roughly constant as the graph grows; the sliders nudge it.
137+
* NodeCloud applies `nodeBoost` directly (no internal density scaling),
138+
* whereas EdgeLines scales by edge density itself — so it receives only the
139+
* user edge-brightness multiplier to avoid double-applying. */
140+
const nodeBoost = nodeBoostScale(data.nodes.length) * display.nodeGlow;
141+
const bloomIntensity =
142+
BASE_BLOOM_INTENSITY * bloomIntensityScale(data.nodes.length) * display.bloom;
143+
125144
return (
126145
<Canvas
127146
camera={{ position: [0, 0, 800], fov: 50, near: 0.1, far: 100000 }}
@@ -146,12 +165,14 @@ export function GraphScene({
146165
nodes={data.nodes}
147166
edges={data.edges}
148167
highlightedIds={highlightedIds}
168+
brightness={display.edgeBrightness}
149169
/>
150170
<NodeCloud
151171
nodes={data.nodes}
152172
highlightedIds={highlightedIds}
153173
onHover={setHovered}
154174
onClick={onNodeClick}
175+
boost={nodeBoost}
155176
/>
156177
{showLabels && <NodeLabels nodes={data.nodes} highlightedIds={highlightedIds} />}
157178

@@ -170,13 +191,15 @@ export function GraphScene({
170191
edges={lp.edges}
171192
highlightedIds={null}
172193
opacity={0.3}
194+
brightness={display.edgeBrightness}
173195
/>
174196
<NodeCloud
175197
nodes={offsetNodes}
176198
highlightedIds={null}
177199
onHover={setHovered}
178200
onClick={onNodeClick}
179201
opacity={0.5}
202+
boost={nodeBoost}
180203
/>
181204
{/* Inter-galaxy CROSS_* edges: source is in primary, target in
182205
* this linked project's offset nodes. */}
@@ -187,6 +210,7 @@ export function GraphScene({
187210
edges={lp.cross_edges}
188211
highlightedIds={highlightedIds}
189212
opacity={0.85}
213+
brightness={display.edgeBrightness}
190214
/>
191215
)}
192216
</group>
@@ -202,7 +226,7 @@ export function GraphScene({
202226
<Bloom
203227
luminanceThreshold={0.3}
204228
luminanceSmoothing={0.7}
205-
intensity={1.2}
229+
intensity={bloomIntensity}
206230
mipmapBlur
207231
radius={0.6}
208232
/>

‎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

0 commit comments

Comments
 (0)