I've successfully implemented a comprehensive auto-layout and graph generation system for Redstring. Here's what was built:
1. src/services/graphLayoutService.js (340 lines)
- Five layout algorithms:
- Force-Directed: Fruchterman-Reingold physics simulation with spring forces and repulsion
- Hierarchical: BFS-based tree layout with level detection
- Radial: Concentric orbit layout around most-connected node
- Grid: Regular rows and columns
- Circular: Equal spacing on circle perimeter
- Configurable parameters for each algorithm
- Respects Redstring's instance-based architecture
2. src/services/autoGraphGenerator.js (550 lines)
- Input parsers:
- Simple JSON (nodes + edges format)
- JSON-LD / RDF (semantic web format with @context)
- Auto-detection based on structure
- Intelligent prototype management:
- Searches for existing prototypes by name
- Reuses prototypes for semantic consistency
- Creates new prototypes only when needed
- Instance creation with layout positions
- Edge creation with proper directionality
- Four sample data templates:
- Simple Network (5 nodes)
- Family Tree (hierarchical, 6 nodes)
- Knowledge Graph (JSON-LD, 4 nodes)
- Concept Network (dense, 7 nodes)
3. src/components/AutoGraphModal.jsx (240 lines)
- Modal dialog with full configuration UI:
- Data source selector (Sample / Custom)
- Sample template dropdown
- Custom JSON input textarea
- Format selector (Auto / Simple JSON / JSON-LD)
- Layout algorithm dropdown (5 options)
- Target mode (Add to Current / New Graph / Replace)
- Graph name input (for new graphs)
- Input validation
- Live sample preview with stats
4. src/components/AutoGraphModal.css (250 lines)
- Maroon-themed styling matching Redstring aesthetic
- Responsive layout with scrollable content
- Form controls with proper focus states
- Button groups and radio buttons
- Monospace textarea for JSON input
1. src/RedstringMenu.jsx
- Added "Generate Test Graph" menu item in Debug menu
- Menu item triggers modal open via callback
- Styled with teal color (#4ecdc4) for debug features
- Positioned after "Show Debug Overlay" before settings
2. src/Header.jsx
- Added
onGenerateTestGraphprop - Passes handler through to RedstringMenu
3. src/NodeCanvas.jsx
- Imported AutoGraphModal and generation services
- Added modal state (
autoGraphModalVisible) - Added handler to open modal (
onGenerateTestGraph) - Integrated generation logic with store actions:
- Parses input data
- Generates graph with selected options
- Shows results notification
- Handles errors gracefully
- Modal positioned at end of component tree with other modals
- Reuse over Create: Searches existing prototypes by name before creating new ones
- Semantic Consistency: Maintains single source of truth for concepts
- Type Preservation: Respects typeNodeId relationships
- Collision Avoidance: All algorithms prevent node overlap
- Bounds Management: Keeps nodes within canvas with configurable padding
- Configurable Spacing: Adjust distances, forces, iterations per algorithm
- Centering: Prevents graph drift in force-directed layout
- Simple JSON: Easy to write, human-readable
- JSON-LD: Full semantic web compatibility with RDF
- URI Preservation: Maintains @id references for linked data
- Property Mapping: Intelligently maps various property names (name/label/rdfs:label)
- Sample Templates: Quick testing without writing JSON
- Live Preview: Shows node/edge counts for samples
- Mode Selection: New graph, add to current, or replace
- Error Handling: Graceful failures with clear error messages
- Results Notification: Summary of what was created
- User clicks Redstring Menu → Debug → Generate Test Graph
- Modal opens with configuration options
- User selects:
- Sample data or pastes custom JSON
- Layout algorithm
- Target graph mode
- User clicks "Generate Graph"
- System:
- Parses input data
- Finds/creates prototypes
- Applies layout algorithm
- Creates instances with positions
- Creates edges
- Shows results
- Graph is immediately visible on canvas
Created comprehensive guide: AUTO_LAYOUT_GUIDE.md
- Feature overview
- Input format specifications
- Layout algorithm details
- Architecture explanation (three-layer system)
- API documentation
- Configuration options
- Sample data examples
- Best practices
- Troubleshooting guide
- Prototypes: Reusable semantic concepts (shared across universe)
- Instances: Positioned occurrences in graphs
- Graphs: Spatial contexts containing instances
- Uses
storeActions.addNodePrototype()for new concepts - Uses
storeActions.addNodeInstance()with positions - Uses
storeActions.addEdge()for connections - Uses
storeActions.createNewGraph()when requested - Properly manages Maps and Sets
- Respects dual format (instance IDs + prototype metadata)
- Creates proper directionality objects
- Sets appropriate typeNodeId for relations
Ready to test with:
- Sample templates (built-in, 4 options)
- Custom JSON (paste your own)
- JSON-LD import (RDF/semantic web data)
- All 5 layout algorithms
- Different graph modes (new/current/replace)
To test the feature:
- Start Redstring
- Click Redstring menu (top left)
- Debug → Generate Test Graph
- Try "Simple Network" with "Force-Directed" layout
- Click "Generate Graph"
- See immediate results on canvas!
To iterate on layouts:
- Try different algorithms (hierarchical, radial, etc.)
- Adjust layout parameters in code (spacing, iterations)
- Test with your own data (paste custom JSON)
To extend:
- Add new layout algorithms in
graphLayoutService.js - Add new sample templates in
autoGraphGenerator.js - Add new input parsers in
parseInputData() - Customize layout parameters per algorithm
- Modal matches Redstring aesthetic (maroon theme)
- Menu item uses debug color scheme (teal)
- Results notification uses native alert (can be upgraded to toast)
- No visual conflicts with existing UI
New Files (4):
src/services/graphLayoutService.js- Layout algorithmssrc/services/autoGraphGenerator.js- Data parsing & generationsrc/components/AutoGraphModal.jsx- UI modalsrc/components/AutoGraphModal.css- Modal styling
Modified Files (3):
src/RedstringMenu.jsx- Added menu itemsrc/Header.jsx- Added prop passthroughsrc/NodeCanvas.jsx- Added integration & state
Documentation (2):
AUTO_LAYOUT_GUIDE.md- User guideAUTOGRAPH_IMPLEMENTATION_SUMMARY.md- This file
Total LOC Added: ~1,400 lines of production code + 600 lines of documentation
All files pass ESLint validation. Code follows Redstring conventions.
The feature is fully implemented, documented, and ready for testing and iteration.