yog/render/dot

DOT (Graphviz) format export for visualizing graphs.

This module exports graphs to the DOT language, which is the native format for Graphviz - a powerful open-source graph visualization tool. The exported files can be rendered to PNG, SVG, PDF, and other formats using the dot, neato, circo, or other Graphviz layout engines.

Quick Start

import yog/render/dot

// Export with default styling
let dot_string = dot.to_string(my_graph)

// Write to file and render with Graphviz CLI
// $ dot -Tpng output.dot -o graph.png

Customization

Use DotOptions to customize:

Rendering Options

EngineBest For
dotHierarchical layouts (DAGs, trees)
neatoSpring-based layouts (undirected)
circoCircular layouts
fdpForce-directed layouts
sfdpLarge graphs

References

Types

Arrow head/tail style

pub type ArrowStyle {
  Normal
  ArrowDot
  ArrowDiamond
  ODiamond
  ArrowBox
  Crow
  Vee
  Inv
  Tee
  ArrowNone
  CustomArrow(String)
}

Constructors

  • Normal

    Standard arrow

  • ArrowDot

    Dot circle

  • ArrowDiamond

    Filled diamond

  • ODiamond

    Empty diamond

  • ArrowBox

    ArrowBox

  • Crow

    Crow’s foot (database notation)

  • Vee

    V-shaped

  • Inv

    Inverted V

  • Tee

    Tee (perpendicular line)

  • ArrowNone

    No arrow

  • CustomArrow(String)

    Custom arrow (e.g., “ediamond”, “odot”)

Options for customizing DOT (Graphviz) diagram rendering.

