Class DOTExporter<V,E>

java.lang.Object
org.jgrapht.nio.BaseExporter<V,E>
org.jgrapht.nio.dot.DOTExporter<V,E>
Type Parameters:
V - the graph vertex type
E - the graph edge type
All Implemented Interfaces:
GraphExporter<V,E>

public class DOTExporter<V,E> extends BaseExporter<V,E> implements GraphExporter<V,E>
Exports a graph into a DOT file.

For a description of the format see http://en.wikipedia.org/wiki/DOT_language.

The user can adjust the behavior using the various providers.
  • Field Details

  • Constructor Details

    • DOTExporter

      public DOTExporter()
      Constructs a new DOTExporter object with an integer id provider.
    • DOTExporter

      public DOTExporter(Function<V,String> vertexIdProvider)
      Constructs a new DOTExporter object with the given id provider. Additional providers such as attributes can be given using the appropriate setter methods.
      Parameters:
      vertexIdProvider - for generating vertex IDs. Must not be null.
  • Method Details

    • exportGraph

      public void exportGraph(Graph<V,E> g, Writer writer)
      Exports a graph into a plain text file in DOT format.
      Specified by:
      exportGraph in interface GraphExporter<V,E>
      Parameters:
      g - the graph to be exported
      writer - the writer to which the graph to be exported
    • computeHeader

      private String computeHeader(Graph<V,E> graph)
      Compute the header
      Parameters:
      graph - the graph
      Returns:
      the header
    • computeFooter

      private String computeFooter(Graph<V,E> graph)
      Compute the footer
      Parameters:
      graph - the graph
      Returns:
      the footer
    • computeConnector

      private String computeConnector(Graph<V,E> graph)
      Compute the connector
      Parameters:
      graph - the graph
      Returns:
      the connector
    • computeGraphId

      private String computeGraphId(Graph<V,E> graph)
      Get the id of the graph.
      Parameters:
      graph - the graph
      Returns:
      the graph id
    • renderAttributes

      private void renderAttributes(PrintWriter out, Map<String,Attribute> attributes)
    • renderAttribute

      private void renderAttribute(PrintWriter out, String attrName, Attribute attribute)
    • escapeDoubleQuotes

      private static String escapeDoubleQuotes(String labelName)
    • getVertexID

      private String getVertexID(V v)
      Return a valid vertex ID (with respect to the .dot language definition as described in http://www.graphviz.org/doc/info/lang.html

      Quoted from above mentioned source: An ID is valid if it meets one of the following criteria:

      • any string of alphabetic characters, underscores or digits, not beginning with a digit;
      • a number [-]?(.[0-9]+ | [0-9]+(.[0-9]*)? );
      • any double-quoted string ("...") possibly containing escaped quotes (\");
      • an HTML string (invalid input: '<'...>).
      Throws:
      ExportException - if the given vertexIDProvider didn't generate a valid vertex ID.