Graphviz --- edge label too close to another edge - graphviz

I have the following code, and it results in the image below. As you can see, it's a little crowded around the edges and edge labels, especially around the "^a". What is the best way to create just a tad more space, so that one can clearly see which label belongs to which edge?
digraph finite_state_machine {
pad=0.2;
{
rank=same;
node [shape = point, style = invis]; q_0;
node [shape = doublecircle, style = solid]; q_5;
node [shape = circle];
q_1 [ label = <<i>q<sub>1</sub></i>> ];
q_2 [ label = <<i>q<sub>2</sub></i>> ];
q_3 [ label = <<i>q<sub>3</sub></i>> ];
q_4 [ label = <<i>q<sub>4</sub></i>> ];
q_5 [ label = <<i>q<sub>5</sub></i>> ];
q_0 -> q_1;
q_1 -> q_2 [ label = "." ];
q_1 -> q_2 [ label = <ε>, constraint=false ];
q_2 -> q_1 [ label = <ε>, constraint=false ];
q_2 -> q_3 [ label = <<i>a</i>> ];
q_3 -> q_4 [ label = <<i>^a</i>> ];
q_3 -> q_4 [ label = <ε>, constraint=false ];
q_4 -> q_3 [ label = <ε>, constraint=false ];
q_4 -> q_5 [ label = <<i>b</i>> ];
}
}

There is no attribute in Graphviz to adjust the margin/padding around edge labels. The closest you can probably get to the effect you require is to use \n to introduce blank lines above/below your label to force space.
Obviously, this will not scale to anything automatic.
Alternately, you could try to use the ranksep attribute to force in some additional space.

If xlabel doesn't solve it, then wrapping the label in a table can sometimes be a work-around. For example:
q_1 -> q_2 [ label = <<table cellpadding="10" border="0" cellborder="0">
<tr><td>ε</td></tr>
</table>>,
constraint = false ];
To add more space on one side than on another, you can add an empty cell. The code then quickly becomes (more) unreadable, but you could use a simple sed script to pre-process your dot file.

I know this is an old question, but this approach below might also be helpful, if this is what you are looking for. see the image below.
i added the following to your code:
minlen=2 (to extend gaps between nodes)
tailport=n/s (to change location of the tail of the arrow to north/south)
headport=n/s (to change location of the head to the arrow to north or south)
digraph finite_state_machine {
pad=0.2;
{
rank=same;
node [shape = point, style = invis]; q_0;
node [shape = doublecircle, style = solid]; q_5;
node [shape = circle];
q_1 [ label = <<i>q<sub>1</sub></i>> ];
q_2 [ label = <<i>q<sub>2</sub></i>> ];
q_3 [ label = <<i>q<sub>3</sub></i>> ];
q_4 [ label = <<i>q<sub>4</sub></i>> ];
q_5 [ label = <<i>q<sub>5</sub></i>> ];
q_0 -> q_1;
q_1 -> q_2 [ label = "." ];
q_1 -> q_2 [ label = <ε>, constraint=false, minlen=2, tailport=n, headport=n];
q_2 -> q_1 [ label = <ε>, constraint=false, minlen=2, tailport=s, headport=s];
q_2 -> q_3 [ label = <<i>a</i>> ];
q_3 -> q_4 [ label = <<i>^a</i>> ];
q_3 -> q_4 [ label = <ε>, constraint=false, minlen=2, tailport=n, headport=n];
q_4 -> q_3 [ label = <ε>, constraint=false, minlen=2, tailport=s, headport=s];
q_4 -> q_5 [ label = <<i>b</i>> ];
}
}

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;
}
}

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 adjust outer labels for nodes

