Is it possible to have nested node shapes on Graphviz? - graphviz

Is it possible to have nested shapes on Graphviz?
I would like to have a diamond inside a square, like the image bellow:

I got a solution:
subgraph cluster_1 {
margin = 1;
label = "";
associative_entity [shape = diamond, height = 1];
}

The Msquare shape might be close enough if your own solution doesn't work well for what you want.

Related

How can I align two (disconnected) nodes in GraphViz?

Suppose I have the GraphViz graph:
digraph G {
a->b->d;
c->d;
}
How can I make a and c be aligned vertically, i.e. appear at the same height?
You can align them using grouping and a group-scope attribute:
digraph G {
{rank = same; a; c;}
a->b->d;
c->d;
}
Note that if your rankdir value is different, this alignment will not be vertical: e.g. if rankdir=LR then a and c will be horizontally aligned to the same position - with the arrows pointing rightwards.

Graphviz drawing two arrows intead of one

I have a strange result trying to make a simple graph using graphviz. Two arrows are drawn between 3 and 4 instead of one. I can't figure out why, if it is a bug or if I've done something wrong. Here is a minimal example, anything I remove makes the problem dissapear:
digraph dia {
newrank=true;
1 -> 2;
subgraph cluster_1 {
label = "1";
3 -> 5;
3 -> 6;
5 -> 6
}
subgraph cluster_2 {
label = "2";
4;
}
3 -> 4;
{rank="same"; 2; 5; 6;}
{rank="same"; 3; 4}
}
It produces the following output:
My actual graph is larger than that, and I need newrank property.
I think I have the lastest version of graphviz...
dot - graphviz version 2.40.1 (20161225.0304)
Thanks for any help !
I also noticed some strange things going on in graphviz when clusters are being used (especially in combination with rank=same. So probably a bug, yes.
In your situation simply adding a port to one of the problematic nodes fixes the problem:
3:e -> 4;

How to display / determine the index of a vertex in ARSCNFaceGeometry?

I want to get the index of a specific vertex in the mesh of the ARSCNFaceGeometry.
I tried to add a SCNText to the vertex that displays the vertex index:
// Create face node
let faceNode = SCNNode(geometry: geometry) // geometry is the ARSCNFaceGeometry
// Get vertices of face node
let vertices = ...
// For each vertex
vertices.enumerated().forEach({ (index, vertex) in
// Create text geometry
let textGeometry = SCNText(string: text, extrusionDepth: 1)
textGeometry.firstMaterial?.diffuse.contents = UIColor.black
// Create text node
let textNode = SCNNode(geometry: textGeometry)
textNode.scale = SCNVector3(0.0002, 0.0002, 0.0002)
textNode.position = SCNVector3(vertex.x, vertex.y, vertex.z)
// Add text node to face mask node
faceNode.addChildNode(textNode)
})
But the result in Xcode Scene Editor is that some text nodes are positioned correctly, others are scattered all over the place:
Why are the text nodes positioned like that?
Is there another way to get the vertex indices?
Update:
I tried to add SCNBox to every vertex:
let box = SCNBox(width: 0.005, height: 0.005, length: 0.005, chamferRadius: 0)
box.firstMaterial?.multiply.contents = UIColor.blue
let boxNode = SCNNode(geometry: box)
boxNode = vertex
faceNode.addChildNode(boxNode)
The result shows that even the box positions are wrong. So how can I use the vertex to position each box centered in the mesh point?
The way I retrieved the vertices from the face mesh was wrong. I use this answer now to extract the vertices and it works.

Is it possible to place a label midway of an edge in graphviz?

Is is possible to make a graph like this:
Where the label is in the path of an edge between two nodes.
The closest you get, as far as I know, is rather than trying to fiddle around with edge lables, using text only nodes:
digraph so
{
// standard nodes
node[ shape = box ];
A[ label = "Animal" ];
B[ label = "Elephant" ];
// fake label nodes
node[ shape = none ];
a[ label = " large" ];
// get them connected
edge[ arrowhead = none ];
A -> a -> B;
}
This gives you
This is not optimal as it gives you layout problems - the distance between your "real" nodes is probably larger than you want, and you would have to introduce empty nodes for edges without labels. But at least it comes close to the picture you have posted.

Graphviz node ordering

I want to have a diagram which has the layout as follwing :
But when i wrote the codes like this:
digraph g {
a->b->c;
{rank=same;b,d,e,f,g,h}
d->g [weight = 1];
d->f [weight = 10];
}
And comes like this:
The dot guide even recommends this:
Edge weights also play a role when nodes are constrained to the same rank.
Edges with non-zero weight between these nodes are aimed across the rank
in the samedirection (left-to-right, or top-to-bottom in a rotated drawing) as far
as possible. This fact may be exploited to adjust node ordering by placing
invisible edges (style="invis") where needed.
I wander why it not work?
add the following line in your graph:
f->g[style=invis];
digraph g {
a->b->c;
{rank=same;b,d,e,f,g,h}
d->g [weight = 0];
d->f [weight = 1];
}
Works as you wish.
But, I also don't know why
d->g [weight = 1];
d->f [weight = 2];
doesn't work.
Maybe it depends on layout type, neato or dot or etc. See https://graphviz.gitlab.io/docs/attrs/weight/
Also
digraph {
a -> b -> c;
d->g
d->f
{rank = same; b;d;e;f;g;h;}
}
Works. Source

Resources