Skip to content

Commit 8e65f8f

Browse files
committed
feat(graph-ui): density-aware contrast + Display controls
High-density graphs washed out to a cyan-white blob: edges blend additively and the per-node boost rewarded luminance, so ~80k overlapping edges plus the white/yellow mid-tier stars saturated the center. Compensate by density so contrast stays roughly constant as the graph grows: - edges dim by ~1/sqrt(edgeCount) (they cause the blob) while nodes and bloom stay at full strength up to 25k nodes and only ease gently past that, so the bright-star look is preserved on moderate graphs; - the per-node glow is now colour-aware by channel dominance instead of luminance: blue hubs (high-degree) glow brightest, red leaves modestly, white/yellow least — matching the star-class meaning and giving the graph depth instead of a uniform white core. Add a Display menu (edge brightness / node glow / bloom multipliers, 0–3×, persisted) layered on top of the adaptive defaults, so the look is tunable live. A selection is never density-scaled and stays bright against the dimmed rest. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 9969253 commit 8e65f8f

7 files changed

Lines changed: 472 additions & 12 deletions

File tree

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

‎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.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import {
88
GRAPH_NODE_BUDGET_MAX,
99
} from "../hooks/useGraphData";
1010
import { GraphLoader } from "./GraphLoader";
11+
import { DisplaySettingsMenu } from "./DisplaySettingsMenu";
12+
import {
13+
loadDisplaySettings,
14+
saveDisplaySettings,
15+
type DisplaySettings,
16+
} from "../lib/density";
1117
import {
1218
GraphScene,
1319
computeCameraTarget,
@@ -65,6 +71,13 @@ export function GraphTab({ project }: GraphTabProps) {
6571
const [cameraTarget, setCameraTarget] = useState<CameraTarget | null>(null);
6672
const [repoInfo, setRepoInfo] = useState<RepoInfo | null>(null);
6773
const [showLabels, setShowLabels] = useState(true);
74+
const [display, setDisplay] = useState<DisplaySettings>(() =>
75+
loadDisplaySettings(),
76+
);
77+
const updateDisplay = useCallback((next: DisplaySettings) => {
78+
setDisplay(next);
79+
saveDisplaySettings(next);
80+
}, []);
6881
const [leftWidth, setLeftWidth] = useState(() => loadWidth("cbm-left-w", 260));
6982
const [rightWidth, setRightWidth] = useState(() => loadWidth("cbm-right-w", 280));
7083
const limitNotice = formatGraphLimitNotice(data);
@@ -375,6 +388,7 @@ export function GraphTab({ project }: GraphTabProps) {
375388
highlightedIds={highlightedIds}
376389
cameraTarget={cameraTarget}
377390
showLabels={showLabels}
391+
display={display}
378392
onNodeClick={handleNodeClick}
379393
/>
380394
</ErrorBoundary>
@@ -440,6 +454,7 @@ export function GraphTab({ project }: GraphTabProps) {
440454
title="How many nodes to load (5,000 steps, edges between loaded nodes follow automatically)"
441455
/>
442456
</div>
457+
<DisplaySettingsMenu settings={display} onChange={updateDisplay} />
443458
<Button
444459
variant="outline"
445460
size="sm"

0 commit comments

Comments
 (0)