digraph G
{
rankdir=LR;
Array1 [ shape = record, label = "{ <a1>A(1) | <a2>A(2) | <a3>A(...) | <an>A(n)}"] ;
Array2 [ shape = record, label = "{ <b1>B(1) | <b2>B(2) | <b3>B(...) | <bn1>B(n+1)}"] ;
Array1:a1 -> Array2:b1 [style=solid];
Array1:an -> Array2:bn1 [style=solid];
{rank=same; Array1; Array2;}
}
I'm trying to get graphviz plot two array from left to right but Array1 on the top and Array2 at the bottom.
Output with rank=same
As you can see in the picture there are no arrows drawn but the layout is like it should be. I'm also getting some errors from dot, but I can't find anything useful with that information:
dot -Tpng algoA.dot -o algoA.png :(
Warning: flat edge between adjacent nodes one of which has a record shape - replace records with HTML-like labels
Edge Array2 -> Array1
Error: lost Array1 Array2 edge
Error: lost Array1 Array2 edge
digraph G
{
rankdir=LR;
Array1 [ shape = record, label = "{ <a1>A(1) | <a2>A(2) | <a3>A(...) | <an>A(n)}"] ;
Array2 [ shape = record, label = "{ <b1>B(1) | <b2>B(2) | <b3>B(...) | <bn1>B(n+1)}"] ;
Array1:a1 -> Array2:b1 [style=solid];
Array1:an -> Array2:bn1 [style=solid];
//{rank=same; Array1; Array2;}
}
Output with rank=same removed
Without rank=same in the code I get the arrows like I wanted, but not like I wanted it with Array1 on top and Array2 on the bottom. The error messages are gone. What am I doing wrong? I tried several ways and all of them didn't work for me, I'm always getting a wrong layout or I have to add several other nodes to get it drawn, with those invisible the arrows for my arrays also don't get drawn.
The key is in the error message: replace records with HTML-like labels. Details can be found here.
Taking your code and what I understand you want to achieve, this can be done with creating your arrays as two HTML-like labels. Comments in the code.
digraph so
{
# plaintext is being used to create HTML-like labels
node [shape=plaintext]
# no border for the table, a single border for each cell and
# no distance between individual cells looks like record shape
# PORTs being defined as addresses of individual cells
# that edges can be directed to
array1 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR>
<TD PORT="a1">A(1)</TD>
<TD PORT="a2">A(2)</TD>
<TD PORT="ax">A(...)</TD>
<TD PORT="an">A(n)</TD>
</TR> </TABLE>>];
array2 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR>
<TD PORT="b1">B(1)</TD>
<TD PORT="b2">B(2)</TD>
<TD PORT="bx">B(...)</TD>
<TD PORT="bn">B(n+1)</TD>
</TR> </TABLE>>];
array1:a1 -> array2:b1;
array1:an -> array2:bn;
}
This produces what (I think) you want:
Related
Is it possible to have graphviz/dot render a node as a circle that is split in the middle horizontally, with a top and bottom text content? Something like a record, but the final shape should be a circle. Currently I'm using Mrecord, but that's only a rounded rectangle, not a circle shape.
I searched for ways to increase the border radius of Mrecord (to make it a quasi-circle) but that did not work. I also tried Mcircle, which is not what I was looking for.
Not directly, but you can create a circle-shaped node, divided in half with the wedged attribute and in the HTML-like label write a HTML <TABLE> without borders which will place text on top of the node.
Script:
digraph {
nodepie [shape = "circle"
style = "wedged"
fillcolor="white;0.5:white"
label=<<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
<TR>
<TD>one</TD>
</TR>
<TR>
<TD>two</TD>
</TR>
</TABLE>>];
}
Result:
Not directly, but you can create an image (svg, png, ...) that looks exactly like you want, using any drawing program, & then include that image in your Graphviz graph.
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"];
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.
I have a very simple graph:
digraph {
node [shape=rect];
rankdir=LR;
A -> B
}
It outputs as I expect:
However, I need to place unique numbers in each corner of both A and B. I am currently only aware of xlabel, but from what I gather can only be used once and cannot be specified in a particular region. So how can I accomplish writing numbers in each corner?
Newest versions of Graphviz support HTML styling of nodes, including tables ("newer than mid-November 2003", that is). So you can make a 3x3 table like this:
Source:
digraph {
node [shape=rect];
rankdir=LR;
A [shape=none label=<
<TABLE BORDER="0" CELLBORDER="0">
<TR><TD>1</TD><TD></TD><TD>2</TD></TR>
<TR><TD COLSPAN="3" BORDER="1">A</TD></TR>
<TR><TD>3</TD><TD></TD><TD>4</TD></TR>
</TABLE>
>];
A -> B
}
Tested with http://sandbox.kidstrythisathome.com/erdos/; it also works with my local installed version (2.38.0).
See Graphviz: Node Shapes for the full set of supported HTML, and examples.
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.