A simple SVG polygon editor built with React, TypeScript, and Vite. PolyDraw allows you to create and edit polygon coordinates for image annotation, computer vision tasks, and SVG generation.
- Polygon Tool: Click to create polygon vertices, click the first point or
escbutton to complete - Select Tool: Drag and move existing polygon points by hovering over the point
- Point Selection: Click on a point to select them
- Delete Points: Press Delete key to remove selected point
- Image Upload: Upload background images (JPG, PNG, GIF, etc.)
- Auto-fit View: Automatically scales and centers uploaded images
- Snap to Edges: Points snap to image boundaries for precise annotation
- Adjustable Snap Distance: Customize snap threshold (5-50px)
- Zoom In/Out: Mouse wheel or zoom buttons (10% - 1000%)
- Pan Canvas: Drag to move around the canvas
- Reset View: Fit image to canvas with one click
- Grid Background: Visual grid for better positioning
- Multiple Polygons: Create unlimited polygons
- Custom Names: Edit polygon names for organization
- Opacity Control: Adjust polygon transparency (0-100%)
- Visual Feedback: Selected points highlighted in red
- Delete Polygons: Remove individual polygons or clear all
- Python Format: Generate Python coordinate arrays
- SVG String Format: Export as SVG polygon coordinates
- Normalized Coordinates: Option to export as 0-1 normalized values
- Copy to Clipboard: One-click copying of generated code
- Direct Editing: Edit SVG strings and apply changes
- Keyboard Shortcuts:
Delete: Remove selected pointEscape: Cancel current polygon creation
- Real-time Preview: See polygon changes as you draw
- Responsive Design: Works on desktop and tablet devices
- TypeScript: Full type safety and IntelliSense support
- Docker
- Docker Compose
-
Clone the repository
git clone <repository-url> cd PolyDraw
-
Start with Docker Compose
docker-compose up -d --build
-
Access the application Open your browser and navigate to
http://localhost:3000
docker-compose down- Select the Polygon tool from the left panel
- Click on the canvas to place vertices
- Click the first point again to complete the polygon
- Press
Escapeto cancel polygon creation
- Select the Select tool
- Click and drag points to move them
- Click a point to select it (highlighted in red)
- Press
Deleteto remove selected points - Use the coordinate inputs for precise positioning
- Click Choose File to upload an image
- The image will automatically fit to the canvas
- Enable Snap to Image Edges for precise boundary annotation
- Adjust snap distance as needed
- Create your polygons
- Choose export format (Python or SVG String)
- Toggle Normalize Coordinates if needed
- Click Copy to Clipboard to copy the code
- Computer Vision: Create training data for object detection
- Image Annotation: Mark regions of interest in images
- SVG Generation: Create vector graphics from coordinates
- GIS Applications: Define geographic regions
- Frontend: React 18 with TypeScript
- Build Tool: Vite
- Styling: Tailwind CSS
- Icons: Lucide React
- Testing: Vitest + React Testing Library
- Development: ESLint for code quality
PolyDraw/
├── src/ # Source code
│ ├── components/ # React components
│ │ ├── Canvas/ # Canvas component
│ │ ├── UI/ # UI components (Button, Input)
│ │ └── Widgets/ # Feature widgets
│ ├── hooks/ # Custom React hooks
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ ├── App.tsx # Main application component
│ ├── main.tsx # Application entry point
│ └── index.css # Global styles
├── tests/ # Test files (mirrors src structure)
│ ├── components/ # Component tests
│ ├── utils/ # Utility tests
│ ├── hooks/ # Hook tests
│ └── setup/ # Test configuration
├── public/ # Static assets
├── package.json # Dependencies and scripts
├── vite.config.ts # Vite configuration
├── vitest.config.ts # Vitest test configuration
├── tailwind.config.js # Tailwind CSS configuration
└── tsconfig.json # TypeScript configuration
The project includes comprehensive unit tests:
# Run tests in watch mode
npm test
# Run tests once
npm run test:run
# Run tests with coverage
npm run test:coverage
# Run tests with UI
npm run test:uiSee TESTING.md for detailed testing documentation and TEST_ORGANIZATION.md for information about the test structure.
If you encounter any issues or have questions:
- Check the browser console for error messages
- Ensure you're using a modern browser (Chrome, Firefox, Safari, Edge)
- Try refreshing the page if the canvas becomes unresponsive
- Create an issue in the repository with details about the problem
Happy Polygon Drawing! 🎨