Smart Canvas Library Overview
Comprehensive canvas system for Angular applications with drag & drop, connections, theming, and mobile support
Smart Canvas Library Overview
๐ฏ What is Smart Canvas?
Smart Canvas (@smart-canvas) is a comprehensive, intelligent canvas system designed to replace multiple canvas implementations across the GoGrab Space monorepo. It provides a unified, feature-rich solution for building interactive node-based interfaces, flow composers, and visual editors.
โจ Key Features
๐จ Multi-Theme Ready
- 5 Built-in Themes: Space, Modern, Professional, Editor, Dark, Light
- Custom Theme Support: Easy theming with CSS variables
- Responsive Design: Automatic adaptation to different screen sizes
๐ฑ๏ธ Advanced Interactions
- Smooth Pan & Zoom: Mouse wheel, touch gestures, keyboard shortcuts
- Multi-Selection: Ctrl/Cmd+Click, drag selection rectangle
- Node Dragging: Smooth drag & drop with snap-to-grid
- Connection Creation: Click ports to create SVG connections
- Context Menus: Right-click functionality integration
๐ฑ Mobile Optimized
- Touch Gestures: Pinch-to-zoom, two-finger pan, tap selection
- Mobile-First Design: Optimized for touch interactions
- Responsive Layout: Adapts to mobile screen sizes
๐ Node Connectivity
- Port-Based Connections: Input/output ports for precise connections
- Multiple Connection Types: Straight, bezier, orthogonal curves
- Connection Styling: Customizable colors, widths, markers
- Real-time Updates: Dynamic connection rendering
๐พ Intelligent Storage
- Auto-Persistence: Zero-config state persistence with
@flash-persistence - Storage Integration: Full
@storage-systemintegration - Undo/Redo: Complete history management
- State Synchronization: Reactive state updates
๐๏ธ Rich Configuration
- Live Configuration Panel: Real-time settings adjustment
- Feature Toggles: Enable/disable specific functionality
- Performance Settings: Optimization controls
- Accessibility Options: WCAG-compliant features
๐๏ธ Architecture
Core Components
@smart-canvas/
โโโ SmartCanvasComponent # Main canvas container
โโโ CanvasNodeComponent # Individual node rendering
โโโ CanvasConnectionComponent # SVG connection rendering
โโโ CanvasGridComponent # Background grid system
โโโ CanvasToolbarComponent # Action toolbar
โโโ CanvasConfigPanel # Configuration UI
โโโ CanvasMinimapComponent # Navigation minimap
Core Services
@smart-canvas/services/
โโโ SmartCanvasService # State management & persistence
โโโ CanvasInteractionService # User interaction handling
โโโ CanvasDragDropService # Drag & drop operations
Type System
interface SmartCanvasConfig {
viewport: CanvasViewport;
transform: CanvasTransform;
features: CanvasFeatures;
interactions: CanvasInteractionConfig;
appearance: CanvasAppearanceConfig;
performance: CanvasPerformanceConfig;
content: CanvasContentConfig;
}
๐ Quick Start
Installation
# Smart Canvas is part of the monorepo
yarn install
Basic Usage
import { SmartCanvasComponent } from '@smart-canvas';
@Component({
template: `
<lib-smart-canvas
[nodes]="nodes"
[connections]="connections"
[config]="canvasConfig">
</lib-smart-canvas>
`
})
export class MyCanvasComponent {
nodes: CanvasNode[] = [
{
id: 'node-1',
type: 'process',
position: { x: 100, y: 100, z: 1 },
size: { width: 120, height: 80 },
data: { title: 'Start Process' },
ports: [
{ id: 'out-1', type: 'output', position: { x: 1, y: 0.5 } }
]
}
];
canvasConfig: Partial<SmartCanvasConfig> = {
features: {
enablePanning: true,
enableZooming: true,
enableSelection: true,
showGrid: true
}
};
}
Advanced Configuration
canvasConfig: SmartCanvasConfig = {
appearance: {
theme: 'modern',
grid: {
enabled: true,
type: 'dots',
size: 40,
color: '#e5e5e5',
opacity: 0.4
}
},
interactions: {
panSensitivity: 1,
zoomSensitivity: 0.8,
selectionRectangle: true,
panWithSpace: false
},
features: {
enableMultiSelection: true,
enableConnectionCreation: true,
showToolbar: true,
showConfigPanel: true
}
};
๐ฎ User Interactions
Mouse Controls
- Left Click: Select nodes, click ports to connect
- Ctrl/Cmd + Click: Multi-select nodes
- Drag Empty Space: Pan canvas or create selection rectangle
- Mouse Wheel: Zoom in/out
- Right Click: Context menu
Keyboard Shortcuts
- Ctrl/Cmd + Z: Undo
- Ctrl/Cmd + Y: Redo
- Delete: Delete selected nodes
- Ctrl/Cmd + D: Duplicate selected nodes
- Space: Pan mode toggle
Touch Gestures
- Tap: Select nodes
- Pinch: Zoom in/out
- Two-finger drag: Pan canvas
- Long press: Context menu
๐ง Integration Examples
Flow Composer Integration
// Replace existing canvas with Smart Canvas
@Component({
template: `
<lib-smart-canvas
[nodes]="flowNodes"
[connections]="flowConnections"
[config]="flowConfig"
(nodeUpdate)="onNodeUpdate($event)"
(connectionCreate)="onConnectionCreate($event)"
(contextMenu)="onContextMenu($event)">
</lib-smart-canvas>
`
})
export class FlowComposerComponent {
// Migrate existing flow data to Smart Canvas format
}
Logic Builder Integration
// Convert logic blocks to Smart Canvas nodes
const logicNodes = logicBlocks.map(block => ({
id: block.id,
type: 'logic',
position: block.position,
size: block.size,
data: block.config,
ports: block.inputs.concat(block.outputs)
}));
๐ Performance Features
Optimization Strategies
- Virtual Scrolling: Handle thousands of nodes efficiently
- Connection Caching: Optimized SVG path generation
- Selective Rendering: Only render visible elements
- Debounced Updates: Smooth interaction performance
Performance Monitoring
canvasConfig.performance = {
enableVirtualScrolling: true,
maxVisibleNodes: 1000,
debounceMs: 16,
updateStrategy: 'frame-aligned'
};
๐จ Theming System
Built-in Themes
- Space: Dark space-themed with cosmic colors
- Modern: Clean, minimalist design
- Professional: Business-friendly appearance
- Editor: Code editor inspired theme
- Dark/Light: Standard dark and light modes
Custom Themes
canvasConfig.appearance.customTheme = {
primary: '#your-primary-color',
background: '#your-bg-color',
grid: '#your-grid-color',
nodes: {
default: '#your-node-color',
selected: '#your-selection-color'
}
};
๐ API Reference
Core Interfaces
SmartCanvasConfig- Main configuration interfaceCanvasNode- Node data structureCanvasConnection- Connection data structure
Event System
CanvasEvents- Event types and handlersInteractionEvents- User interaction events
๐งช Testing
Unit Tests
# Run Smart Canvas tests
yarn test smart-canvas
Integration Tests
# Test with Flow Composer
yarn test flow-composer-integration
๐ Migration Guide
From Space Canvas
- Replace
<space-canvas>with<lib-smart-canvas> - Update node data structure to include ports
- Configure theme to 'space' for consistent appearance
From Logic Builder
- Convert logic blocks to
CanvasNodeformat - Map input/output connections to ports
- Update event handlers for new API
From Flow Composer
- Migrate flow data to Smart Canvas format
- Update connection creation logic
- Integrate with new toolbar and config panel
๐ฏ Best Practices
Performance
- Use
trackByfunctions for large node lists - Enable virtual scrolling for 1000+ nodes
- Implement connection pooling for complex graphs
Accessibility
- Provide meaningful node labels
- Implement keyboard navigation
- Use high contrast themes when needed
User Experience
- Start with minimal configuration
- Enable progressive feature discovery
- Provide clear visual feedback for interactions
๐ฎ Future Roadmap
Planned Features
- Collaborative Editing: Real-time multi-user editing
- Advanced Animations: Smooth transitions and effects
- Plugin System: Extensible architecture
- AI Integration: Intelligent layout suggestions
Performance Improvements
- WebGL Rendering: Hardware acceleration
- Web Workers: Background processing
- Streaming: Large dataset handling
Smart Canvas represents the next generation of canvas systems in the GoGrab Space ecosystem, providing a unified, powerful, and extensible foundation for all visual editing needs.