The Canvas Layout Transformation System enables AI-driven restructuring of canvas content into various visual formats. This system supports converting unorganized nodes into structured layouts like mind maps, roadmaps, timelines, flowcharts, and presentations.
LayoutService- Core transformation algorithms for each layout typeLayoutController- HTTP API endpoints for layout transformationslayout.routes.ts- Express.js routes with authentication and validation
ActionExecutor.executeLayout()- Client-side layout transformation execution- AI Planner Prompt - Enhanced to recognize layout transformation requests
- Canvas Types - Extended with layout action types and properties
- Purpose: Brainstorming, concept exploration, knowledge organization
- Structure: Radial branching from a central concept
- Features: Center node focus, hierarchical branching, color coding
- Best For: Creative sessions, concept mapping, idea exploration
{
"type": "layout",
"layoutType": "mindmap",
"options": {
"spacing": { "x": 200, "y": 150 },
"centerPosition": { "x": 0, "y": 0 }
}
}- Purpose: Project planning, milestone tracking, strategic planning
- Structure: Sequential phases with color-coded progression
- Features: Phase grouping, progress indicators, sequential flow
- Best For: Project timelines, strategic planning, milestone tracking
{
"type": "layout",
"layoutType": "roadmap",
"options": {
"spacing": { "x": 300, "y": 200 },
"direction": "horizontal"
}
}- Purpose: Historical events, project schedules, process documentation
- Structure: Chronological horizontal progression
- Features: Time-based ordering, alternating positioning, flow arrows
- Best For: Historical data, project schedules, sequential processes
{
"type": "layout",
"layoutType": "timeline",
"options": {
"spacing": { "x": 250, "y": 100 },
"direction": "horizontal"
}
}- Purpose: Process documentation, decision trees, workflow design
- Structure: Hierarchical levels with decision flow
- Features: Process shapes, decision nodes, hierarchical organization
- Best For: Process documentation, decision trees, workflow visualization
{
"type": "layout",
"layoutType": "flowchart",
"options": {
"spacing": { "x": 200, "y": 150 },
"direction": "vertical"
}
}- Purpose: Content organization for presentations
- Structure: Slide-based grouping with consistent spacing
- Features: Slide organization, grid layout, presentation styling
- Best For: Presentation preparation, content organization, storytelling
{
"type": "layout",
"layoutType": "presentation",
"options": {
"spacing": { "x": 150, "y": 100 },
"groupBy": "topic"
}
}Transform canvas nodes into specified layout.
Authentication: Required
Validation: Board access required
interface TransformRequest {
nodes: Node[];
edges: Edge[];
layoutType: "mindmap" | "roadmap" | "timeline" | "flowchart" | "presentation";
options?: {
spacing?: { x: number; y: number };
centerPosition?: { x: number; y: number };
direction?: "horizontal" | "vertical" | "radial";
groupBy?: "type" | "topic" | "priority" | "date";
};
}
interface TransformResponse {
success: boolean;
layout: string;
result: {
nodes: Node[];
edges: Edge[];
metadata: any;
};
stats: {
originalNodes: number;
resultNodes: number;
originalEdges: number;
resultEdges: number;
};
}Get available layout types and descriptions.
Authentication: Required
interface LayoutTypesResponse {
success: boolean;
layoutTypes: Array<{
id: string;
name: string;
description: string;
features: string[];
bestFor: string;
}>;
count: number;
}Preview layout transformation without applying changes.
Authentication: Required
Validation: Board access required
interface PreviewResponse {
success: boolean;
preview: {
layoutType: string;
estimatedChanges: {
nodesRepositioned: number;
edgesModified: number;
newEdges: number;
};
features: string[];
options: any;
};
}The AI planner recognizes natural language requests for layout transformations:
- "Convert this into a mind map"
- "Organize this as a roadmap"
- "Structure this like a timeline"
- "Make this look like a flowchart"
- "Turn this into presentation slides"
The planner prompt includes layout transformation intelligence:
// Layout transformation triggers:
- User asks to "convert to [layout type]"
- User requests "organize this into a [layout]"
- Canvas appears disorganized and would benefit from structureLayout transformations execute through the ActionExecutor:
// AI generates action plan
{
"actions": [
{
"type": "layout",
"layoutType": "mindmap",
"options": {
"spacing": { "x": 200, "y": 150 },
"centerPosition": { "x": 0, "y": 0 }
}
}
]
}
// ActionExecutor calls layout API
const response = await api.post("/layout/transform", transformRequest);
// Canvas updates with new node positions
setNodes(response.result.nodes);
setEdges(response.result.edges);- Identify/create center node (most connected or first node)
- Calculate radial positions around center
- Position child nodes in hierarchical levels
- Connect all nodes to center in star pattern
- Apply color coding and styling
- Group nodes into phases (2-4 nodes per phase)
- Position phases horizontally with increasing colors
- Create sequential connections between phases
- Add phase labels and progress indicators
- Sort nodes by creation time or content hints
- Position nodes horizontally with alternating vertical offset
- Create sequential flow connections
- Add timeline styling and flow arrows
- Build hierarchy from edge relationships
- Assign flowchart node types (start, process, decision, end)
- Position nodes in vertical levels
- Apply appropriate shapes and connections
- Group nodes into slides (3-4 nodes per slide)
- Position slides horizontally with grid layout within slides
- Maintain consistent spacing and alignment
- Apply presentation styling
The system includes comprehensive error handling:
- ValidationError: Invalid transformation parameters
- UnsupportedLayout: Unknown layout type requested
- LayoutTransformError: Algorithm execution failure
- InternalError: System-level failures
Run layout tests:
bun test tests/layout.test.tsTests cover:
- All layout algorithm correctness
- Node positioning and edge creation
- Options handling and validation
- Error scenarios and edge cases
// Voice command: "convert this into a mind map"
// AI generates:
{
"actions": [
{
"type": "layout",
"layoutType": "mindmap"
}
]
}// Voice command: "organize this as a roadmap with wide spacing"
// AI generates:
{
"actions": [
{
"type": "layout",
"layoutType": "roadmap",
"options": {
"spacing": { "x": 400, "y": 250 }
}
}
]
}// Voice command: "make this look like a vertical flowchart"
// AI generates:
{
"actions": [
{
"type": "layout",
"layoutType": "flowchart",
"options": {
"direction": "vertical"
}
}
]
}- Test the implementation with various canvas configurations
- Refine algorithms based on user feedback and edge cases
- Add more layout options like hierarchical trees or network diagrams
- Enhance AI recognition of layout transformation contexts
- Add animation support for smooth layout transitions
This system provides the foundation for AI-driven canvas restructuring as specified in the PRD, enabling users to transform unorganized content into structured, visually appealing layouts through natural voice commands.