2013-07-12 46 views
1

我想为graphViz中的节点分配多种颜色。最佳的解决方案将是一个饼图格式的圆形节点。graphViz:如何为节点分配多种颜色

我知道一种使用HTML标签的方法。下面是一个简单的例子:

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]; 
} 

然而,也存在一些问题:

  1. 节点1没有标签(我希望它有标有 “1”)

  2. 连接节点1到节点2的边并没有完全连接到节点1.换句话说,节点1和连接到节点2的边之间存在空间。

  3. 节点1是矩形的。我怎么能有一个圆形节点?

如果没有办法克服这些问题,请您提供其他图形可视化软件吗?

回答

0

对于你的第一个问题,它确实取决于你对双色节点的实现。你已经在这个职位描述的多个解决方案:Two colours in one node with graphviz's dot?以您目前的代码,添加标签,最简单的方法就是把它写在下面的代码里面OT了<td></td>标记,如:

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]; 
} 

但是,它赢得了” t居中,我认为一个渐变节点是可取的。

对于你的第二个问题,你需要声明你的阵列的单元格的端口,并用它们来锚定的边画边时:

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; 
} 

为您3问题,根据http://www.graphviz.org/doc/info/shapes.html,你有可能创建自定义形状。我不知道有什么办法来创建这样的圆形数组,所以你应该朝着这个方向看,我认为。

2

您可以通过

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]; 
} 

实现这个方法的好处是,你可以在一个节点使用超过2种颜色。