我正在使用 Graphviz 的
neato
渲染一个大图。
以下所有事情都发生在这个环境中:
digraph G {
graph [scale="1,0.7"]
在其中的某个地方,我想显示一个节点,它只是一个彩色圆圈,旁边有一个文本。
我可以并排放置两个节点(一个用于圆圈,一个用于标签),但不知何故无法左对齐文本:
n1 [pos="1,-8!" style=filled shape=circle width=0.25 color=green1]
n2 [pos="1,-8!" label="the node label"]
显然,标签(
n2
)像这样以节点(n1
)为中心。尽管我打算将最终图表中的标签稍微向右移动,但出于演示目的,我们仍保持这样:
最终,这就是我想要实现的目标:
但是对于这个输出,我必须手动调整标签的位置,这样标签节点的中心点就位于文本左边缘紧邻圆圈的正确位置 - 即取决于标签的长度,因此相当笨拙。
我尝试过使用“左对齐换行符”:
n1 [pos="1,-8!" style=filled shape=circle width=0.25 color=green1]
n2 [pos="1,-8!" label="the node label\l"]
标签仍然居中。
labeljust
属性:
n1 [pos="1,-8!" style=filled shape=circle width=0.25 color=green1]
n2 [pos="1,-8!" label="the node label" labeljust=l]
标签仍然居中。
然后,我尝试使用类似 HTML 的标签和
align
属性来对齐文本,如前面提到的,例如这里。由于 Graphviz 无法识别 Creole 的 <plain>
标签,因此我使用 <font>
作为看似下一个最佳替代方案,使用 just 一个包装标签来放置 align
属性,无需任何进一步的格式化:
n1 [pos="1,-8!" style=filled shape=circle width=0.25 color=green1]
n2 [pos="1,-8!" label=<<font align="left">the node label</font>>]
为此,Graphviz 会输出有关
<font>
标签上的非法属性的警告,并且文本仍居中。
如何左对齐文本,以便更容易放置文本节点?或者是否有另一种方法可以将文本放在节点的右侧?
没有简单的方法可以满足您的要求。 xlabel 应该按照你的要求执行,但你无法指定标签位置(似乎默认为“靠近西北角”)。
对齐和调整工作不起作用,因为它们适用于节点边界内部,而不是外部
以下是三种可能的解决方案:
digraph L{
n1 [pos="1,5!" style=filled label="" shape=circle width=0.25 color=green1]
n2 [pos="2.0,5!" shape=plaintext width="1.2" label="the node label1" labeljust=l]
b [pos="1,1!" style=filled shape=circle fixedsize=true height=.25 width=0.25 color=pink1
label=" the node label4"]
d [pos="1,3!" style=filled shape=circle fixedsize=true height=".25" width=".25" color=lightblue
label=<
<table border="0" cellspacing="0" cellborder="0">
<TR><TD width="138"></TD><TD>the node label6</TD></TR></table>> ]
}