Yog.FSharp
Getting Started Examples API Reference GitHub

Dot Module

DOT (Graphviz) graph rendering.

Provides functions to export graphs in DOT format for visualization with Graphviz tools.

Example

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
open Yog.IO
open Yog.Model

let graph =
    empty Directed
    |> addNode 1 "Start"
    |> addNode 2 "End"
    |> addEdge 1 2 5

// Export to DOT for Graphviz
let dot = Dot.render Dot.defaultOptions graph
File.WriteAllText("graph.dot", dot)
namespace Yog
namespace Yog.IO
module Model from Yog
<summary> Core graph data structures and basic operations for the yog library. This module defines the fundamental `Graph` type and provides all basic operations for creating and manipulating graphs. The graph uses an adjacency list representation with dual indexing (both outgoing and incoming edges) for efficient traversal in both directions. </summary>
val graph: Graph<string,int>
val empty: graphType: GraphType -> Graph<'n,'e>
<summary> Creates a new empty graph of the specified type. ## Example ```fsharp let graph = Model.empty Directed ``` </summary>
union case GraphType.Directed: GraphType
<summary> A directed graph where edges have a direction from source to destination. </summary>
val addNode: id: NodeId -> data: 'n -> graph: Graph<'n,'e> -> Graph<'n,'e>
<summary> Adds a node to the graph with the given ID and data. If a node with this ID already exists, its data will be replaced. ## Example ```fsharp graph |&gt; addNode 1 "Node A" |&gt; addNode 2 "Node B" ``` </summary>
val addEdge: src: NodeId -> dst: NodeId -> weight: 'e -> graph: Graph<'n,'e> -> Graph<'n,'e>
<summary> Adds an edge to the graph with the given weight. For directed graphs, adds a single edge from src to dst. For undirected graphs, adds edges in both directions. &gt; **Note:** If `src` or `dst` have not been added via `addNode`, &gt; the edge will still be created in the edge dictionaries, but the &gt; nodes will be missing from `graph.Nodes`. This creates "ghost nodes" &gt; that are traversable but invisible to functions that iterate over &gt; nodes (e.g. `order`, `allNodes`). Use `addEdgeEnsured` to &gt; auto-create missing endpoints with a default value. ## Example ```fsharp graph |&gt; addEdge 1 2 10 ``` </summary>
val dot: string
module Dot from Yog.IO
<summary> DOT (Graphviz) graph rendering. Provides functions to export graphs in DOT format for visualization with Graphviz tools. ## Example ```fsharp open Yog.IO open Yog.Model let graph = empty Directed |&gt; addNode 1 "Start" |&gt; addNode 2 "End" |&gt; addEdge 1 2 5 // Export to DOT for Graphviz let dot = Dot.render Dot.defaultOptions graph File.WriteAllText("graph.dot", dot) ``` </summary>
val render: options: Dot.Options<'n,'e> -> graph: Graph<'n,'e> -> string
<summary> Converts a graph to DOT (Graphviz) syntax. The DOT format can be processed by Graphviz tools: `dot -Tpng -o graph.png graph.dot` **Time Complexity:** O(V + E) ## Example ```fsharp let graph = empty Directed |&gt; addNode 1 "Start" |&gt; addNode 2 "Process" |&gt; addEdge 1 2 "5" let options = { Dot.defaultOptions with NodeLabel = fun id data -&gt; $"{id}:{data}" HighlightedNodes = Set.ofList [1] } let diagram = Dot.render options graph // digraph G { // node [shape=ellipse]; // 1 [label="1:Start", fillcolor="red", style=filled]; // 2 [label="2:Process"]; // 1 -&gt; 2 [label="5"]; // } ``` ## Use Cases - Professional graph visualization - Publication-quality diagrams - Complex graph layouts (hierarchical, circular, etc.) </summary>
val defaultOptions<'n,'e> : Dot.Options<'n,'e>
<summary> Default configuration for DOT output. Uses node ID as a label and edge weight as a string. </summary>

Types

Type Description

Options<'n, 'e>

Options for customizing DOT (Graphviz) diagram rendering.

Functions and values

Function or value Description

defaultOptions

Full Usage: defaultOptions

Returns: Options<'n, 'e>

Default configuration for DOT output.

Uses node ID as a label and edge weight as a string.

Returns: Options<'n, 'e>

render options graph

Full Usage: render options graph

Parameters:
Returns: string

Converts a graph to DOT (Graphviz) syntax.

The DOT format can be processed by Graphviz tools: dot -Tpng -o graph.png graph.dot

Time Complexity: O(V + E)

Example

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
let graph =
    empty Directed
    |> addNode 1 "Start"
    |> addNode 2 "Process"
    |> addEdge 1 2 "5"

let options = { Dot.defaultOptions with
    NodeLabel = fun id data -> $"{id}:{data}"
    HighlightedNodes = Set.ofList [1]
}

let diagram = Dot.render options graph
// digraph G {
//   node [shape=ellipse];
//   1 [label="1:Start", fillcolor="red", style=filled];
//   2 [label="2:Process"];
//   1 -> 2 [label="5"];
// }

Use Cases

  • Professional graph visualization
  • Publication-quality diagrams
  • Complex graph layouts (hierarchical, circular, etc.)
val graph: obj
val options: bool
val id: x: 'T -> 'T
Multiple items
module Set from Microsoft.FSharp.Collections

--------------------
type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: objnull -> bool ...

--------------------
new: elements: 'T seq -> Set<'T>
val ofList: elements: 'T list -> Set<'T> (requires comparison)
val diagram: obj

options : Options<'n, 'e>
graph : Graph<'n, 'e>
Returns: string

writeFile path options graph

Full Usage: writeFile path options graph

Parameters:
    path : string
    options : Options<'n, 'e>
    graph : Graph<'n, 'e>

Renders a graph to a DOT file.

Example

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let graph =
    empty Directed
    |> addNode 1 "A"
    |> addNode 2 "B"
    |> addEdge 1 2 5

Dot.writeFile "output.dot" Dot.defaultOptions graph
val graph: obj

path : string
options : Options<'n, 'e>
graph : Graph<'n, 'e>