Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: finish the graph3d extraction — shared touch-hint and tooltip-clamp, drop dead motion field (#6828)

[._.]/ Adam Eivy9e011eb32895
diff --git a/client/src/components/brain/tabs/BrainGraph.jsx b/client/src/components/brain/tabs/BrainGraph.jsx
index 8b0ce2d0fb..5e3e2b691b 100644
--- a/client/src/components/brain/tabs/BrainGraph.jsx
+++ b/client/src/components/brain/tabs/BrainGraph.jsx
@@ -10,6 +10,7 @@ import { buildGraph } from '../../../lib/graphSimulation';
import { pushFocus, popFocus, currentFocusId } from '../../../lib/brainGraphFocus';
import GraphScene, { graphMotionSettings } from '../../graph3d/GraphScene';
import useGraphCanvasInteraction from '../../graph3d/useGraphCanvasInteraction';
+import TouchDragHint from '../../graph3d/TouchDragHint';
import EntityCombobox from '../../EntityCombobox';
import InlineConfirmRow from '../../ui/InlineConfirmRow';
import BrailleSpinner from '../../BrailleSpinner';
@@ -24,10 +25,12 @@ const EDGE_COLORS = {
const BRAIN_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'songs', 'goals', 'journals'];
-// Scene-appearance callbacks handed to the shared graph3d/GraphScene —
-// exported so the extraction's behavior split from MemoryGraph's own flat
-// blue/gray palette is pinned directly (see BrainGraph.test.jsx).
-export const brainNodeColor = (node) => BRAIN_TYPE_HEX[node.brainType] || '#6b7280';
+// Scene-appearance callbacks handed to the shared graph3d/GraphScene.
+// brainEdgeColor/brainEdgeIntensity are exported so the extraction's
+// behavior split from MemoryGraph's own flat blue/gray palette is pinned
+// directly (see BrainGraph.test.jsx); brainNodeColor is a plain lookup with
+// no distinct per-page behavior worth pinning, so it stays module-private.
+const brainNodeColor = (node) => BRAIN_TYPE_HEX[node.brainType] || '#6b7280';
export const brainEdgeColor = (edge) => EDGE_COLORS[edge.type] || '#6b7280';
export const brainEdgeIntensity = (edge, dimmed) =>
dimmed ? 0.06 : (edge.type === 'linked' ? 0.6 : 0.3 * (edge.weight || 0.5));
@@ -47,11 +50,6 @@ export const brainEdgeIntensity = (edge, dimmed) =>
*/
const brainTypeChipStyle = (brainType, mode) => chipColors(BRAIN_TYPE_HEX[brainType], mode) || undefined;
-// Widest the hover tooltip renders. Single source for both its max-width and
-// the clamp that keeps it inside the viewport — as a CSS class plus a mirrored
-// constant the two silently drift apart.
-const TOOLTIP_WIDTH = 320;
-
// Per-type API getters for detail panel
const TYPE_GETTERS = {
people: api.getBrainPerson,
@@ -227,7 +225,7 @@ export default function BrainGraph() {
pickRef,
touchGestureRef,
hoveredNode,
- tooltipPos,
+ tooltipStyle,
handleHover,
handlePointerMove,
touchHintVisible,
@@ -494,15 +492,7 @@ export default function BrainGraph() {
</Canvas>
)}
- {touchHintVisible && (
- <div
- role="status"
- aria-live="polite"
- className="absolute top-3 inset-x-3 z-20 flex justify-center pointer-events-none"
- >
- <span className="port-media-overlay rounded-lg px-3 py-2 text-xs">Drag to rotate</span>
- </div>
- )}
+ <TouchDragHint visible={touchHintVisible} />
{!graph && (
<div className="flex items-center justify-center h-full text-gray-500 text-sm">
@@ -585,16 +575,13 @@ export default function BrainGraph() {
preview with — a tap selects the node and the detail panel below
already shows the same record — and it would otherwise flash under
the user's own finger advertising a double-click touch can't do.
- Position is clamped so it can't run off the right edge of a narrow
- window, where `x + 12` alone would clip the label. */}
+ Position is clamped (useGraphCanvasInteraction's `tooltipStyle`) so
+ it can't run off the right edge of a narrow window, where `x + 12`
+ alone would clip the label. */}
{hoveredNode && (
<div
className="fixed z-50 pointer-events-none pointer-coarse:hidden bg-port-bg border border-port-border rounded-lg px-3 py-2 shadow-lg"
- style={{
- maxWidth: TOOLTIP_WIDTH,
- left: Math.max(8, Math.min(tooltipPos.x + 12, window.innerWidth - TOOLTIP_WIDTH - 8)),
- top: Math.max(8, tooltipPos.y - 12)
- }}
+ style={tooltipStyle}
>
<div className="flex items-center gap-2 mb-1">
<span
diff --git a/client/src/components/cos/tabs/MemoryGraph.jsx b/client/src/components/cos/tabs/MemoryGraph.jsx
index 0d447be16e..c7903336af 100644
--- a/client/src/components/cos/tabs/MemoryGraph.jsx
+++ b/client/src/components/cos/tabs/MemoryGraph.jsx
@@ -6,15 +6,11 @@ import { MEMORY_TYPES, MEMORY_TYPE_COLORS } from '../constants';
import { buildGraph } from '../../../lib/graphSimulation';
import GraphScene, { graphMotionSettings } from '../../graph3d/GraphScene';
import useGraphCanvasInteraction from '../../graph3d/useGraphCanvasInteraction';
+import TouchDragHint from '../../graph3d/TouchDragHint';
import BrailleSpinner from '../../BrailleSpinner';
import usePrefersReducedMotion from '../../../hooks/usePrefersReducedMotion';
import { formatDateNumeric } from '../../../utils/formatters';
-// Widest the hover tooltip renders. Single source for both its max-width and
-// the clamp that keeps it inside the viewport — as a CSS class plus a mirrored
-// constant the two silently drift apart.
-const TOOLTIP_WIDTH = 320;
-
const TYPE_HEX = {
fact: '#3b82f6',
learning: '#22c55e',
@@ -24,12 +20,15 @@ const TYPE_HEX = {
context: '#6b7280'
};
-// Scene-appearance callbacks handed to the shared graph3d/GraphScene —
-// exported so the extraction's behavior split from BrainGraph's own
-// per-edge-type palette and weight fallback is pinned directly (see
-// MemoryGraph.test.jsx). Unlike BrainGraph, every edge kind here scales by
-// weight (including "linked", which BrainGraph holds at a flat intensity).
-export const memoryNodeColor = (node) => TYPE_HEX[node.type] || '#6b7280';
+// Scene-appearance callbacks handed to the shared graph3d/GraphScene.
+// memoryEdgeColor/memoryEdgeIntensity are exported so the extraction's
+// behavior split from BrainGraph's own per-edge-type palette and weight
+// fallback is pinned directly (see MemoryGraph.test.jsx) — unlike BrainGraph,
+// every edge kind here scales by weight (including "linked", which
+// BrainGraph holds at a flat intensity). memoryNodeColor is a plain lookup
+// with no distinct per-page behavior worth pinning, so it stays
+// module-private.
+const memoryNodeColor = (node) => TYPE_HEX[node.type] || '#6b7280';
export const memoryEdgeColor = (edge) => (edge.type === 'linked' ? '#3b82f6' : '#6b7280');
export const memoryEdgeIntensity = (edge, dimmed) =>
dimmed ? 0.06 : (edge.type === 'linked' ? 0.6 * edge.weight : 0.3 * edge.weight);
@@ -106,7 +105,7 @@ export default function MemoryGraph() {
pickRef,
touchGestureRef,
hoveredNode,
- tooltipPos,
+ tooltipStyle,
handleHover,
handlePointerMove,
touchHintVisible,
@@ -182,15 +181,7 @@ export default function MemoryGraph() {
</Canvas>
)}
- {touchHintVisible && (
- <div
- role="status"
- aria-live="polite"
- className="absolute top-3 inset-x-3 z-20 flex justify-center pointer-events-none"
- >
- <span className="port-media-overlay rounded-lg px-3 py-2 text-xs">Drag to rotate</span>
- </div>
- )}
+ <TouchDragHint visible={touchHintVisible} />
{/* Legend. Its ~200px blankets a short canvas, so it auto-shows only on
a `roomy-viewport` (wide AND tall — see index.css); otherwise it
@@ -244,16 +235,14 @@ export default function MemoryGraph() {
{/* Hover tooltip. Suppressed on a coarse pointer: there is no hover to
preview with — a tap selects the node and the detail panel below
already shows the same record — and it would otherwise flash under
- the user's own finger. Position is clamped so it can't run off the
- right edge of a narrow window, where `x + 12` alone would clip it. */}
+ the user's own finger. Position is clamped
+ (useGraphCanvasInteraction's `tooltipStyle`) so it can't run off
+ the right edge of a narrow window, where `x + 12` alone would clip
+ it. */}
{hoveredNode && (
<div
className="fixed z-50 pointer-events-none pointer-coarse:hidden bg-port-bg border border-port-border rounded-lg px-3 py-2 shadow-lg"
- style={{
- maxWidth: TOOLTIP_WIDTH,
- left: Math.max(8, Math.min(tooltipPos.x + 12, window.innerWidth - TOOLTIP_WIDTH - 8)),
- top: Math.max(8, tooltipPos.y - 12)
- }}
+ style={tooltipStyle}
>
<div className="flex items-center gap-2 mb-1">
<span className={`px-1.5 py-0.5 text-[10px] rounded-full border ${MEMORY_TYPE_COLORS[hoveredNode.type] || 'border-port-border text-gray-400'}`}>
diff --git a/client/src/components/graph3d/GraphScene.jsx b/client/src/components/graph3d/GraphScene.jsx
index 35e822befc..899f5834ed 100644
--- a/client/src/components/graph3d/GraphScene.jsx
+++ b/client/src/components/graph3d/GraphScene.jsx
@@ -6,16 +6,19 @@ import GraphEdges from './GraphEdges';
import { pickNearestNodeByScreenDistance } from '../../lib/graphPicking';
// The force layout is settled before the scene renders, so reduced-motion
-// users can see it immediately at rest. Keep the canvas on demand and turn
-// off OrbitControls' inertia too, preventing movement after an interaction.
-// Canonical home for both graph pages — call from the page that owns the
-// <Canvas> to size its `frameloop` prop; GraphScene reads `reducedMotion`
-// directly for its own OrbitControls damping.
+// users can see it immediately at rest: keep the canvas on demand instead of
+// running its render loop every frame. Canonical home for both graph pages —
+// call from the page that owns the <Canvas> to size its `frameloop` prop.
+// GraphScene reads `reducedMotion` directly for its own OrbitControls
+// damping below, rather than through this helper.
export const graphMotionSettings = (reducedMotion) => ({
- frameloop: reducedMotion ? 'demand' : 'always',
- enableDamping: !reducedMotion
+ frameloop: reducedMotion ? 'demand' : 'always'
});
+// Sphere radius for a node's importance — also used, +0.2, for the
+// wireframe halo around the selected node below.
+const nodeRadius = (node) => 0.4 + (node.importance ?? 0.5) * 0.8;
+
// Memoized: the container's onPointerMove re-renders the owning page on every
// mouse move over the canvas WHILE A NODE IS HOVERED (it tracks the tooltip
// position), and every prop here is already identity-stable across that
@@ -39,7 +42,7 @@ const GraphScene = memo(function GraphScene({
const { camera, size } = useThree();
const selNode = selectedId ? graph.idMap.get(selectedId) : null;
- const selRadius = selNode ? 0.4 + (selNode.importance ?? 0.5) * 0.8 : 0;
+ const selRadius = selNode ? nodeRadius(selNode) : 0;
// Publish a live screen-space pick to the DOM wrapper, which owns the touch
// gesture (see useGraphCanvasInteraction). The camera object is stable
@@ -76,7 +79,7 @@ const GraphScene = memo(function GraphScene({
/>
{graph.simNodes.map(node => {
- const radius = 0.4 + (node.importance ?? 0.5) * 0.8;
+ const radius = nodeRadius(node);
const color = nodeColor(node);
const isSelected = node.id === selectedId;
const isConnected = adjacentIds?.has(node.id);
diff --git a/client/src/components/graph3d/GraphScene.test.jsx b/client/src/components/graph3d/GraphScene.test.jsx
index ad6f506483..507a57498f 100644
--- a/client/src/components/graph3d/GraphScene.test.jsx
+++ b/client/src/components/graph3d/GraphScene.test.jsx
@@ -66,11 +66,11 @@ describe('reduced motion', () => {
});
describe('graphMotionSettings', () => {
- it('stops the canvas render loop and OrbitControls inertia when motion is reduced', () => {
- expect(graphMotionSettings(true)).toEqual({ frameloop: 'demand', enableDamping: false });
+ it('runs the canvas render loop on demand when motion is reduced', () => {
+ expect(graphMotionSettings(true)).toEqual({ frameloop: 'demand' });
});
- it('keeps animated rendering and controls for users without the preference', () => {
- expect(graphMotionSettings(false)).toEqual({ frameloop: 'always', enableDamping: true });
+ it('keeps the canvas animating for users without the preference', () => {
+ expect(graphMotionSettings(false)).toEqual({ frameloop: 'always' });
});
});
diff --git a/client/src/components/graph3d/TouchDragHint.jsx b/client/src/components/graph3d/TouchDragHint.jsx
new file mode 100644
index 0000000000..7c7be13813
--- /dev/null
+++ b/client/src/components/graph3d/TouchDragHint.jsx
@@ -0,0 +1,18 @@
+/**
+ * "Drag to rotate" hint shown once when a graph canvas first receives a touch
+ * gesture (see `useFirstTouchHint`, wired through `useGraphCanvasInteraction`'s
+ * `touchHintVisible`). Identical chrome on both graph pages — BrainGraph and
+ * MemoryGraph — so it lives here instead of being copy-pasted per page.
+ */
+export default function TouchDragHint({ visible }) {
+ if (!visible) return null;
+ return (
+ <div
+ role="status"
+ aria-live="polite"
+ className="absolute top-3 inset-x-3 z-20 flex justify-center pointer-events-none"
+ >
+ <span className="port-media-overlay rounded-lg px-3 py-2 text-xs">Drag to rotate</span>
+ </div>
+ );
+}
diff --git a/client/src/components/graph3d/useGraphCanvasInteraction.js b/client/src/components/graph3d/useGraphCanvasInteraction.js
index 5c3ad2321f..03b4218367 100644
--- a/client/src/components/graph3d/useGraphCanvasInteraction.js
+++ b/client/src/components/graph3d/useGraphCanvasInteraction.js
@@ -12,12 +12,28 @@ import { isTapGesture } from '../../lib/graphPicking';
// this problem.)
const isCanvasGesture = (e) => e.target?.tagName === 'CANVAS';
+// Widest the hover tooltip renders. Single source for both its max-width and
+// the clamp that keeps it inside the viewport — as a CSS class plus a
+// mirrored constant the two would silently drift apart.
+const TOOLTIP_WIDTH = 320;
+
+// Clamp the hover tooltip to the viewport: an unclamped `x + 12`/`y - 12`
+// can push it past the right edge on a narrow window, or above the top on a
+// low hover. Both graph pages render page-specific content (badge, summary)
+// inside this same clamp, so the positioning is computed once here rather
+// than copied per page.
+const clampTooltipStyle = (pos) => ({
+ maxWidth: TOOLTIP_WIDTH,
+ left: Math.max(8, Math.min(pos.x + 12, window.innerWidth - TOOLTIP_WIDTH - 8)),
+ top: Math.max(8, pos.y - 12)
+});
+
/**
* Pointer/tap/tooltip wiring shared by the 3D graph scenes (BrainGraph,
* MemoryGraph): tells a canvas tap from an orbit drag, resolves a touch tap
* to the nearest node via the wrapper-owned screen-space pick (see
* lib/graphPicking.js and GraphScene's `pickRef`), and tracks the hover
- * tooltip position.
+ * tooltip position and its viewport-clamped style.
*
* `onSelect` is called with the picked node to select it, or `null` to clear
* the selection — the same null-safe contract each page's own `handleSelect`
@@ -79,7 +95,7 @@ export default function useGraphCanvasInteraction({ onSelect }) {
pickRef,
touchGestureRef,
hoveredNode,
- tooltipPos,
+ tooltipStyle: clampTooltipStyle(tooltipPos),
handleHover,
handlePointerMove,
touchHintVisible,