In Graphviz, can I adjust arrow pointing to rectangle's boundary? - graphviz

Can I adjust arrow pointing to rectangle's boundary? I want to describe a stack pointer. Thanks!
Like this:

You can use a port. For example:
sp->stack:sw;

Most likely you want to use HTML-like-labels
digraph structs {
node [shape=plaintext]
stack [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD PORT="top">top</TD></TR>
<TR><TD PORT="mid">middle</TD></TR>
<TR><TD PORT="bot">bottom</TD></TR>
</TABLE>>];
// edge to stack bottom west
sp -> stack:bot:w
}

Related

How to change the background color of a edge label in GraphViz

I am wanting to change the background color of an edge label in Graphviz. At the moment the only way I can see of doing this is using an HTML table.
Eg,
edge [len=3,fontcolor=red];
DeviceA -- DeviceB [headlabel=<
<table border="0" cellborder="0">
<tr>
<td bgcolor="white">Head Label</td>
</tr>
</table>>
,taillabel="Tail Label"];
What I would like to be able to do is something shorter/cleaner:
edge [len=3,fontcolor=red,bgcolour=white];
DeviceA -- DeviceB [headlabel="Head Label",taillabel="Tail Label"];
Is their an option for this in graphviz?
The reason I am trying to do this is because end labels end up written over edges, which makes the label difficult to read, a background color the same color as the canvas, artificially creates a break in the edge.
Thanks
In GraphViz there is no way to change the Background Colour of an Edge Label. However you can achieve the same by using a HTML Table:
Eg:
edge [len=3,fontcolor=red];
DeviceA -- DeviceB [headlabel=<
<table border="0" cellborder="0">
<tr>
<td bgcolor="white">Head Label</td>
</tr>
</table>>
,taillabel="Tail Label"];

graphviz: Arrow "through" boxes, not "from - to" box

