### Interact with TrackCell and Renderable in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Explains how to handle individual cells in the rendered output using TrackCell and Renderable. It includes an example of matching on TrackCell variants to determine if a cell is a node or a connection. ```rust use renderdag::{GraphRenderer, Node, TrackCell, NodeKind, ConnectionKind}; let mut renderer = GraphRenderer::default(); let nodes = vec![ Node::new("b", vec!["a".to_string()]), Node::new("a", vec![]), ]; let output = renderer.render_to_string(&nodes); match TrackCell::Node(NodeKind::Merge) { TrackCell::Node(kind) => println!("Node of kind: {:?}", kind), TrackCell::Connection(kind) => println!("Connection of kind: {:?}", kind), } ``` -------------------------------- ### Compute Graph Layout with GraphLayout in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Demonstrates how to use the GraphLayout engine to compute node positions and layout details for a graph. It shows how to process nodes, retrieve layout plans, and access detailed step information. This is useful for custom rendering or inspecting layout computations. ```rust use renderdag::{GraphLayout, Node, GraphNode}; let mut layout = GraphLayout::new(); let nodes = vec![ Node::new("c", vec!["a".to_string(), "b".to_string()]), Node::new("b", vec!["a".to_string()]), Node::new("a", vec![]), ]; // Get detailed layout information for each row let plans = layout.layout(&nodes); for plan in &plans { println!("Node: {}", plan.node.id()); println!(" Lane column: {}", plan.node_lane_col); println!(" Row width: {}", plan.width); println!(" Operations: {} cells", plan.operations.len()); println!(" Parents present: {}", plan.parent_availability.present_count); println!(" Parents missing: {}", plan.parent_availability.missing_count); } // For even more detail, use layout_steps() let detailed_steps = layout.layout_steps(&nodes); for step in &detailed_steps { println!("Node lane ID: {}", step.node_lane_id); println!("Merge columns: {:?}", step.merge_columns); println!("Parent lane IDs: {:?}", step.parent_lane_ids); } ``` -------------------------------- ### Render Complex Git-like Graphs with Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Demonstrates how to use the GraphRenderer to visualize complex histories including octopus merges and partial graphs. It covers both default rendering and custom configurations for terminal lanes. ```rust use renderdag::{GraphRenderer, Node, RenderConfig}; fn main() { let mut renderer = GraphRenderer::default(); let nodes = vec![ Node::new("release", vec![ "main".to_string(), "feature-a".to_string(), "feature-b".to_string(), "hotfix".to_string(), ]), Node::new("hotfix", vec!["main".to_string()]), Node::new("feature-b", vec!["base".to_string()]), Node::new("feature-a", vec!["base".to_string()]), Node::new("main", vec!["base".to_string()]), Node::new("base", vec![]), ]; let output = renderer.render_to_string(&nodes); println!("{}", output); let mut config = RenderConfig::default(); config.set_render_terminal_lanes(true); let mut renderer2 = GraphRenderer::new(config); let partial_nodes = vec![ Node::new("Y", vec!["X".to_string()]), Node::new("X", vec!["A".to_string(), "Z".to_string()]), Node::new("A", vec![]), ]; let output2 = renderer2.render_to_string(&partial_nodes); println!("{}", output2); } ``` -------------------------------- ### Manage and Override Glyphs in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Shows how to use the Glyphs struct to manage visual overrides for nodes and connections. It demonstrates both individual updates and bulk application of glyph mappings. ```rust use renderdag::{Glyphs, NodeKind, ConnectionKind}; let mut glyphs = Glyphs::default(); glyphs.set_node_glyph(NodeKind::Node, '*'); glyphs.set_connection_glyph(ConnectionKind::Vertical, '|'); glyphs.apply_overrides( [ (NodeKind::Initial, 'o'), (NodeKind::Merge, 'M'), (NodeKind::NodeLeaf, '@'), ], [ (ConnectionKind::Vertical, '|'), (ConnectionKind::Horizontal, '-'), (ConnectionKind::CornerUpLeft, '+'), (ConnectionKind::CornerUpRight, '+'), (ConnectionKind::CornerDownLeft, '+'), (ConnectionKind::CornerDownRight, '+'), ], ); let node_glyph = glyphs.node[NodeKind::Merge.idx()]; let conn_glyph = glyphs.connection[ConnectionKind::Vertical.idx()]; ``` -------------------------------- ### Create Nodes for DAG Representation in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Demonstrates how to create Node structs, which represent graph nodes with an ID and a list of parent IDs. This is fundamental for building DAG structures in renderdag. ```rust use renderdag::Node; // Create nodes for a simple git-like history // Commit "d" has parent "c", "c" has parent "b", etc. let nodes = vec![ Node::new("d", vec!["c".to_string()]), Node::new("c", vec!["b".to_string()]), Node::new("b", vec!["a".to_string()]), Node::new("a", vec![]), // Initial commit, no parents ]; // Merge commit example - node with multiple parents let merge_node = Node::new("merge", vec!["feature".to_string(), "main".to_string()]); ``` -------------------------------- ### Render DAG to String using GraphRenderer in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Shows how to use the GraphRenderer to convert a list of Node objects into a string representation of the DAG. It handles layout and glyph selection automatically. ```rust use renderdag::{GraphRenderer, Node, RenderConfig}; // Create a renderer with default Unicode glyphs let mut renderer = GraphRenderer::default(); // Define a simple branching history let nodes = vec![ Node::new("d", vec!["b".to_string(), "c".to_string()]), // Merge commit Node::new("c", vec!["a".to_string()]), // Feature branch Node::new("b", vec!["a".to_string()]), // Main branch Node::new("a", vec![]), // Root commit ]; // Render to string let output = renderer.render_to_string(&nodes); println!("{}", output); // Output: // ⍟─╮ d (merge of b and c) // │ ● c // ● │ b // ⊝─╯ a ``` -------------------------------- ### RenderConfig Source: https://context7.com/kdheepak/renderdag/llms.txt Configuration struct for customizing glyph rendering and display options for the graph. Allows modification of node and connection glyphs, and rendering of terminal lanes. ```APIDOC ## RenderConfig ### Description `RenderConfig` allows customization of the visual appearance of the rendered graph. You can change the glyphs used for different node types (initial, merge, leaf, etc.) and connection types (vertical, horizontal, corners, etc.). It also supports enabling terminal lane rendering to show open branches. ### Usage ```rust use renderdag::{RenderConfig, NodeKind, ConnectionKind, GraphRenderer, Node}; // Create custom configuration let mut config = RenderConfig::default(); // Customize node glyphs config.set_node_glyph(NodeKind::Initial, 'o'); // Root nodes config.set_node_glyph(NodeKind::Node, '*'); // Regular nodes config.set_node_glyph(NodeKind::Merge, 'M'); // Merge commits config.set_node_glyph(NodeKind::NodeLeaf, '@'); // Leaf nodes (HEAD) config.set_node_glyph(NodeKind::MergeLeaf, '#'); // Merge that is also HEAD // Customize connection glyphs config.set_connection_glyph(ConnectionKind::Vertical, '|'); config.set_connection_glyph(ConnectionKind::Horizontal, '-'); // Enable terminal lane markers (shows open branches at bottom) config.set_render_terminal_lanes(true); // Create renderer with custom config let mut renderer = GraphRenderer::new(config); let nodes = vec![ Node::new("head", vec!["parent".to_string()]), Node::new("parent", vec![]), ]; let output = renderer.render_to_string(&nodes); // Output uses custom glyphs: '@' for leaf, 'o' for initial ``` ``` -------------------------------- ### Customize DAG Rendering with RenderConfig in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Illustrates how to customize the appearance of the rendered DAG using the RenderConfig struct. This includes changing node and connection glyphs, and enabling terminal lane markers. ```rust use renderdag::{RenderConfig, NodeKind, ConnectionKind, GraphRenderer, Node}; // Create custom configuration let mut config = RenderConfig::default(); // Customize node glyphs config.set_node_glyph(NodeKind::Initial, 'o'); // Root nodes config.set_node_glyph(NodeKind::Node, '*'); // Regular nodes config.set_node_glyph(NodeKind::Merge, 'M'); // Merge commits config.set_node_glyph(NodeKind::NodeLeaf, '@'); // Leaf nodes (HEAD) config.set_node_glyph(NodeKind::MergeLeaf, '#'); // Merge that is also HEAD // Customize connection glyphs config.set_connection_glyph(ConnectionKind::Vertical, '|'); config.set_connection_glyph(ConnectionKind::Horizontal, '-'); // Enable terminal lane markers (shows open branches at bottom) config.set_render_terminal_lanes(true); // Create renderer with custom config let mut renderer = GraphRenderer::new(config); let nodes = vec![ Node::new("head", vec!["parent".to_string()]), Node::new("parent", vec![]), ]; let output = renderer.render_to_string(&nodes); // Output uses custom glyphs: @ for leaf, o for initial ``` -------------------------------- ### Graph Rendering API Source: https://context7.com/kdheepak/renderdag/llms.txt API for rendering graph structures using GraphRenderer and RenderConfig. ```APIDOC ## POST /render/graph ### Description Render a list of nodes into an ASCII/Unicode string representation. The renderer handles complex relationships like octopus merges and parallel branches. ### Method POST ### Endpoint /render/graph ### Parameters #### Request Body - **nodes** (Array) - Required - A list of nodes where each node contains an ID and a list of parent IDs. - **config** (Object) - Optional - Configuration object for rendering, including terminal lanes and glyph settings. ### Request Example { "nodes": [ { "id": "release", "parents": ["main", "feature-a"] }, { "id": "main", "parents": ["base"] }, { "id": "base", "parents": [] } ], "config": { "render_terminal_lanes": true } } ### Response #### Success Response (200) - **output** (String) - The rendered ASCII/Unicode graph string. #### Response Example { "output": "⍟─┬─╮ release\n● │ │ main\n⊝─┴─╯ base" } ``` -------------------------------- ### Implement Custom Nodes with GraphNode Trait in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Shows how to implement the GraphNode trait for a custom struct (GitCommit) to integrate it with the renderdag layout system. This allows using custom data types without conversion overhead, enabling detailed inspection of layout information alongside custom data. ```rust use renderdag::{GraphNode, GraphLayout, GraphRenderer, RenderConfig}; use std::hash::Hash; // Define your own commit structure #[derive(Clone)] struct GitCommit { sha: String, parent_shas: Vec, message: String, author: String, } // Implement GraphNode trait impl GraphNode for GitCommit { type Id = String; fn id(&self) -> Self::Id { self.sha.clone() } fn parents(&self) -> &[Self::Id] { &self.parent_shas } } // Now use with the layout engine let commits = vec![ GitCommit { sha: "abc123".to_string(), parent_shas: vec!["def456".to_string()], message: "Add feature".to_string(), author: "Alice".to_string(), }, GitCommit { sha: "def456".to_string(), parent_shas: vec![], message: "Initial commit".to_string(), author: "Bob".to_string(), }, ]; let mut layout = GraphLayout::new(); let plans = layout.layout(&commits); // Access both layout info and your custom data for plan in plans { println!("{}: {} (by {})", plan.node.sha, plan.node.message, plan.node.author ); } ``` -------------------------------- ### Define and Parse ConnectionKind in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Demonstrates the ConnectionKind enum which defines box-drawing glyphs for graph connections. It also shows how to parse string identifiers into their corresponding enum variants. ```rust use renderdag::ConnectionKind; let connections = [ (ConnectionKind::Empty, ' '), (ConnectionKind::Vertical, '│'), (ConnectionKind::Horizontal, '─'), (ConnectionKind::CornerUpLeft, '╯'), (ConnectionKind::CornerUpRight, '╰'), (ConnectionKind::CornerDownRight, '╭'), (ConnectionKind::CornerDownLeft, '╮'), (ConnectionKind::TeeUp, '┴'), (ConnectionKind::TeeDown, '┬'), (ConnectionKind::TeeLeft, '┤'), (ConnectionKind::TeeRight, '├'), (ConnectionKind::CrossOver, '┊'), (ConnectionKind::EndUp, '╵'), (ConnectionKind::EndDown, '╷'), (ConnectionKind::EndLeft, '╴'), (ConnectionKind::EndRight, '╶'), ]; assert_eq!(ConnectionKind::parse("corner_up_left"), Some(ConnectionKind::CornerUpLeft)); assert_eq!(ConnectionKind::parse("crossover"), Some(ConnectionKind::CrossOver)); ``` -------------------------------- ### Understand NodeKind Enum for Graph Node Classification in Rust Source: https://context7.com/kdheepak/renderdag/llms.txt Explains the NodeKind enum used in renderdag to classify different types of graph nodes based on their position and relationships. It lists the available kinds, their default glyphs, and demonstrates parsing from and serializing to strings. ```rust use renderdag::NodeKind; // Available node kinds and their default Unicode glyphs: let kinds = [ (NodeKind::Initial, '⊝'), // Root node (no parents) (NodeKind::Node, '●'), // Regular node with parent(s) (NodeKind::NodeLeaf, '⦿'), // Leaf node (no children) (NodeKind::Merge, '⊗'), // Merge node (2+ parents) (NodeKind::MergeLeaf, '⍟'), // Merge that is also a leaf (NodeKind::Orphan, '◌'), // Node with all parents missing (NodeKind::MergeTruncated, '⊘'), // Merge with some parents missing (NodeKind::MergeLeafTruncated, '⊛'), // Truncated merge leaf ]; // Parse from string (case-insensitive, ignores underscores/dashes) assert_eq!(NodeKind::parse("merge_leaf"), Some(NodeKind::MergeLeaf)); assert_eq!(NodeKind::parse("MergeLeaf"), Some(NodeKind::MergeLeaf)); assert_eq!(NodeKind::parse("mergeleaf"), Some(NodeKind::MergeLeaf)); // Serialize to snake_case string assert_eq!(NodeKind::MergeLeaf.as_snake(), "merge_leaf"); ``` -------------------------------- ### GraphRenderer Source: https://context7.com/kdheepak/renderdag/llms.txt The main rendering interface that converts a list of nodes into ASCII or Unicode graph output. It handles layout calculations, lane management, and glyph selection. ```APIDOC ## GraphRenderer ### Description The `GraphRenderer` is the primary entry point for rendering DAGs. It maintains internal state for efficient re-rendering and provides methods to render graphs to strings. The renderer automatically handles all layout calculations, lane management, and glyph selection. ### Usage ```rust use renderdag::{GraphRenderer, Node, RenderConfig}; // Create a renderer with default Unicode glyphs let mut renderer = GraphRenderer::default(); // Define a simple branching history let nodes = vec![ Node::new("d", vec!["b".to_string(), "c".to_string()]), // Merge commit Node::new("c", vec!["a".to_string()]), // Feature branch Node::new("b", vec!["a".to_string()]), // Main branch Node::new("a", vec![]), // Root commit ]; // Render to string let output = renderer.render_to_string(&nodes); println!("{}", output); // Expected Output: // ⍟─╮ d (merge of b and c) // │ ● c // ● │ b // ⊝─╯ a ``` ``` -------------------------------- ### Node Struct Source: https://context7.com/kdheepak/renderdag/llms.txt Represents a node in the Directed Acyclic Graph (DAG). Each node has a unique ID and a list of parent IDs. ```APIDOC ## Node Struct ### Description The `Node` struct represents a graph node with an ID and list of parent IDs. It is the fundamental building block of a DAG, with each node having a unique identifier and references to zero or more parent nodes. This information is used to compute the visual layout and determine node types. ### Usage ```rust use renderdag::Node; // Create nodes for a simple git-like history // Commit "d" has parent "c", "c" has parent "b", etc. let nodes = vec![ Node::new("d", vec!["c".to_string()]), Node::new("c", vec!["b".to_string()]), Node::new("b", vec!["a".to_string()]), Node::new("a", vec![]), // Initial commit, no parents ]; // Merge commit example - node with multiple parents let merge_node = Node::new("merge", vec!["feature".to_string(), "main".to_string()]); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.