如何为一组边缘分配相同的样式? [英] How to assign the same style to a group of edges?

查看:61
本文介绍了如何为一组边缘分配相同的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图表,希望graphviz可以为我进行布局和可视化。该图具有122条边和123个节点。边缘有4种不同的边缘,我希望它们在视觉上可以区分。但是,我还没有决定最好的方法,我想稍微玩一下表盘。

I've got a graph that I want graphviz to layout and visualize for me. The graph has 122 edges and 123 nodes. The edges are of 4 different kinds and I want them to be visually distinguishable. However I've not yet decided what would be the best way of doing that, I'd like to play around with the dials a bit.

不幸的是,我没有看到边缘的 class或 stylesheet属性。我只能为每个边缘(很多重复)分别设置视觉属性。也许我错过了什么?毕竟是否有某种方法可以将边添加到4个不同的组中,然后对组进行样式设置,而不是分别对每个边进行样式设置?

Unfortunately I do not see anything like a "class" or "stylesheet" attribute for edges. I can only set visual attributes individually for every edge (lots of repetition). Perhaps I've missed something? Is there maybe some way after all to add edges to 4 different groups and then style the groups, not each edge individually?

推荐答案

要按组 (而不是单独地) 设置边缘(或节点)的样式,请使用 子图

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

因此,如果您将上面的代码在带有 .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

这篇关于如何为一组边缘分配相同的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