GraphvizDocument Class

A graph read from the DOT language of Graphviz, drawn as a FlowchartDiagram: the nodes, the edges and the clusters, with their shapes, styles, colors and labels. The layout is the layered layout of the flowcharts, close to the dot engine of Graphviz.

public sealed class GraphvizDocument

Example

var text = """
    digraph Orders {
        rankdir=LR;
        node [shape=box, style=rounded];
        start [label="Order received", shape=ellipse];
        check [label="Payment valid?", shape=diamond];
        subgraph cluster_fulfillment {
            label="Fulfillment";
            ship [label="Ship the order"];
            notify [label="Notify the customer"];
        }
        cancel [label="Cancel the order", color=red];
        start -> check;
        check -> ship [label="yes"];
        ship -> notify;
        check -> cancel [label="no", style=dashed];
    }
    """;

var document = GraphvizDocument.Parse(text);
var flowchart = document.Diagram;
var svg = flowchart.ToSvg();

Properties

NameDescription
DiagramGets the flowchart of the graph. The clusters (the subgraphs whose name starts with cluster) are its subgraphs.
IsDirectedGets a value that indicates whether the graph is directed (digraph). The edges of an undirected graph have no arrowheads.
IsStrictGets a value that indicates whether the graph is strict: the edges between the same nodes are merged.
NameGets the name of the graph (digraph name { }), or null when it has none.
WarningsGets the parts of the text that are valid DOT but are not supported, and are ignored or approximated.

Gets the flowchart of the graph. The clusters (the subgraphs whose name starts with cluster) are its subgraphs.

public FlowchartDiagram Diagram { get; }

Property value

FlowchartDiagram

Gets a value that indicates whether the graph is directed (digraph). The edges of an undirected graph have no arrowheads.

public bool IsDirected { get; }

Property value

bool

Gets a value that indicates whether the graph is strict: the edges between the same nodes are merged.

public bool IsStrict { get; }

Property value

bool

Gets the name of the graph (digraph name { }), or null when it has none.

public string? Name { get; }

Property value

string?

Gets the parts of the text that are valid DOT but are not supported, and are ignored or approximated.

public IReadOnlyList<GraphvizWarning> Warnings { get; }

Methods

NameDescription
Parse(string, GraphvizParseOptions?)Reads a DOT text. Only its first graph is read.
TryParse(string?, GraphvizDocument?)Tries to read a DOT text.
TryParse(string?, GraphvizParseOptions?, GraphvizDocument?, GraphvizParseError)Tries to read a DOT text.

Parse(string, GraphvizParseOptions?)

GraphvizDocument.cs

Reads a DOT text. Only its first graph is read.

public static GraphvizDocument Parse(string text, GraphvizParseOptions? options = null)

Parameters

text string
The text.
options GraphvizParseOptions?
The options, or null for GraphvizParseOptions.Default.

Returns

GraphvizDocument The document.

Exceptions

GraphvizParseException
The text is not valid, or it exceeds a limit of the options.

TryParse overloads

TryParse(string?, GraphvizDocument?)

GraphvizDocument.cs

Tries to read a DOT text.

public static bool TryParse(string? text, out GraphvizDocument? document)
Parameters
text string?
The text.
document GraphvizDocument?
The document, when the method returns true.
Returns

bool true when the text is valid.

TryParse(string?, GraphvizParseOptions?, GraphvizDocument?, GraphvizParseError)

GraphvizDocument.cs

Tries to read a DOT text.

public static bool TryParse(string? text, GraphvizParseOptions? options, out GraphvizDocument? document, out GraphvizParseError error)
Parameters
text string?
The text.
options GraphvizParseOptions?
The options, or null for GraphvizParseOptions.Default.
document GraphvizDocument?
The document, when the method returns true.
error GraphvizParseError
The error, when the method returns false.
Returns

bool true when the text is valid.