Wireframing | Cell 12 | Cell 14 | Search

The provided Graphviz code is a directed graph written in DOT language, defining a process flow diagram with nodes and edges that represent stages and transitions in the process, and specifying various properties such as layout direction, font, and color.

The Graphviz code defines a directed graph with a specific layout direction and font properties, and it outlines a process flow diagram with nodes and edges representing various stages and transitions. The code also specifies default properties for nodes and edges, allowing for customization of the graph's appearance.

Cell 13

%%
dot

digraph
apply
{
    rankdir = BT;
    fontname = Helvetica
    node[peripheries = 0, style = filled, fillcolor = blue, fontcolor = white, fontname = Helvetica, fixedsize = true, width = 1.8, height = 0.8]
    edge[fontname = Helvetica, fontsize = 12, fontcolor = blue, labeldistance = 1.8]

    subgraph
    cluster_student
    {
        label = 'Student';
        style = filled;
        fillcolor = grey92
        submit [shape = record, style = 'filled,rounded', label = 'Submit\nRegistration\n']
        letter [shape = box, peripheries = 0, label = 'Letter']
    }
    subgraph
    cluster_admin
    {
        label = 'Admin'
        style = filled;
        fillcolor = grey92
        complete  [shape = diamond, height = 1.5, label = 'Application\nComplete?']
        admreject [shape = record, label = 'Write Rejection\nLetter\n']
    }
    subgraph
    cluster_registrar
    {
        label = 'Registrar'
        style = filled;
        fillcolor = grey92
        min [shape = diamond, height = 1.8, label = 'Minimum\nStandard\nMet?']
    }
    subgraph
    cluster_faculty
    {
        label = 'Faculty'
        style = filled;
        fillcolor = grey92
        {
            rank = same;
            suitable  [shape = diamond, height = 1.8, label = 'Suitable for\nProgram?\n']
            facaccept [shape = record, label = 'Write Acceptance\nLetter\n']
        }
    }

    submit -> complete
    complete -> submit     [headlabel = 'no']
    complete -> min        [headlabel = 'yes']
    min -> admreject       [headlabel = 'no']
    min -> suitable        [headlabel = 'yes']
    suitable -> admreject  [headlabel = 'no']
    suitable -> facaccept  [headlabel = 'yes']
    admreject -> letter
    facaccept -> letter
}

What the code could have been:

typescript
// Import the Graphviz library
import * as Graphviz from 'graphviz';

// Create a new directed graph object
const dot = new Graphviz.Digraph({
  filename: 'example',
  dir: 'LR',
});

// Set the font and style for all nodes
dot.setGraph({
  rankdir: 'BT',
  fontname: 'Helvetica',
});

// Set the visual style for all nodes
dot.node().setStyle({
  peripheries: 0,
  style: 'filled',
  fillcolor: 'blue',
  fontcolor: 'white',
  fixedsize: true,
  height: 0.8,
  width: 1.8,
});

// Set the font style for all edges
dot.edge().setStyle({
  fontname: 'Helvetica',
  fontsize: 12,
  fontcolor: 'blue',
  labeldistance: 1.8,
});

// Define the student cluster
dot.subgraph('cluster_student', {
  label: 'Student',
  style: 'filled',
  fillcolor: 'grey92',
  node: {
    shape:'record',
    style: 'filled, rounded',
    label: 'Submit\nRegistration\n',
  },
  node: {
    shape: 'box',
    peripheries: 0,
    label: 'Letter',
  },
});

// Define the admin cluster
dot.subgraph('cluster_admin', {
  label: 'Admin',
  style: 'filled',
  fillcolor: 'grey92',
  node: {
    shape: 'diamond',
    height: 1.5,
    label: 'Application\nComplete?',
  },
  node: {
    shape:'record',
    label: 'Write Rejection\nLetter\n',
  },
});

// Define the registrar cluster
dot.subgraph('cluster_registrar', {
  label: 'Registrar',
  style: 'filled',
  fillcolor: 'grey92',
  node: {
    shape: 'diamond',
    height: 1.8,
    label: 'Minimum\nStandard\nMet?',
  },
});

// Define the faculty cluster
dot.subgraph('cluster_faculty', {
  label: 'Faculty',
  style: 'filled',
  fillcolor: 'grey92',
  node: {
    shape: 'diamond',
    height: 1.8,
    label: 'Suitable for\nProgram?\n',
  },
  node: {
    shape:'record',
    label: 'Write Acceptance\nLetter\n',
  },
});

// Define the edges between nodes
dot.addEdge('submit', 'complete');
dot.addEdge('complete','submit', { label: 'no' });
dot.addEdge('complete','min', { label: 'yes' });
dot.addEdge('min', 'admreject', { label: 'no' });
dot.addEdge('min','suitable', { label: 'yes' });
dot.addEdge('suitable', 'admreject', { label: 'no' });
dot.addEdge('suitable', 'facaccept', { label: 'yes' });
dot.addEdge('admreject', 'letter');
dot.addEdge('facaccept', 'letter');

// Render the graph
dot.render('png', (err, graph) => {
  if (err) {
    console.error(err);
  } else {
    console.log(graph);
  }
});

Graphviz Code Breakdown

This is a Graphviz code written in DOT language, which is used to create directed graphs.

Graph Definition

digraph apply {
   ...
}

Graph Properties

rankdir = BT;
fontname = Helvetica

Node Properties

node[peripheries = 0, style = filled, fillcolor = blue, fontcolor = white, fontname = Helvetica, fixedsize = true, width = 1.8, height = 0.8]

Edge Properties

edge[fontname = Helvetica, fontsize = 12, fontcolor = blue, labeldistance = 1.8]

Subgraphs

The code defines four subgraphs: cluster_student, cluster_admin, cluster_registrar, and cluster_faculty. Each subgraph represents a stage in a process.

Nodes and Edges

Within each subgraph, nodes and edges are defined to represent the stages and transitions between them.

For example:

submit -> complete
complete -> submit     [headlabel = 'no']
complete -> min        [headlabel = 'yes']

This code can be used to create a process flow diagram using Graphviz tools.