Class GraphvizWriter

java.lang.Object
org.jhotdraw8.graph.io.GraphvizWriter

public class GraphvizWriter extends Object
Writes a graph into a graphviz "dot" file.

Writes the following productions. Does not write subgraphs!

 graph        : digrap [ ID ] '{' stmt_list '}'
 stmt_list    : [ stmt [ ';' ] stmt_list ]
 stmt         : node_stmt
              | edge_stmt
              | attr_stmt
              | ID '=' ID
              | subgraph
 attr_stmt    : (graph | node | edge) attr_list
 attr_list    : '[' [ a_list ] ']' [ attr_list ]
 a_list       : ID '=' ID [ (';' | ',') ] [ a_list ]
 edge_stmt    : (node_id | subgraph) edgeRHS [ attr_list ]
 edgeRHS      : edgeop (node_id | subgraph) [ edgeRHS ]
 node_stmt    : node_id [ attr_list ]  * node_id : ID [ port ]
 port         : ':' ID [ ':' compass_pt ]  * | ':' compass_pt
 subgraph     : [ subgraph [ ID ] ] '{' stmt_list '}'
 compass_pt   : (n | ne | e | se | s | sw | w | nw | c | _)
 edgeop       : -> | --
 

References:

Graphviz. DOT Language.
graphviz.org
  • Constructor Details

    • GraphvizWriter

      public GraphvizWriter()
      Creates a new instance.
  • Method Details

    • write

      public <V, A> void write(@NonNull Appendable w, @NonNull DirectedGraph<V,A> graph) throws IOException
      Dumps a directed graph into a String which can be rendered with the graphviz "dot" tool.
      Type Parameters:
      V - the vertex data type
      A - the arrow data type
      Parameters:
      w - the writer
      graph - the graph
      Throws:
      IOException - if writing fails
    • write

      public <V, A> void write(@NonNull Appendable w, @NonNull DirectedGraph<V,A> graph, @NonNull Function<V,String> vertexToString) throws IOException
      Dumps a directed graph into a String which can be rendered with the graphviz "dot" tool.
      Type Parameters:
      V - the vertex data type
      A - the arrow data type
      Parameters:
      w - the writer
      graph - the graph
      vertexToString - a function that converts a vertex to a String for use as vertex name
      Throws:
      IOException - if writing fails
    • write

      public <V, A> String write(@NonNull DirectedGraph<V,A> graph, @NonNull Function<V,String> vertexToString, @NonNull Function<V,String> vertexAttributes, @NonNull Function<A,String> arrowAttributes)
      Dumps a directed graph into a String which can be rendered with the graphviz "dot" tool.
      Type Parameters:
      V - the vertex data type
      A - the arrow data type
      Parameters:
      graph - the graph
      vertexToString - a function that converts a vertex to a String for use as vertex name
      vertexAttributes - a function that converts a vertex to a String for use as vertex attributes
      arrowAttributes - a function that converts an arrow to a String for use as arrow attributes
      Returns:
      the "dot" string
    • write

      public <V, A> void write(@NonNull Appendable w, @NonNull DirectedGraph<V,A> graph, @NonNull Function<V,String> vertexToString, @Nullable Function<V,String> vertexAttributes, @Nullable Function<A,String> arrowAttributes, @Nullable String graphId) throws IOException
      Dumps a directed graph into a String which can be rendered with the graphviz "dot" tool.
      Type Parameters:
      V - the vertex data type
      A - the arrow data type
      Parameters:
      w - the writer
      graph - the graph
      vertexToString - a function that converts a vertex to a String for use as vertex name
      vertexAttributes - a function that converts a vertex to a String for use as vertex attributes
      arrowAttributes - a function that converts an arrow to a String for use as arrow attributes
      graphId - the id of the graph
      Throws:
      IOException - if writing fails
    • write

      public <V, A> String write(@NonNull DirectedGraph<V,A> graph)
      Dumps the graph graph into a String which can be rendered with the graphviz "dot" tool.
      Type Parameters:
      V - the vertex data type
      A - the arrow data type
      Parameters:
      graph - the graph to be dumped
      Returns:
      the dump