且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Graphviz:如何将相同的样式分配给一组边?

更新时间:2023-11-26 13:53:16

是否可能有某种方法要将边添加到4个不同的组,然后对组进行风格化,要按组 (而不是单独)样式边缘(或节点),请使用 子图

To style edges (or nodes) by group rather than individually, use subgraph.

如下:

digraph G {

node [style=filled,color="#5D8AA8", fillcolor="#5D8AA8"];

subgraph c1 {
    edge [color="#004225", arrowsize="0.6", penwidth="1"];
    "node 1" -> "node 3";
    "node 5" -> "node 7";
    "node 1" -> "node 2"; 
    label = "";
}

subgraph c2 {
    edge [color="#FBEC5D", arrowsize="1.2", penwidth="3"];
    "node 2" -> "node 4";
    "node 4" -> "node 6";
    "node 3" -> "node 5";
    "node 6" -> "node 8"; 
    label = "";

}

begin -> "node 1";
start -> "node 2";
"node 1" -> "node 4"
"node 2" -> "node 6";

start [shape=diamond];}

上面的代码在文件w / a.dot扩展;然后在graphviz中渲染,您将在外观上看到三种不同类型的边。

So if you put the code above in a file w/ a ".dot" extension; then render it in graphviz,, you'll see three different types of edges, appearance-wise.

一种类型是默认(颜色=黑色,厚度= 1等) - 即,这些边缘未分配给子图。

One type is the just the default (color=black, thickness=1, etc.)--i.e., these edges not assigned to a subgraph.

其他两种类型的边绿色组和厚的亮黄色组)基于赋予两个子图簇之一的样式。

The other two types of edges(a thin, dark-green group, and a thick, bright-yellow group) are styled based on assignment to one of two subgraph clusters.

子图用于可视地突出显示节点集群(即,区分特定的连续组节点与图中的其余节点);然而,没有要求(从我的示例中可以看到),您选择通过赋值给给定子图样式的边缘属于连续的组节点 - 您可以指定任何希望分配的边一个给定的子图。)

Subgraph is often used to visually highlight a node cluster (i.e., to distinguish a particular contiguous 'group' of nodes from the rest of the nodes in the graph); however, there is no requirement (as you can see from my example) that the edges you chose to style by assignment to a given subgraph, belong to a contiguous 'group' of nodes--you can designate any edges you wish for assignment to a given sub-graph.)

对我来说,按组样式化节点类似于定义一个类并将它分配给HTML标记中的一个div集合的HTML实践

to me, styling nodes by group is analogous to the HTML practice of defining a class and assigning it to a collection of divs in HTML markup