@@ -54,7 +54,7 @@ type GraphNode = NodeObject & {
5454
5555export function MemoryGraph ( { className, height = 400 , width } : MemoryGraphProps ) {
5656 const containerRef = useRef < HTMLDivElement > ( null ) ;
57- const graphRef = useRef < ForceGraphMethods | null > ( null ) ;
57+ const graphRef = useRef < ForceGraphMethods | undefined > ( undefined ) ;
5858 const [ dimensions , setDimensions ] = useState ( { width : width || 400 , height } ) ;
5959 const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
6060 const [ selectedCategory , setSelectedCategory ] = useState < MemoryNodeCategory | null > ( null ) ;
@@ -118,20 +118,22 @@ export function MemoryGraph({ className, height = 400, width }: MemoryGraphProps
118118
119119 // Custom node rendering
120120 const nodeCanvasObject = useCallback (
121- ( node : GraphNode , ctx : CanvasRenderingContext2D , globalScale : number ) => {
121+ ( node : NodeObject , ctx : CanvasRenderingContext2D , globalScale : number ) => {
122122 if ( typeof node . x !== 'number' || typeof node . y !== 'number' ) return ;
123- const label = node . name ;
123+ const label = typeof node . name === 'string' ? node . name : '' ;
124124 const fontSize = 12 / globalScale ;
125125 const nodeRadius = 8 ;
126126
127127 // Draw node circle
128128 ctx . beginPath ( ) ;
129129 ctx . arc ( node . x , node . y , nodeRadius , 0 , 2 * Math . PI ) ;
130- ctx . fillStyle = node . color ;
130+ ctx . fillStyle = typeof node . color === 'string' ? node . color : '#8b5cf6' ;
131131 ctx . fill ( ) ;
132132
133133 // Draw border
134- ctx . strokeStyle = categoryColors [ node . category as MemoryNodeCategory ] . border ;
134+ const category =
135+ typeof node . category === 'string' ? ( node . category as MemoryNodeCategory ) : null ;
136+ ctx . strokeStyle = category ? categoryColors [ category ] . border : 'rgba(255,255,255,0.3)' ;
135137 ctx . lineWidth = 2 / globalScale ;
136138 ctx . stroke ( ) ;
137139
@@ -147,8 +149,11 @@ export function MemoryGraph({ className, height = 400, width }: MemoryGraphProps
147149
148150 // Handle node click
149151 const handleNodeClick = useCallback (
150- ( node : GraphNode ) => {
151- selectNode ( node . id ) ;
152+ ( node : NodeObject ) => {
153+ const nodeId =
154+ typeof node . id === 'number' ? node . id . toString ( ) : typeof node . id === 'string' ? node . id : null ;
155+ if ( ! nodeId ) return ;
156+ selectNode ( nodeId ) ;
152157 // Center on node
153158 if ( graphRef . current && typeof node . x === 'number' && typeof node . y === 'number' ) {
154159 graphRef . current . centerAt ( node . x , node . y , 500 ) ;
@@ -160,8 +165,11 @@ export function MemoryGraph({ className, height = 400, width }: MemoryGraphProps
160165
161166 // Handle node hover
162167 const handleNodeHover = useCallback (
163- ( node : GraphNode | null ) => {
164- hoverNode ( node ?. id || null ) ;
168+ ( node : NodeObject | null ) => {
169+ const nodeId = node
170+ ? typeof node . id === 'number' ? node . id . toString ( ) : typeof node . id === 'string' ? node . id : null
171+ : null ;
172+ hoverNode ( nodeId ) ;
165173 } ,
166174 [ hoverNode ]
167175 ) ;
0 commit comments