head and tail labels overlap the arrow - graphviz

In the following code, the head and tail labels overlap the arrow, which I do not want. What do I have to do?
digraph G {
node [shape = "record"];
edge [
arrowhead = "normal"
headlabel = "0..*"
taillabel = "longlabel"
];
N1 [ label="N1"];
N2 [label = "N2" ];
N1->N2;
}

You can't really control the position of head and tail-labels as it is possible for the edge label (using labelangle, labeldistance, etc.)
However, as a hack, you could add whitespace to the head/tail-label and that way force the center of the label to be on the left or right of the label text:
headlabel = " 0..*"
taillabel = "longlabel "

Related

Graphviz: route line from the left side of the node

I am trying to create flow chart as shown in the image #2 (with the red lines) but I am not able to position the lines from the left side of the onset node to the left side of the sampling node. If :w or :s is added to the node, line is broken and goes from the inside of the node. Is it possible to route the lines like that and put the text to the side so it doesn't collide with the line?
digraph G {
graph [splines=ortho];//, nodesep=0.8]
node [shape=record]
sampling [
label = "Sampling";
shape = rect;
];
onset [
label = "Onset\ndetection";
shape = diamond;
];
collect [
label = "Collect 1024 samples";
shape = rect;
];
xcorr [
label = "Compute\ncross correlation";
shape = rect;
];
display [
label = "Display data";
shape = rect;
];
sampling->onset;
onset->sampling [label = "No"];
onset->collect [label = "Yes"];
collect->xcorr;
xcorr->display;
xcorr->sampling [ label = "Return"; ];
{
rank = same;
collect; xcorr;
}
}

How can I make dot (graphviz) layout unconnected nodes vertically instead of horizontally?

I use pyreverse to create class diagrams from python code and this results in graphs like this:
as can be seen, some classes are not related. I would like to have the subgraphs laid out below each other so that I can include the image in a document.
Is there a simple way to modify a dot file so that disconnected parts of a graph are placed below each other?
Connect the disconnected parts with invisible edges:
digraph so
{
node[ shape = box ];
A[ label = "Message" ];
B[ label = "MetaMessage" ];
C[ label = "TrainingMessage" ];
D[ label = "MessageBundle" ];
A -> { B C };
{ B C } -> D[ style = invis ];
}
yields

self loop edges too short and ugly in graphviz

I drawed a picture using graphviz. Please see FSM.
I think It is ugly because self loop edges are so short.
The attribute "minlen" of edges doesn't work for me.
And I tried several ports of the node, but it all shows a mess except my current implementation. Do you have a clever idea for me ?
Code is here:
digraph finite_state_machine {
rankdir=LR;
size="8,2"
fontname="Verdana"
node [shape = doublecircle]; Idle;
node [shape = circle,nodesep = "2.0"];
Working:s -> Working:s [ label = "response[j]?" ,minlen = 50000];
Idle -> Working [ label = "boot" ];
Working:n -> Working:n [ label = "sendtx[i]!",minlen = 50000 ];
Working:e -> Working:e [ label = "qry!" ,minlen = 50000];
}
Adding nodesep=1; makes loops larger, although not nicer. So this would help:
digraph finite_state_machine {
rankdir=LR;
size="8,2"
fontname="Verdana"
node [shape = doublecircle]; Idle;
node [shape = circle,nodesep = "2.0"];
Working:s -> Working:s [ label = "response[j]?" ,minlen = 50000];
Idle -> Working [ label = "boot" ];
Working:n -> Working:n [ label = "sendtx[i]!" ];
Working:e -> Working:e [ label = "qry!"];
nodesep=1;
}
Will produce something like:
Dot Output

How to set bend direction for edges with splines="curved" in GraphViz? (using neato)

I am creating a graph with manually positioned nodes and use the splines="curved" type of edges between them.
digraph graphname {
splines="curved";
node[shape = box, margin="0.03,0.03", fontsize=11, height=0.1, width=0.1, fixedsize=false];
"LeftFoot\nRightHand" [pos="-150,-150!"];
"RightFoot\nRightHand" [pos="-90,-150!"];
"LeftFoot\nRightFoot" [pos="0,-150!"];
...
edge[style = solid,fontsize=11];
"LeftFoot\nRightFoot":n -> "RightFoot\nRightHand":n [label = "3", penwidth = 1, color = "red"];
"LeftFoot\nRightFoot":s -> "LeftFoot\nRightHand":s [label = "7", penwidth = 1, color = "red"];
...
}
The problem is that one of the edges is bent to the wrong side, so it passes through a node:
Is there an easy way to fix this, like e.g. "bend left" or "bend right" in TikZ?
I tried to use the pos attribute on the edge to set a spline control point to change the bend, however this does not appear to change the edge at all.
In Grapvhiz 2.38 this seems to be fixed. I've scaled the pos slightly but left the rest of the code alone:
Dot source:
digraph graphname {
splines="curved";
node[shape = box, margin="0.03,0.03", fontsize=11, height=0.1, width=0.1, fixedsize=false];
"LeftFoot\nRightHand" [pos="-2,-2!"];
"RightFoot\nRightHand" [pos="-1.2,-2!"];
"LeftFoot\nRightFoot" [pos="0,-2!"];
edge[style = solid,fontsize=11];
"LeftFoot\nRightFoot":n -> "RightFoot\nRightHand":n [label = "3", penwidth = 1, color = "red"];
"LeftFoot\nRightFoot":s -> "LeftFoot\nRightHand":s [label = "7", penwidth = 1, color = "red"];
}
Command:
dot -Kneato -Tpng input.gv > output.png
Output:

Graphviz forcing nodes to stack vertically despite rankdir=LR

I am new to Graphviz and trying to layout some nodes from left to right with something like the following:
digraph g {
graph [ rankdir = "LR" ];
node [ fontsize = "16", fontname="Arial" ];
nodesep = 1.0;
ranksep = 4.0;
"node0" [
label = "<f0>OBJECT0| <f1> Id | <f2> Name"
shape = "record" ];
"node1" [
label = "<f0>OBJECT1| <f1> Id | <f2> Name"
shape = "record" ];
"node2" [
label = "<f0>OBJECT2| <f1> Id | <f2> Name"
shape = "record" ];
"node4" [
label = "<f0>OBJECT3| <f1> Id | <f2> Name"
shape = "record" ];
** I also have some connectors in here across the nodes **
}
This works ok for very basic nodes, but if I have say 100 rows within a node (representing a database table and fields) the nodes are stacked vertically and nothing I do seems to influence the damn things to revert back to a horizontal layout.
Any suggestions on how I might force the issue would be most appreciated - this one has me completely stuck!
Cheers
CH
Resolved - needed to add the line node0 -> node1 -> node2 -> node3 -> node4 [style=invis]

Resources