|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmapss.dif.graph.DotGenerator
public class DotGenerator
Dot file or string generator for GraphViz graph visualization package. Any
graph that will be used as an input to this class should have a
valid clone()
method. This is because the graph object passed
to the DotGenerator is cloned and cached.
Output files (or strings) obtained from this class can be fed to
Dot or Neato tools of the GraphViz package to generate graphical
representations of mocgraph.Graph
objects. GraphViz package
is developed by AT&T labs and can be found at www.graphviz.org.
Although Dot and Neato are intended for directed and undirected graphs respectively they can handle both kind of graph inputs. Input files are written in "Dot File Format" and generated files will automatically have a ".dot" extension. For more information about the usage of these tools, refer to GraphViz documentation.
DotGenerator class provides two ways for creating dot files (or strings).
First is using the static toFile
methods which don't require
constructing a
DotGenerator object. These methods use the default settings for node and edge
attributes. By default, node labels are copied from the graph using nodeLabel
method and node shapes are ellipses. Second way is by constructing an object
and using its methods. This is required if one needs to change the default
attributes or add new attributes to the visual graph. A clone of the original
graph is used in the DotGenerator object for caching.
To run dot or neato to create a Postscript file following commands can be used in command prompt:
dot | neato -Tps
inputFile -o
outputFile
For further commands see GraphViz documentation.
Graph
Field Summary | |
---|---|
protected java.util.HashMap |
_clusterAttributes
HashMap: Collection cluster -> StringBuffer |
protected java.util.Vector |
_clusters
Each element is a Collection of Nodes. |
protected java.util.HashMap |
_elementAttributes
HashMap: Element -> (AttributeName -> AttributeValue) |
protected java.lang.StringBuffer |
_extraLines
Extra lines/attributes to be added to a graph description before topology definitions. |
protected mocgraph.Graph |
_graph
Clone of the original graph given in the constructor. |
protected boolean |
_isDirected
Should be set to true if the graph is directed. |
protected java.lang.String |
_name
Name of this graph. |
Constructor Summary | |
---|---|
protected |
DotGenerator()
|
|
DotGenerator(mocgraph.Graph graph)
Constructs DotGenerator object associated with a graph. |
Method Summary | |
---|---|
void |
addLine(java.lang.String line)
Inserts a line to before the dot description in a graph. |
boolean |
isClusterNode(mocgraph.Node node)
Returns true if this node is defined within a cluster previously. |
boolean |
setAsDirected(boolean directed)
Sets the DotGenerator object to represent the graph as directed. |
boolean |
setAttribute(java.util.Collection clusterNodes,
java.lang.String line)
Sets an attribute in the cluster. |
java.lang.String |
setAttribute(mocgraph.Element graphElement,
java.lang.String attribute,
java.lang.String value)
Sets an attribute for a node in the graph. |
boolean |
setCluster(java.util.Collection clusterNodes)
Sets a group of nodes as a cluster. |
java.lang.String |
setGraphName(java.lang.String name)
Sets the name for this graph and adds a line to the graph definition to print this name to GraphViz. |
static void |
toFile(mocgraph.Graph graph,
java.lang.String fileName,
boolean isDirected)
Creates fileName.dot from the given graph. |
void |
toFile(java.lang.String fileName)
Creates fileName.dot from the DotGenerator object. |
java.lang.String |
toString()
Creates "dot" code string of the DotGenerator object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected mocgraph.Graph _graph
Graph.clone()
protected java.lang.String _name
protected java.util.HashMap _elementAttributes
Element -> (AttributeName -> AttributeValue)
protected java.util.HashMap _clusterAttributes
Collection cluster -> StringBuffer
protected java.util.Vector _clusters
protected java.lang.StringBuffer _extraLines
protected boolean _isDirected
Constructor Detail |
---|
protected DotGenerator()
public DotGenerator(mocgraph.Graph graph)
This is only required if you need to change the default attributes of the visual graph. Otherwise it is easier to use the static methods.
graph
- A Graph object.Method Detail |
---|
public void addLine(java.lang.String line)
label = "graph_name";
. Semicolons should be included at the end of the line.
line
- Line to be added to the dot description of the graph.
A line feed will automatically be added to the end of the line.public boolean isClusterNode(mocgraph.Node node)
node
- A graph node.public boolean setAsDirected(boolean directed)
public boolean setAttribute(java.util.Collection clusterNodes, java.lang.String line)
addLine(java.lang.String)
works.
clusterNodes
- Cluster for which the attribute is going to be set.line
- Attribute string
public java.lang.String setAttribute(mocgraph.Element graphElement, java.lang.String attribute, java.lang.String value)
ex: setAttribute(graphNode,"label","\"my_node\"")
This method is case sensitive for attributes and values.
graphElement
- A node or edge of the graph to set an attribute
for.attribute
- Attribute that is going to be set.value
- Value for the attribute. Use null if there is no need for
a value.
public boolean setCluster(java.util.Collection clusterNodes)
clusterNodes
- A collection of nodes.
public java.lang.String setGraphName(java.lang.String name)
name
- Name of the graph. It shouldn't include white space or
punctuation.
public void toFile(java.lang.String fileName) throws java.io.IOException
fileName.dot
from the DotGenerator object.
fileName
- Name of the dot file to be created. A ".dot" extension
will be appended to this name.
java.io.IOException
- If the file could not be created.public static void toFile(mocgraph.Graph graph, java.lang.String fileName, boolean isDirected) throws java.io.IOException
fileName.dot
from the given graph.
graph
- A Graph object.fileName
- Name of the dot file to be created. A ".dot" extension
will be appended to this name.isDirected
- True if the graph is directed, false otherwise.
java.io.IOException
- If the file could not be created.public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |