Skip to content

Commit 7e05e52

Browse files
committed
Optimized Minimap performance with useCallback and updated README.md document
1 parent 8dcabfe commit 7e05e52

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@ This project is a web-based visual scripting environment that allows users to cr
1616
- HTTP Requests
1717
- JSON handling (Parse, Stringify)
1818
- Base64 encoding/decoding
19-
- Real-time code generation with customizable settings
20-
- Ability to run scripts with debugging support
21-
- Undo/Redo functionality
22-
- Canvas controls (zoom, pan)
23-
- Project management (save, load)
24-
- Export options (JSON, JavaScript, Image)
19+
- Real-time code generation with customizable settings:
20+
- Strict mode toggle
21+
- Semicolon usage toggle
22+
- Const/Let declaration choice
23+
- Comment generation toggle
24+
- Canvas controls:
25+
- Zoom and pan functionality
26+
- Grid toggle
27+
- Minimap visualization
28+
- Node rounding options
2529
- Theme customization (dark/light)
26-
- Grid and minimap visualization
27-
- Graph inspector panel
30+
- Project management:
31+
- Save/Load functionality
32+
- Export options (JSON, JavaScript, Image)
33+
- Graph inspector panel with real-time node configuration
2834
- Predefined example projects
2935

3036
## Installation
@@ -78,6 +84,9 @@ This project is a web-based visual scripting environment that allows users to cr
7884
- `GraphInspector.js`: Node properties panel
7985
- `MenuBar.js`: Application menu
8086
- `SettingsTab.js`: Configuration interface
87+
- `ContextMenu.js`: Right-click menu
88+
- `NodeContextMenu.js`: Node-specific context menu
89+
- `Minimap.js`: Canvas overview
8190
- `src/examples.js`: Predefined example projects
8291

8392
## Contributing

src/components/Minimap.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useRef, useEffect, useCallback } from 'react';
33
const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeTypes }) => {
44
const minimapRef = useRef(null);
55

6-
const calculateBounds = (nodes, ctx) => {
6+
const calculateBounds = useCallback((nodes, ctx) => {
77
if (!nodes.length) return null;
88

99
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
@@ -21,9 +21,9 @@ const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeType
2121
});
2222

2323
return minX === Infinity ? null : { minX, minY, maxX, maxY };
24-
};
24+
}, [getNodeDimensions]);
2525

26-
const drawEdge = (ctx, edge, nodes, scale, bounds) => {
26+
const drawEdge = useCallback((ctx, edge, nodes, scale, bounds) => {
2727
const startNode = nodes.find(n => n.id === edge.start.nodeId);
2828
const endNode = nodes.find(n => n.id === edge.end.nodeId);
2929
if (!startNode || !endNode) return;
@@ -40,9 +40,9 @@ const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeType
4040
ctx.strokeStyle = '#666';
4141
ctx.lineWidth = 1;
4242
ctx.stroke();
43-
};
43+
}, [getNodeDimensions]);
4444

45-
const drawNode = (ctx, node, scale, bounds) => {
45+
const drawNode = useCallback((ctx, node, scale, bounds) => {
4646
const { width, height } = getNodeDimensions(node, ctx);
4747
const nodeType = nodeTypes[node.type];
4848

@@ -73,7 +73,7 @@ const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeType
7373
(node.x - bounds.minX + 5) * scale,
7474
(node.y - bounds.minY + 15) * scale
7575
);
76-
};
76+
}, [getNodeDimensions, nodeTypes]);
7777

7878
const drawViewport = (ctx, camera, canvasSize, scale, bounds) => {
7979
const viewportWidth = canvasSize.width / camera.scale;
@@ -121,7 +121,7 @@ const Minimap = ({ nodes, edges, camera, canvasSize, getNodeDimensions, nodeType
121121
nodes.forEach(node => drawNode(minimapCtx, node, scale, bounds));
122122
drawViewport(minimapCtx, camera, canvasSize, scale, bounds);
123123

124-
}, [nodes, edges, camera, canvasSize, getNodeDimensions, nodeTypes]);
124+
}, [nodes, edges, camera, canvasSize, calculateBounds, drawEdge, drawNode]);
125125

126126
useEffect(() => {
127127
try {

src/components/NodeContextMenu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React from 'react';
22
import styles from './ContextMenu.module.css';
33

44
const NodeContextMenu = ({ visible, x, y, camera, onAction }) => {
@@ -36,4 +36,4 @@ const NodeContextMenu = ({ visible, x, y, camera, onAction }) => {
3636
);
3737
};
3838

39-
export default NodeContextMenu;
39+
export default NodeContextMenu;

0 commit comments

Comments
 (0)