I'm trying to use GraphViz to draw graphical models. However, I didn't find a way to make draw overlapping clusters. For example, how can I make "nodeA->nodeB" to lie inside both clusterA and clusterB?
AFAIK you can't.
Clusters as described in the documentation:
If the name of the subgraph begins with cluster, Graphviz notes the
subgraph as a special cluster subgraph. If supported, the layout
engine will do the layout so that the nodes belonging to the cluster
are drawn together, with the entire drawing of the cluster contained
within a bounding rectangle.
The whole idea of clusters is not to overlap, but to group nodes (and graphviz raises an error when a node is part of two subgraphs).
Related
I have a graph with a lot of objects. A number of these objects have no links. GraphVis lays these out on one long horizontal line on the top of the diagram.
Is there anyway to make GraphViz have a maximum width, so unconnected objects go on the next "line" ?
Add invisible edges between them. This will force graphviz to layout these nodes like the ordinary ones.
I would like to use graphviz for a project and am unable to get the behaviour I want. I have a graph that I can draw with graphviz just fine, but I also have a version of the same graph that has some extra edges. I would like the second graph to be drawn with the nodes in the same positions as the first one and the edges in the same positions, but the new edges to be drawn without avoiding any overlap with nodes.
To get a better idea of what I want, imagine a Powerpoint slide with a graph and then on the next slide the same graph with these extra edges that appear on top of the first graph, wihtout modifying the look of the old parts of the graph. That is the effect I want.
I think the effect could be achieved by having some edges ignore any overlapping constraints. I could not figure out how to control the overlap between edges and nodes for particular edges (or even for all edges).
Any ideas?
You can get dot to output another .dot file, with positions assigned to all elements, via dot -Tdot (or maybe dot -Txdot). Add your additional edges to that file, and run it through dot again to produce your second graph.
I am trying to draw a graph with Graphviz.
I wish to draw a dotted line around a set of vertices, symbolizing that they are a part of a bigger entity.
Say for example, if I have three vertices as eggs, chicken and ham, I should be able to draw a dotted line around all three of them, and label that border as food.
It is possible to group nodes in graphviz by putting them into a cluster. A cluster is a special kind of subgraph which certain layout engines (dot, fdp, ...) support, and if supported, the nodes in a cluster will be drawn together.
From the documentation:
If the name of the subgraph begins with cluster, Graphviz notes the
subgraph as a special cluster subgraph. If supported, the layout
engine will do the layout so that the nodes belonging to the cluster
are drawn together, with the entire drawing of the cluster contained
within a bounding rectangle.
Note that, for good and bad, cluster
subgraphs are not part of the DOT language, but solely a syntactic
convention adhered to by certain of the layout engines.
Important: The ID of the subgraph has to start with cluster.
Example:
graph g{
subgraph cluster_food {
eggs; chicken; ham;
label="Food";
graph[style=dotted];
}
}
I am trying to stack a group of fields vertically (there are 8 specific fields, so I would preferably have 4x4) within Graphviz. I have a subgraph cluster containing 8 fields, which by default are lined up side by side horizontally, making connections extremely messy. I feel it would be much more clear if the subfields were stacked vertically.
A common technique to layout nodes is to use invisible edges.
In the following example, the nodes n1-n8 are layed out vertically within a cluster, but no edges are displayed.
digraph g{
subgraph cluster0 {
edge[style=invis];
n1->n2->n3->n4->n5->n6->n7->n8;
}
// some visible edges from nodes outside of the cluster to nodes within the cluster
a -> b;
a -> {n2;n7;n8};
b -> {n4;n6;n7;};
}
Is there any way to force graphviz to always draw the nodes above edges even if the edge is drawn over (or preferably under) the node?
So far I have tried ordering them and different layer options but not found a way that works.
You'll want to specify outputorder="edgesfirst". This can be found in the documentation.