I want to plot graph with some outer labels.
I found that there some helpful attributes - xlabel,taillabel,headlabel but the result still looks weird.
MCVE
digraph {
forcelabels=true;
node [shape=point,style=filled;label="",height=0.2];
y3[color=black;xlabel=<"y3 (2)">];x3[color=gray;xlabel=<"x3 [0.25]">];
y2[color=black;xlabel=<"y2 (3)">];x2[color=gray;xlabel=<"x2 [0.3]">];
y1[color=black;xlabel=<"y1 (2)">];x1[color=gray;xlabel=<"x1 [0.1]">];
y5[color=black;xlabel=<"y5 (4)">];x5[color=gray;xlabel=<"x5 [0.15]">];
x4[color=gray;xlabel=<"x4 [0.2]">];
y3->y2[dir=none;taillabel = 0.75];
y2->y1[dir=none;taillabel = 0.45];
y1->y5[dir=none;taillabel = 0.35];
y3->x3[dir=none];
y2->x2[dir=none];
y1->x1[dir=none];
y5->x5[dir=none];
y5->x4[dir=none];
}
it looks like
As you can see, conformity between labels and nodes not always obvious.
So, the Q is - is there any way to change location of labels ?
This may not be the answer to your question as it still does not look great and takes a lot of manual adjustment, but I post it anyway: I spent quite some time fiddling around, and there may be some ideas that could be helpful for your actual context:
digraph
{
forcelabels = TRUE;
splines = FALSE;
// nodes
node[ shape = point, style = filled, color = gray, label = "", height = 0.2 ];
x3[ xlabel = <"x3 [0.25]"> ];
x2[ xlabel = <"x2 [0.3]"> ];
x1[ xlabel = <"x1 [0.1]"> ];
x5[ xlabel = <"x5 [0.15]"> ];
x4;
node[ color = black ];
y3, y2, y1, y5;
node[ shape = plaintext, fillcolor = white ];
y_3[ label = "y3 (2)" ];
y_2[ label = "y2 (3)" ];
y_1[ label = "y1 (2)" ];
y_5[ label = "y5 (4)" ];
// edges
edge[ dir = none ];
y3:se -> y2[ label = " 0.75" ];
y2:se -> y1[ label = " 0.45" ];
y1:se -> y5[ label = " 0.35" ];
y3 -> x3;
y2 -> x2;
y1 -> x1;
y5 -> x5;
y5 -> x4[ headlabel = <"x4 [0.2]"> ];
edge[ style = invis ];
{ rank = same; y3 -> y_3 }
{ rank = same; y2 -> y_2 }
{ rank = same; y1 -> y_1 }
{ rank = same; y5 -> y_5 }
}
yields

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]

how to control edge placements and labels in dot (graphviz)

I have trouble controlling the layout of graphviz.
Trying to produce a simple automaton.
The source:
digraph mygraph {
rankdir=LR;
size="13,13"
node [shape = circle];
init -> Ready [ label = "" ];
Ready -> P1 [ label = "t<T\n----TexT----" ];
P1 -> Ready [ label = "t>T" ];
P1 -> B1 [ label = "t<T" ];
B1 -> P1 [ label = "----TexT----" ];
B1 -> U1 [ label = "----TexT----" ];
Ready -> P2 [ label = "t<T\n----TexT----" ];
P2 -> Ready [ label = "t>T" ];
P2 -> B2 [ label = "t<T" ];
B2 -> P2 [ label = "----TexT----" ];
B2 -> U2 [ label = "----TexT----" ];
U1 -> Ready [ label = "----TexT----", constraint=false];
U2 -> Ready [ label = "----TexT----", constraint=false];
P1 -> P2 [ label = "t<T\n----TexT----", constraint=false];
P2 -> P1 [ label = "t<T\n----TexT----", constraint=false];
}
trouble is, the labels are intertwined. I probably need:
1. larger spacing
2. move some of the edges up
3. control label placings
how do I do it?
Since the conflict occurs on vertical edges going in opposite directions between nodes placed by dot on the same rank (P1 & P2) you could use vertical rank direction (drop the "rankdir=LR" line) so that the labels for theses specific edges are placed one below the other rather than side by side.
Granted, it's not a universal cure for this sort of issues but should help here without unnecessarily bloating the graph (which increasing node separation via "nodesep" would do).

Resources