使用 graphviz(点)为节点创建顶部标签

发布于 2024-10-30 10:54:33 字数 798 浏览 12 评论 0原文

我需要创建一个表示可扩展哈希结构的图。到目前为止,我已经成功地在 graphviz 中创建图形(使用点工具)...但是,我在制作代表每个桶的位数的顶部标签时遇到了麻烦...我想做的是与此类似的事情:

维基百科上的可扩展哈希表

我不能做什么完成的是小 2 和 1 代表位..任何人都可以解释我将如何去做这件事吗?

到目前为止,我的图表如下所示:

digraph G {
nodesep = 0.5;
rankdir = LR;
node [shape=record];

node0[label = "<f0>0 | <f1>1"];
node1[label = "0010 | |", toplabel="1"];

subgraph cluster_0 {
    style=filled;
    color=white;
    node [style=filled,color=white];
    node0;
    label = "i = 1";
}

node0:f0->node1;}

结果

I need to create a graph representing a extendable hashing structure. So far I have had success with creating graphs in graphviz (using the dot tool)... I am however having trouble making top labels representing the number of bits for each bucket... What I want to do is something similar to this:

Extendable hashing table on wikipedia

What I cannot get done are the small 2's and 1's representing bits.. Can anybody explain how I would go around doing this?

My graph so far looks like this:

digraph G {
nodesep = 0.5;
rankdir = LR;
node [shape=record];

node0[label = "<f0>0 | <f1>1"];
node1[label = "0010 | |", toplabel="1"];

subgraph cluster_0 {
    style=filled;
    color=white;
    node [style=filled,color=white];
    node0;
    label = "i = 1";
}

node0:f0->node1;}

result

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年少掌心 2024-11-06 10:54:33

如果您确实必须使用 graphviz 执行此操作,您可以考虑使用 HTML-Like labels

我从维基百科重新创建了提到的示例:

rankdir = LR;
node [shape=none];
splines=false;

n1[label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
 <TD CELLPADDING="2">2</TD>
 <TD BORDER="0"></TD>
</TR>
<TR><TD COLSPAN="2" PORT="port00"> 00 </TD></TR>
<TR><TD COLSPAN="2" PORT="port01"> 01 </TD></TR>
<TR><TD COLSPAN="2" PORT="port10"> 10 </TD></TR>
<TR><TD COLSPAN="2" PORT="port11"> 11 </TD></TR>
</TABLE>>];

a[label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
 <TD CELLPADDING="0" BORDER="0" COLSPAN="2">
  <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="2" FIXEDSIZE="TRUE" WIDTH="1" ALIGN="LEFT"><TR><TD>1</TD></TR></TABLE>
 </TD>
</TR>
<TR>
 <TD PORT="porta"> A </TD>
 <TD>k2</TD>
</TR>
</TABLE>>];

b[label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
 <TD CELLPADDING="2">2</TD>
 <TD BORDER="0" COLSPAN="2"></TD>
</TR>
<TR>
 <TD PORT="portb" COLSPAN="2"> B </TD>
 <TD>k1</TD>
</TR>
</TABLE>>];

c[label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
 <TD CELLPADDING="2">2</TD>
 <TD BORDER="0" COLSPAN="2"></TD>
</TR>
<TR>
 <TD PORT="portc" COLSPAN="2"> C </TD>
 <TD>k3</TD>
</TR>
</TABLE>>];

n1:port00 -> a:porta;
n1:port01 -> a:porta;
n1:port10 -> b:portb;
n1:port11 -> c:portc;

如您所见,代码并不漂亮...但是,结果很接近:

http://graph.gafol.net/evEKgxwgj

graphviz 输出

请注意,有一个变体用于演示目的的顶部标签 - 节点 a 使用嵌套表。

You may consider using HTML-Like labels if you really must do this with graphviz.

I recreated the mentioned example from wikipedia:

rankdir = LR;
node [shape=none];
splines=false;

n1[label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
 <TD CELLPADDING="2">2</TD>
 <TD BORDER="0"></TD>
</TR>
<TR><TD COLSPAN="2" PORT="port00"> 00 </TD></TR>
<TR><TD COLSPAN="2" PORT="port01"> 01 </TD></TR>
<TR><TD COLSPAN="2" PORT="port10"> 10 </TD></TR>
<TR><TD COLSPAN="2" PORT="port11"> 11 </TD></TR>
</TABLE>>];

a[label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
 <TD CELLPADDING="0" BORDER="0" COLSPAN="2">
  <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="2" FIXEDSIZE="TRUE" WIDTH="1" ALIGN="LEFT"><TR><TD>1</TD></TR></TABLE>
 </TD>
</TR>
<TR>
 <TD PORT="porta"> A </TD>
 <TD>k2</TD>
</TR>
</TABLE>>];

b[label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
 <TD CELLPADDING="2">2</TD>
 <TD BORDER="0" COLSPAN="2"></TD>
</TR>
<TR>
 <TD PORT="portb" COLSPAN="2"> B </TD>
 <TD>k1</TD>
</TR>
</TABLE>>];

c[label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
 <TD CELLPADDING="2">2</TD>
 <TD BORDER="0" COLSPAN="2"></TD>
</TR>
<TR>
 <TD PORT="portc" COLSPAN="2"> C </TD>
 <TD>k3</TD>
</TR>
</TABLE>>];

n1:port00 -> a:porta;
n1:port01 -> a:porta;
n1:port10 -> b:portb;
n1:port11 -> c:portc;

As you can see, the code is not pretty... however, the result comes close:

http://graph.gafol.net/evEKgxwgj

graphviz output

Please note that there is a variation for the top label for demonstration purposes - node a uses a nested table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文