- java.lang.Object
-
- org.jgrapht.nio.BaseExporter<V,E>
-
- org.jgrapht.nio.dot.DOTExporter<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- 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 Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_GRAPH_ID
Default graph id used by the exporter.private static java.lang.String
INDENT
private java.util.Map<V,java.lang.String>
validatedIds
-
Fields inherited from class org.jgrapht.nio.BaseExporter
edgeAttributeProvider, edgeIdProvider, graphAttributeProvider, graphIdProvider, vertexAttributeProvider, vertexIdProvider
-
-
Constructor Summary
Constructors Constructor Description DOTExporter()
Constructs a new DOTExporter object with an integer id provider.DOTExporter(java.util.function.Function<V,java.lang.String> vertexIdProvider)
Constructs a new DOTExporter object with the given id provider.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
computeConnector(Graph<V,E> graph)
Compute the connectorprivate java.lang.String
computeFooter(Graph<V,E> graph)
Compute the footerprivate java.lang.String
computeGraphId(Graph<V,E> graph)
Get the id of the graph.private java.lang.String
computeHeader(Graph<V,E> graph)
Compute the headerprivate static java.lang.String
escapeDoubleQuotes(java.lang.String labelName)
void
exportGraph(Graph<V,E> g, java.io.Writer writer)
Exports a graph into a plain text file in DOT format.private java.lang.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.htmlprivate void
renderAttribute(java.io.PrintWriter out, java.lang.String attrName, Attribute attribute)
private void
renderAttributes(java.io.PrintWriter out, java.util.Map<java.lang.String,Attribute> attributes)
-
Methods inherited from class org.jgrapht.nio.BaseExporter
getEdgeAttribute, getEdgeAttributeProvider, getEdgeAttributes, getEdgeId, getEdgeIdProvider, getGraphAttribute, getGraphAttributeProvider, getGraphId, getGraphIdProvider, getVertexAttribute, getVertexAttributeProvider, getVertexAttributes, getVertexId, getVertexIdProvider, setEdgeAttributeProvider, setEdgeIdProvider, setGraphAttributeProvider, setGraphIdProvider, setVertexAttributeProvider, setVertexIdProvider
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgrapht.nio.GraphExporter
exportGraph, exportGraph
-
-
-
-
Field Detail
-
DEFAULT_GRAPH_ID
public static final java.lang.String DEFAULT_GRAPH_ID
Default graph id used by the exporter.- See Also:
- Constant Field Values
-
INDENT
private static final java.lang.String INDENT
- See Also:
- Constant Field Values
-
validatedIds
private final java.util.Map<V,java.lang.String> validatedIds
-
-
Constructor Detail
-
DOTExporter
public DOTExporter()
Constructs a new DOTExporter object with an integer id provider.
-
DOTExporter
public DOTExporter(java.util.function.Function<V,java.lang.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 Detail
-
exportGraph
public void exportGraph(Graph<V,E> g, java.io.Writer writer)
Exports a graph into a plain text file in DOT format.- Specified by:
exportGraph
in interfaceGraphExporter<V,E>
- Parameters:
g
- the graph to be exportedwriter
- the writer to which the graph to be exported
-
computeHeader
private java.lang.String computeHeader(Graph<V,E> graph)
Compute the header- Parameters:
graph
- the graph- Returns:
- the header
-
computeFooter
private java.lang.String computeFooter(Graph<V,E> graph)
Compute the footer- Parameters:
graph
- the graph- Returns:
- the footer
-
computeConnector
private java.lang.String computeConnector(Graph<V,E> graph)
Compute the connector- Parameters:
graph
- the graph- Returns:
- the connector
-
computeGraphId
private java.lang.String computeGraphId(Graph<V,E> graph)
Get the id of the graph.- Parameters:
graph
- the graph- Returns:
- the graph id
-
renderAttributes
private void renderAttributes(java.io.PrintWriter out, java.util.Map<java.lang.String,Attribute> attributes)
-
renderAttribute
private void renderAttribute(java.io.PrintWriter out, java.lang.String attrName, Attribute attribute)
-
escapeDoubleQuotes
private static java.lang.String escapeDoubleQuotes(java.lang.String labelName)
-
getVertexID
private java.lang.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.htmlQuoted 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 (<...>).
- Throws:
ExportException
- if the givenvertexIDProvider
didn't generate a valid vertex ID.
-
-