I would like to have arrows go "through" a box, not from box to box. Is there a way to accomplish this (see below) in graphviz?
(Why am I asking: I have some data flow diagrams where multiple outputs from an entity are going through the same entity to be passed to the last entity, and the graphviz output looks like this:
eg., I find this not nice and not recognizable.)
This doesn't exist in graphviz.
How about simply omitting the arrow heads in the edges from A/B to C ?
digraph G {
node[shape=box];
{A;B} -> C [arrowhead=none];
C -> D;
C -> D;
}
Edit: unless, you really want to do that ...
... then you could use HTML-like labels for the node which should have edges crossing through, define ports within the label to attach edges to (in this case, "ww" and "ee"), and have an edge going to the port without an arrow head, as well as an edge leaving from the port with an arrow head, creating the illusion of a single arrow crossing through the port (which isn't visible as such).
digraph G {
node[shape=box];
C[label=<
<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD port="ww"></TD>
<TD></TD>
<TD port="ee"></TD>
</TR>
<TR>
<TD></TD>
<TD CELLPADDING="5">C</TD>
<TD></TD>
</TR>
</TABLE>
>];
A -> C:ww:n [arrowhead=none];
B -> C:ee:n [arrowhead=none];
C:ww:s -> D;
C:ee:s -> D;
}
In order to have nices arrow curves, I also defined compass points for the edges - compass points are n/e/s/w and determine from which side an edge is supposed to enter/leave.

Graphviz - how to constrain edges to only connecting to east or west faces of a node?

I am pretty new to Graphviz and needing to try to constrain connections to only the left or right (or east or west) faces of a node. So far my DOT scripting efforts result in the output shown in attached image.
Any suggestions most appreciated.
Using ports (https://www.graphviz.org/doc/info/attrs.html#k:portPos) will probably solve this problem.
digraph i{
t [shape=plaintext,label=<
<TABLE CELLSPACING="2" CELLPADDING="2" BORDER="1">
<TR><TD PORT="one_l">one left</TD><TD PORT="one_r">one right</TD></TR>
<TR><TD PORT="l2">one left</TD><TD PORT="xyz">one right</TD></TR>
</TABLE>
>
]
x -> t:one_l:w
t:xyz:e -> XX
}
Giving:

How do I style the ports of record based nodes in GraphViz?

I'm feeding this simple input script defining record based nodes to dot in order to create a SVG from it (the SVG part actually doesn't matter):
graph mygraph{
node [shape=record, fontsize=10, fontname=Arial];
rankdir=TB;
ranksep=0.5;
rank=max;
splines=true;
overlap=false;
mindist=0.2;
"d1" [style=solid, label="{\N|{<0> 0|<1> 1}}"];
"d2" [style=solid, label="{\N|{<0> 0|<1> 1|<2> 2|<3> 3}}"];
"d1":0 -- "d2":0[color=blue, penwidth=3, tooltip="d1:0 -- d2:0", URL="#"];
}
This yields a graph where ports 0 of d1 and port 0 of d2 are connected by a blue spline:
Fine.
Now I have the need to colorize the ports. For example: port 1 of d2 shall be green and port 2 of d2 shall be orange. Or something.
How do I achieve this?
Edit 1: the solid frame around the nodes is important. I need it solid for some nodes, dashed for others.
HTML-like labels give you a lot of flexibility in formatting labels. This code:
graph mygraph{
node [shape=record, fontsize=10, fontname=Arial];
rankdir=TB;
ranksep=0.5;
rank=max;
splines=true;
overlap=false;
mindist=0.2;
d1 [shape=none, margin=0, label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td colspan="2">d1</td></tr>
<tr><td port="0">0</td><td>1</td></tr>
</table>>];
d2 [shape=none, margin=0, label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td colspan="4">d2</td></tr>
<tr><td port="0">0</td><td bgcolor="green">1</td><td bgcolor="orange">2</td><td>3</td></tr>
</table>>];
d1:0 -- d2:0[color=blue, penwidth=3, tooltip="d1:0 -- d2:0", URL="#"];
}
Produces this graph:
Note the use of the port attribute to identify the port.

graphViz: how to assign multiple color to nodes

I want to assign multiple color to a node in graphViz. the optimal solution would be a circular node with a pie chart format.
I know one way which is to use HTML tag. the following is a simple example:
graph G{
1--2;
1[shape=none,margin=0,label=<
<table BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<tr>
<td bgcolor="red"></td>
<td bgcolor="blue"></td>
</tr>
</table> >];
2[shape=circle,style=filled,fillcolor=yellow];
3[shape=circle,style=filled,fillcolor=yellow];
}
However, there are some problems:
the node 1 has no label (I want it to have label "1" )
the edge connecting the node 1 to node 2 is not completely attached to node 1. In other words, there is a space between node 1 and the edge connecting it to node 2.
node 1 is rectangular. how can I have a circular node?
If there is no way to overcome these problems, would you please suggest any other graph visualization software?
You can achieve this by
graph G{
1--2;
1[shape=circle,style=wedged,fillcolor="red:blue"];
2[shape=circle,style=filled,fillcolor=yellow];
3[shape=circle,style=filled,fillcolor=yellow];
}
The advantage of the approach is that you can use more than 2 colors in a node.
For your 1st problem, it really depends on your implementation for the two-color nodes. You have multiple solutions described in this post: Two colours in one node with graphviz's dot? With your current code, the easiest way to add a label is to write it inside ot the <td></td> tags, like in the following code:
graph G{
1--2;
1[shape=none,margin=0,label=<
<table BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<tr>
<td bgcolor="red">1</td>
<td bgcolor="blue"></td>
</tr>
</table> >];
2[shape=circle,style=filled,fillcolor=yellow];
3[shape=circle,style=filled,fillcolor=yellow];
}
However, it won't be centered, and I think a gradient node is preferrable.
For your second problem, you need to declare a port on the cells of your array, and use them to anchor your edges when drawing edges:
graph G{
1[shape=none, label=<
<table MARGIN="0" BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<tr>
<td bgcolor="red" port="L">1</td>
<td bgcolor="blue" port="R"></td>
</tr>
</table> >];
2[shape=circle,style=filled,fillcolor=yellow];
3[shape=circle,style=filled,fillcolor=yellow];
1:L--2;
}
For your 3rd problem, according to http://www.graphviz.org/doc/info/shapes.html, you have the possibility to create custom shapes. I don't know any way to create such rounded arrays, so you should look in this direction I think.

Resources