@@ -3,7 +3,7 @@ import React, { useRef, useEffect, useCallback } from 'react';
3
3
const Minimap = ( { nodes, edges, camera, canvasSize, getNodeDimensions, nodeTypes } ) => {
4
4
const minimapRef = useRef ( null ) ;
5
5
6
- const calculateBounds = ( nodes , ctx ) => {
6
+ const calculateBounds = useCallback ( ( nodes , ctx ) => {
7
7
if ( ! nodes . length ) return null ;
8
8
9
9
let minX = Infinity , minY = Infinity , maxX = - Infinity , maxY = - Infinity ;
@@ -21,9 +21,9 @@ const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeType
21
21
} ) ;
22
22
23
23
return minX === Infinity ? null : { minX, minY, maxX, maxY } ;
24
- } ;
24
+ } , [ getNodeDimensions ] ) ;
25
25
26
- const drawEdge = ( ctx , edge , nodes , scale , bounds ) => {
26
+ const drawEdge = useCallback ( ( ctx , edge , nodes , scale , bounds ) => {
27
27
const startNode = nodes . find ( n => n . id === edge . start . nodeId ) ;
28
28
const endNode = nodes . find ( n => n . id === edge . end . nodeId ) ;
29
29
if ( ! startNode || ! endNode ) return ;
@@ -40,9 +40,9 @@ const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeType
40
40
ctx . strokeStyle = '#666' ;
41
41
ctx . lineWidth = 1 ;
42
42
ctx . stroke ( ) ;
43
- } ;
43
+ } , [ getNodeDimensions ] ) ;
44
44
45
- const drawNode = ( ctx , node , scale , bounds ) => {
45
+ const drawNode = useCallback ( ( ctx , node , scale , bounds ) => {
46
46
const { width, height } = getNodeDimensions ( node , ctx ) ;
47
47
const nodeType = nodeTypes [ node . type ] ;
48
48
@@ -73,7 +73,7 @@ const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeType
73
73
( node . x - bounds . minX + 5 ) * scale ,
74
74
( node . y - bounds . minY + 15 ) * scale
75
75
) ;
76
- } ;
76
+ } , [ getNodeDimensions , nodeTypes ] ) ;
77
77
78
78
const drawViewport = ( ctx , camera , canvasSize , scale , bounds ) => {
79
79
const viewportWidth = canvasSize . width / camera . scale ;
@@ -121,7 +121,7 @@ const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeType
121
121
nodes . forEach ( node => drawNode ( minimapCtx , node , scale , bounds ) ) ;
122
122
drawViewport ( minimapCtx , camera , canvasSize , scale , bounds ) ;
123
123
124
- } , [ nodes , edges , camera , canvasSize , getNodeDimensions , nodeTypes ] ) ;
124
+ } , [ nodes , edges , camera , canvasSize , calculateBounds , drawEdge , drawNode ] ) ;
125
125
126
126
useEffect ( ( ) => {
127
127
try {
0 commit comments