For arrays with 100 or more elements, the sorting and searching visualizers automatically switch from DOM-based rendering to an optimized Canvas-based visualization with zoom and pan capabilities.
- Arrays with < 100 elements use standard DOM rendering
- Arrays with ≥ 100 elements automatically use Canvas rendering
- No configuration needed - it just works!
All color meanings are preserved:
- 🔵 Blue (#3b82f6): Unsorted/Unvisited elements
- 🟡 Yellow (#eab308): Elements being compared
- 🔴 Red (#ef4444): Elements being swapped
- 🟣 Purple (#a855f7): Pivot element (Quick Sort) or Middle element (Binary Search)
- 🟢 Green (#22c55e): Sorted elements or Found target
- ⚫ Gray (#9ca3af): Out of range (Binary Search)
- Mouse Wheel: Scroll up to zoom in, scroll down to zoom out
- Zoom In Button (+): Increase zoom level
- Zoom Out Button (-): Decrease zoom level
- Zoom Range: 10% to 500%
- Click & Drag: Click and hold, then drag to move the view
- Pan Mode Button: Toggle pan mode on/off
- Enabled automatically for large arrays
- Fit to View (⊡): Automatically fit the entire array in the viewport
- Reset View (↺): Reset zoom to 100% and pan to origin
- Current zoom percentage
- Total number of elements
- Interactive hints (e.g., "Scroll to zoom • Drag to pan")
// Input: "5 2 8 1 9"
// Result: Standard DOM visualization with boxes// Input: Array of 150 numbers
// Result: Canvas visualization with zoom/pan controls// Generate 150 random numbers between 1-1000
Array.from({length: 150}, () => Math.floor(Math.random() * 1000) + 1).join(' ')
// Generate sorted array of 200 numbers
Array.from({length: 200}, (_, i) => i + 1).join(' ')
// Generate reverse sorted array of 120 numbers
Array.from({length: 120}, (_, i) => 120 - i).join(' ')Only elements visible in the current viewport are rendered, improving performance for very large arrays.
Canvas API provides hardware-accelerated rendering, much faster than DOM manipulation for large datasets.
- Transforms are applied at the Canvas level
- No layout recalculation overhead
- 60 FPS animation capability
- ✅ Chrome/Edge (Chromium) - Fully supported
- ✅ Firefox - Fully supported
- ✅ Safari - Fully supported
- ✅ Opera - Fully supported
- ✅ Mobile Chrome/Safari - Touch gestures supported
⚠️ Pan mode works best on tablets and desktops
ZoomableArrayCanvas.tsx
├── Canvas rendering with 2D context
├── Zoom state management (0.1x - 5x)
├── Pan state management (x, y offsets)
├── Mouse event handlers (wheel, drag)
├── Control buttons overlay
└── Info display overlay
SortingVisualizer.tsx- Sorts visualizationSearchingVisualizer.tsx- Search visualizationParallelSortingVisualizer.tsx- Side-by-side comparisonParallelSearchingVisualizer.tsx- Search comparison
interface ArrayElement {
value: number // Element value to display
index: number // Element index in array
color: string // Hex color code (#rrggbb)
}
interface ZoomableArrayCanvasProps {
elements: ArrayElement[]
width?: number // Canvas width (default: 800)
height?: number // Canvas height (default: 200)
onElementClick?: (index: number) => void // Optional click handler
}+/=: Zoom in-/_: Zoom out0: Reset viewF: Fit to viewSpace: Toggle pan mode- Arrow keys: Pan view
Solution: The canvas automatically handles high-DPI displays. If it appears blurry, try refreshing the page.
Solution:
- Ensure array has ≥ 100 elements
- Check that pan mode is enabled (button highlighted)
- Try clicking "Reset View" button
Solution:
- The viewport culling should handle this automatically
- If still slow, try reducing the array size
- Future: We'll add aggregated view option for 1000+ elements
Solution: Controls are only shown for arrays with ≥ 100 elements. For smaller arrays, use the standard DOM visualization.
- Start with small arrays (< 100) to understand the algorithm
- Test with medium arrays (100-500) to see efficiency
- Use large arrays (500+) to appreciate optimization
- Begin demonstrations with visible arrays (< 100)
- Show the transition to Canvas mode for large datasets
- Emphasize the importance of efficient visualization for big data
- Test edge cases: exactly 100 elements
- Test performance: 1000+ elements
- Test on different screen sizes
- Test zoom extremes (10% and 500%)
- Aggregated histogram view for 1000+ elements
- Keyboard shortcuts for all controls
- Touch gestures for mobile (pinch to zoom)
- Export visualization as image/video
- Custom color themes
- Animation speed control integration
- Element highlighting on hover
Inspired by best practices from:
- Google Chrome DevTools Performance Panel
- Observable Notebook visualizations
- D3.js zoom/pan behaviors
- Canvas API documentation (MDN)
Version: 1.0.0
Last Updated: October 12, 2025
Author: DecodeDSA Team