I am trying to generate something similar to this:
https://upload.wikimedia.org/wikipedia/commons/6/65/B-tree.svg
From a btree in memory... is there any way to generate a graph like that on Graphviz, so that I can generate the *.dot file?
Thanks.
I am trying to generate something similar to this:
https://upload.wikimedia.org/wikipedia/commons/6/65/B-tree.svg
From a btree in memory... is there any way to generate a graph like that on Graphviz, so that I can generate the *.dot file?
Thanks.
Go to http://ysangkok.github.io/js-clrs-btree/btree.html and press "init simple". In the textarea you see Graphviz code for the tree shown above. The algorithm is simple, as you can see.
Producing the same effect in Graphviz is a challenge, but not impossible.
digraph "tree test" {
splines=false
node [shape=rect style="rounded,filled" fillcolor=lightblue]
{rank=same
a [label=<
<table border="0" cellspacing="0" cellborder="1">
<tr>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">11</td>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">12</td>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">13</td>
<td border="0" ></td>
<td style="invis" bgcolor="lightcyan">xx</td>
<td border="0" ></td>
</tr>
<tr>
<td port="p1" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p2" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p3" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p4" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p5" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="invis"></td>
</tr>
</table>>]
}
{rank=same
b [label=<
<table border="0" cellspacing="0" cellborder="1">
<tr>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">21</td>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">22</td>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">23</td>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">24</td>
<td border="0" ></td>
</tr>
<tr>
<td port="p1" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p2" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p3" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p4" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p5" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
</tr>
</table>>]
c [label=<
<table border="0" cellspacing="0" cellborder="1">
<tr>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">31</td>
<td border="0" ></td>
<td style="rounded" bgcolor="lightcyan">32</td>
<td border="0" ></td>
<td style="invis" bgcolor="lightcyan">33</td>
<td border="0" ></td>
<td style="invis" bgcolor="lightcyan">34</td>
<td border="0" ></td>
</tr>
<tr>
<td port="p1" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p2" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p3" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="rounded"></td>
<td border="0"></td>
<td port="p4" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="invis"></td>
<td border="0"></td>
<td port="p5" border="0" width="5" height="5" fixedsize="true" bgcolor="red" style="invis"></td>
</tr>
</table>>]
}
a:p1:c -> b
a:p2:c -> c
}
If you want to produce the same effect as the quoted picture, it is impossible. You can check the source of the link and indicate that it was produced by Inkscape.
Yes
You can use rankdir and such to set the direction it lays stuff out in.
If you have a directed graph (digraph
) that forms a tree (no cycles if direction is ignored) it'll pick up on this for you, you can change the dir of individual nodes using A -> B [dir="backwards"]
.
That creates a link from A to B but displayed as fro B to A
If you just have "forward links" (not sure on name of graph) where there are no cycles if direction is considered but there can be if direction is ignored (A->B->C and A->D->C is an example of this) it'll still put it in layers for you.
Once again: yes.
© 2022 - 2024 — McMap. All rights reserved.