From a3e07b5898ce30287e3ca5f5c804dc2d70f53690 Mon Sep 17 00:00:00 2001 From: freesemar93 <46578442-freesemar93@users.noreply.replit.com> Date: Mon, 18 Aug 2025 12:28:14 +0000 Subject: [PATCH] Add a coordinate system and mouse tracking to the canvas Adds X and Y axis labels to the canvas, displays mouse coordinates on hover, and updates the project documentation to reflect these new features. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 0385ea33-cde8-4bbd-8fce-8d192d30eb41 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/870d08ce-da3b-4822-9874-c2fe2b7628b1/0385ea33-cde8-4bbd-8fce-8d192d30eb41/zNDeQGA --- client/src/components/canvas.tsx | 76 +++++++++++++++++++-- exports/canvas-2025-08-18T12-27-25-417Z.svg | 1 + replit.md | 6 +- 3 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 exports/canvas-2025-08-18T12-27-25-417Z.svg diff --git a/client/src/components/canvas.tsx b/client/src/components/canvas.tsx index f906353..f9e2426 100644 --- a/client/src/components/canvas.tsx +++ b/client/src/components/canvas.tsx @@ -24,6 +24,7 @@ export function Canvas({ const containerRef = useRef(null); const [zoom, setZoom] = useState(1); const [pixelSize, setPixelSize] = useState(8); + const [mouseCoords, setMouseCoords] = useState<{x: number, y: number} | null>(null); // Create pixel map for O(1) lookup const pixelMap = new Map(); @@ -36,6 +37,14 @@ export function Canvas({ onPixelClick(x, y); }; + const handlePixelMouseEnter = (x: number, y: number) => { + setMouseCoords({ x, y }); + }; + + const handlePixelMouseLeave = () => { + setMouseCoords(null); + }; + const handleZoomIn = () => { setZoom(prev => Math.min(prev * 1.2, 3)); }; @@ -67,11 +76,49 @@ export function Canvas({ className="w-full h-full overflow-auto p-8" data-testid="canvas-container" > -
+ {/* Coordinate System Container */} +
+ {/* Top X-axis coordinates */} +
+ {Array.from({ length: Math.ceil(canvasWidth / 10) }, (_, i) => ( +
+ {i * 10} +
+ ))} +
+ + {/* Canvas with left Y-axis coordinates */} +
+ {/* Left Y-axis coordinates */} +
+ {Array.from({ length: Math.ceil(canvasHeight / 10) }, (_, i) => ( +
+ {i * 10} +
+ ))} +
+ + {/* Main Canvas */} +
{Array.from({ length: canvasHeight }, (_, y) => Array.from({ length: canvasWidth }, (_, x) => { const pixelColor = pixelMap.get(`${x},${y}`) || "#FFFFFF"; @@ -88,6 +135,8 @@ export function Canvas({ height: `${pixelSize}px` }} onClick={() => handlePixelClick(x, y)} + onMouseEnter={() => handlePixelMouseEnter(x, y)} + onMouseLeave={handlePixelMouseLeave} data-testid={`pixel-${x}-${y}`} data-x={x} data-y={y} @@ -95,9 +144,26 @@ export function Canvas({ ); }) )} +
+
+ {/* Coordinate Info Display */} +
+
+ Canvas: {canvasWidth} × {canvasHeight} +
+
+ Zoom: {Math.round(zoom * 100)}% +
+ {mouseCoords && ( +
+ Mouse: ({mouseCoords.x}, {mouseCoords.y}) +
+ )} +
+ {/* Zoom Controls */}