Overview
TheNodeComponent renders an individual interest as an interactive 3D sphere with a text label. It handles hover effects, click interactions, and maintains billboard text orientation.
Component Signature
Props
The interest node data to render. Contains position, color, radius, label, and ID.
Callback function triggered when the node is clicked. Receives the node’s ID and label for expansion.
Visual Structure
Sphere Mesh
- Geometry: Sphere with 32 segments (smooth)
- Material: Standard material with no metalness, full roughness (matte finish)
- Color: Node’s color from store (random from palette)
- Hover: Changes to white (#ffffff) on pointer over
- Radius: 1.2 for root nodes, 0.6 for child nodes
Text Label
- Position: Below sphere (y - radius - 0.5)
- Orientation: Billboard effect (always faces camera)
- Style: White color with black outline (0.02 width)
- Size: 0.4 units
- Anchor: Center aligned
Internal State
Tracks whether the node is currently being hovered over by the mouse pointer.
Refs
Reference to the sphere mesh for direct position updates in useFrame
Reference to the text group for position and rotation updates (billboard effect)
Frame Updates
The component usesuseFrame to update positions every frame:
- Node positions are updated by physics engine
- Text must maintain billboard orientation as camera moves
- Ensures smooth animations and interactions
Interaction Handlers
onClick
- Stops event propagation to prevent triggering parent handlers
- Calls
onExpandcallback with node ID and label - Triggers AI generation for sub-interests
onPointerOver / onPointerOut
- Updates hover state for visual feedback
- Changes sphere color to white when hovered
- Provides clear indication of interactivity
Material Properties
Dynamic color based on hover state. White when hovered, otherwise node’s assigned color.
Full roughness creates a matte, non-reflective surface.
No metallic properties for a soft, organic look.
Text Rendering
The text uses@react-three/drei’s Text component:
- fontSize: 0.4 units for readable labels
- color: White for high contrast
- anchor: Center alignment ensures text is centered below sphere
- outline: Black outline improves readability against varying backgrounds
- renderOrder: 1 to ensure text renders on top
Usage Example
Performance Considerations
- Each node updates position every frame (necessary for physics)
- Text billboard rotation updates every frame (necessary for camera tracking)
- Hover state updates trigger re-renders (minimal impact)
- Consider LOD (Level of Detail) for very large graphs (100+ nodes)
Accessibility
- Visual hover feedback (color change)
- Click interactions clearly indicated by cursor change
- Text labels provide context
- Consider adding keyboard navigation for accessibility improvements
Related Components
- ThreeGraph - Parent component that manages all nodes
- Interest Store - State management for node data
Source Code Location
components/ThreeGraph.tsx:10-67