pub type DotOptions {
  DotOptions(
    node_label: fn(Int, String) -> String,
    edge_label: fn(String) -> String,
    highlighted_nodes: option.Option(List(Int)),
    highlighted_edges: option.Option(List(#(Int, Int))),
    graph_name: String,
    layout: option.Option(Layout),
    rankdir: option.Option(RankDir),
    bgcolor: option.Option(String),
    splines: option.Option(Splines),
    overlap: option.Option(Overlap),
    nodesep: option.Option(Float),
    ranksep: option.Option(Float),
    node_shape: NodeShape,
    node_color: String,
    node_style: Style,
    node_fontname: String,
    node_fontsize: Int,
    node_fontcolor: String,
    edge_color: String,
    edge_style: Style,
    edge_fontname: String,
    edge_fontsize: Int,
    edge_penwidth: Float,
    arrowhead: option.Option(ArrowStyle),
    arrowtail: option.Option(ArrowStyle),
    highlight_color: String,
    highlight_penwidth: Float,
  )
}

Constructors

  • DotOptions(
      node_label: fn(Int, String) -> String,
      edge_label: fn(String) -> String,
      highlighted_nodes: option.Option(List(Int)),
      highlighted_edges: option.Option(List(#(Int, Int))),
      graph_name: String,
      layout: option.Option(Layout),
      rankdir: option.Option(RankDir),
      bgcolor: option.Option(String),
      splines: option.Option(Splines),
      overlap: option.Option(Overlap),
      nodesep: option.Option(Float),
      ranksep: option.Option(Float),
      node_shape: NodeShape,
      node_color: String,
      node_style: Style,
      node_fontname: String,
      node_fontsize: Int,
      node_fontcolor: String,
      edge_color: String,
      edge_style: Style,
      edge_fontname: String,
      edge_fontsize: Int,
      edge_penwidth: Float,
      arrowhead: option.Option(ArrowStyle),
      arrowtail: option.Option(ArrowStyle),
      highlight_color: String,
      highlight_penwidth: Float,
    )

    Arguments

    node_label

    Function to convert node ID and data to a display label

    edge_label

    Function to convert edge weight to a display label

    highlighted_nodes

    Optional list of node IDs to highlight

    highlighted_edges

    Optional list of edges to highlight as (from, to) pairs

    graph_name

    Graph name (default: “G”)

    layout

    Layout engine (default: None = auto-detect)

    rankdir

    Graph direction (default: Some(TopToBottom))

    bgcolor

    Background color (CSS color, default: None)

    splines

    Edge routing (default: None = Graphviz default)

    overlap

    Overlap handling (default: None)

    nodesep

    Minimum space between nodes in inches (default: 0.25)

    ranksep

    Minimum space between ranks in inches (default: 0.5)

    node_shape

    Node shape (default: Ellipse)

    node_color

    Default node fill color (CSS color)

    node_style

    Node style (default: Filled)

    node_fontname

    Node font name (default: “Helvetica”)

    node_fontsize

    Node font size in points (default: 12)

    node_fontcolor

    Node font color (CSS color, default: “black”)

    edge_color

    Default edge color (CSS color, default: “black”)

    edge_style

    Edge style (default: Solid)

    edge_fontname

    Edge font name (default: “Helvetica”)

    edge_fontsize

    Edge font size in points (default: 10)

    edge_penwidth

    Edge line thickness (default: 1.0)

    arrowhead

    Arrow head style (default: None = Graphviz default)

    arrowtail

    Arrow tail style (default: None)

    highlight_color

    Highlight color for nodes/edges (CSS color, default: “red”)

    highlight_penwidth

    Highlight pen width (default: 2.0)

Graphviz layout engine

pub type Layout {
  Dot
  Neato
  Circo
  Fdp
  Sfdp
  Twopi
  Osage
  CustomLayout(String)
}

Constructors

  • Dot

    Hierarchical layouts (DAGs, trees) - default for most use cases

  • Neato

    Spring-based layouts (undirected graphs)

  • Circo

    Circular layouts

  • Fdp

    Force-directed placement

  • Sfdp

    Scalable force-directed (for large graphs)

  • Twopi

    Radial layouts

  • Osage

    Clustered layouts (array-based)

  • CustomLayout(String)

    Custom layout engine

Node shapes

pub type NodeShape {
  Box
  Circle
  Ellipse
  Diamond
  Hexagon
  Pentagon
  Octagon
  Triangle
  Rectangle
  Square
  Rect
  InvTriangle
  House
  InvHouse
  Parallelogram
  Trapezoid
  CustomShape(String)
}

Constructors

  • Box
  • Circle
  • Ellipse
  • Diamond
  • Hexagon
  • Pentagon
  • Octagon
  • Triangle
  • Rectangle
  • Square
  • Rect

    Rounded rectangle

  • InvTriangle

    Inverted triangle

  • House

    House shape (pentagon with flat top)

  • InvHouse

    Inverted house

  • Parallelogram

    Parallelogram

  • Trapezoid

    Trapezoid

  • CustomShape(String)

    Custom shape (for advanced Graphviz shapes)

Overlap handling

pub type Overlap {
  OverlapTrue
  OverlapFalse
  Scale
  ScaleXY
  Prism
  CustomOverlap(String)
}

Constructors

  • OverlapTrue

    Allow overlaps (faster)

  • OverlapFalse

    Remove all overlaps (slower)

  • Scale

    Scale graph to remove overlaps

  • ScaleXY

    Scale x and y independently

  • Prism

    Prism algorithm (Voronoi-based)

  • CustomOverlap(String)

    Custom overlap mode

Graph direction (rank direction)

pub type RankDir {
  TopToBottom
  LeftToRight
  BottomToTop
  RightToLeft
}

Constructors

  • TopToBottom

    Top to Bottom (vertical, downward)

  • LeftToRight

    Left to Right (horizontal)

  • BottomToTop

    Bottom to Top (vertical, upward)

  • RightToLeft

    Right to Left (horizontal, reversed)

Edge routing style

pub type Splines {
  Line
  Polyline
  Curved
  Ortho
  Spline
  SplinesNone
}

Constructors

  • Line

    Straight lines

  • Polyline

    Polyline (bent lines)

  • Curved

    Curved edges

  • Ortho

    Orthogonal (right angles only)

  • Spline

    Bezier splines (smooth curves) - Graphviz default

  • SplinesNone

    No edges

Visual style

pub type Style {
  Solid
  Dashed
  Dotted
  Bold
  Filled
  Rounded
  Diagonals
  Striped
  Wedged
}

Constructors

  • Solid
  • Dashed
  • Dotted
  • Bold
  • Filled
  • Rounded
  • Diagonals
  • Striped
  • Wedged

Values

pub fn default_dot_options() -> DotOptions

Creates default DOT options with simple labeling and sensible styling.

Default configuration:

  • Layout: Auto-detected by Graphviz
  • Direction: Top-to-bottom
  • Node shape: Ellipse
  • Colors: Light blue nodes, black edges
  • Font: Helvetica 12pt
pub fn path_to_dot_options(
  path: utils.Path(e),
  base_options: DotOptions,
) -> DotOptions

Converts a shortest path result to highlighted DOT options.

pub fn to_dot(
  graph: model.Graph(String, String),
  options: DotOptions,
) -> String

Converts a graph to DOT (Graphviz) syntax.

The graph’s node data and edge data must be convertible to strings. Use the options to customize labels and highlighting.

Time Complexity: O(V + E)

Example

let graph =
  model.new(Directed)
  |> model.add_node(1, "Start")
  |> model.add_node(2, "Process")
  |> model.add_edge(from: 1, to: 2, with: "5")

let diagram = dot.to_dot(graph, default_dot_options())
// io.println(diagram)

This output can be processed by Graphviz tools (e.g., dot -Tpng -o graph.png):

digraph G {
  node [shape=ellipse];
  1 [label="Start"];
  2 [label="Process"];
  1 -> 2 [label="5"];
}
Search Document