Chapter 14. Graphviz DOT

14. Graphviz DOT

Graphviz https://graphviz.org/ is a powerful tool for creating diagrams and visual representations of graphs using the DOT language. The DOT language allows you to describe the nodes and edges of a graph in a plain text format, which Graphviz then uses to render the graph visually.

Below is an overview of the features, along with examples demonstrating various elements of DOT syntax. For complete documentation on DOT syntax, visit the Graphviz documentation: https://graphviz.org/. You can find many more examples here: https://graphviz.org/gallery/.

Please note the availability of a dot-renderer REST service. Detailed information about this REST service is provided in Section 12.5. This service can be accessed via URL, for example: https://SERVER:PORT/reportserverbasedir/reportserver/rest/dot-renderer?path=/fileserver/resources/graph.dot&user=myuser&apikey=MYAPIKEY. Additionally, the DOT renderer can be utilized through scripting (net.datenwerke.rs.dot.service.dot.DotService). Refer to the Scripting Guide for more details.
Please note that you can embed DOT files directly within Markdown syntax. You can also specify the width and height of the rendered SVG. For more details, refer to Section 13.1.10.
Please be aware that the DOT renderer creates a temporary file in your user.home directory. Therefore, this directory must have read and write permissions for your Tomcat server. You can verify if this directory is readable in the "General Information" section of your system console under the "User home" entry. Additionally, ensure that this directory is writable.

In ReportServer, it's crucial to set the content type of your DOT file (e.g., myfile.dot) to ''text/vnd.graphviz''. This ensures that ReportServer recognizes the file as a DOT file and can convert it to SVG.

Note that if the file's content type is not set to ''text/vnd.graphviz'', the preview tab and preview buttons will not be available.

Features

Preview SVG Tab Located in the file system administration window, this tab allows users to preview DOT content directly within ReportServer, rendered as SVG.
Preview SVG Button Found in the Properties tab of the file system administration window, this button renders the DOT content and exports it as an SVG in a new window.
14.1. Basic DOT Syntax

A DOT file consists of a graph definition, which includes nodes, edges, and their attributes. The basic structure of a DOT file is as follows:

Graph Represents an undirected graph.
Digraph Represents a directed graph.
Node Represents a node in the graph.
Edge Represents an edge between two nodes

Example of an Undirected Graph:

graph G {
    A -- B;
    B -- C;
    C -- D;
    D -- A;
}

This is a preview of the result rendering.

Example of a Directed Graph:

digraph G {
    A -> B;
    B -> C;
    C -> D;
    D -> A;
}

This is a preview of the result rendering.

14.1.1. Nodes and Edges

Nodes and edges can be customized with various attributes such as labels, colors, shapes, and styles.

Example with node and edge attributes:

digraph G {
    node [shape=circle, color=lightblue, style=filled];
    A -> B [label="A to B", color=red];
    B -> C [label="B to C", color=green];
    C -> D [label="C to D", color=blue];
    D -> A [label="D to A", color=purple];
}

This is a preview of the result rendering.

Below is an overview of node attributes:

shape Defines the shape of the node (e.g., circle, box, ellipse).
color Defines the color of the node.
style Defines the style of the node (e.g., filled, dashed, dotted).

Below is an overview of edge attributes

label Defines a label for the edge.
color Defines the color of the edge.
style Defines the style of the edge (solid, dashed, dotted).
14.1.2. Subgraphs

Subgraphs are used to group nodes and edges together, which can help in organizing complex graphs or applying common attributes to a group of nodes and edges.

Example of Subgraphs

digraph G {
    subgraph cluster_0 {
        node [style=filled, color=lightgrey];
        A -> B;
        B -> C;
        label = "Cluster 0";
    }

    subgraph cluster_1 {
        node [style=filled, color=lightblue];
        D -> E;
        E -> F;
        label = "Cluster 1";
    }

    C -> D;
    F -> A;
}

This is a preview of the result rendering.

14.1.3. Graph Attributes

Graph attributes define the overall appearance and layout of the graph.

digraph G {
    graph [rankdir=LR, bgcolor=lightyellow];
    node [shape=ellipse, style=filled, color=lightgreen];
    edge [color=black];

    A -> B;
    B -> C;
    C -> D;
    D -> A;
}

This is a preview of the result rendering.

An overview of the graph attributes is shown below.

rankdir Defines the direction of the graph layout (TB for top to bottom, LR for left to right).
bgcolorr Defines the background color of the graph.