【问题标题】:Object's attributes in graphvizgraphviz中对象的属性
【发布时间】:2013-10-14 03:51:57
【问题描述】:

我试图在节点标签下显示状态的属性。

目前是这样的:

 ________________________               ________________________
|                        |    pause()  |                        |
|                        |------------>|                        |
|                        |  continue() |                        |
|________________________|<------------|________________________|

我有代码:

        Graph = new Graph<State>();
        var a = new State()
        {
            Status = "Ready",
            AllowedPurchaserOperations = "operation1, operation2",
            AllowedSupplierOperations = "operarion1, operation 3"
        };
        var b = new State()
        {
            Status = "Paused",
            AllowedPurchaserOperations = "operation1, operation2",
            AllowedSupplierOperations = "operarion1, operation 3"
        };

        Graph.AddVertex(a);
        Graph.AddVertex(b);

        Graph.AddEdge(new Edge<State>(a, b) {Label = "pause()"});
        Graph.AddEdge(new Edge<State>(b, a) {Label = "continue()"});

我想或多或少地这样展示它:

 ________________________               ________________________
|         Ready          |    pause()  |         Paused         |
| operation1, operation2 |------------>| operation1, operation2 |
| operation1, operation3 |  continue() | operation1, operation3 |
|________________________|<------------|________________________|

由于很难找到使用 graphviz 的实现示例,我不知道如何在节点中添加值。有人知道在转换之前我应该​​做什么吗?

【问题讨论】:

  • 你在使用 QuickGraph 吗?
  • @marapet 我正在使用 graphviz4net
  • 不幸的是,这个问题没有用 graphviz4net 标记,但迟到总比没有好。一篇关于在 WPF 中自定义图形元素的短文:graphviz4net.codeplex.com/…
  • @Steves 我无法添加标签,并且堆栈溢出时不存在 graphviz4net。我读过那个链接(我之前也读过)。谢谢。

标签: c# graphviz dot


【解决方案1】:

我对graphviz4net一无所知,但这很容易通过使用Graphviz的DOT language和clusters来实现:

该图的DOT文件如下:

digraph g{

    // Set the graph direction from left to right
    // otherwise the boxes will be above eachother
    // with the arrows pointing up and down
    rankdir="LR"

    // hide the border of the nodes in the cluster supgraph
    node [shape = "none"]

    // make the lines dashed, remove if you want solid lines
    edge [style = "dashed"]

    subgraph cluster_ready {
        label = "Ready"

        ready_op_1_2 [label="operation1, operation2"]
        ready_op_1_3 [label="operation1, operation3"]
    }

    subgraph cluster_paused {
        label = "Paused"

        paused_op_1_2 [label="operation1, operation2"]
        paused_op_1_3 [label="operation1, operation3"]
    }

    ready_op_1_2 -> paused_op_1_2 [label="pause()"]
    paused_op_1_3 -> ready_op_1_3 [label="continue()"]
}

您可以通过更改各种元素的字体、颜色和样式来相当轻松地调整外观。为了解决这个问题,我建议使用GraphViz Workspace 来快速了解哪个属性(以及它的设置)的作用。 attribute manual 可能有点让人不知所措,但它有你需要的一切。

【讨论】:

  • 您的回答澄清了很多,谢谢。你知道如何在 C# 中设置节点 [shape = "none"] 吗?我正在使用 graphviz4net。
  • 不客气,很高兴为您提供帮助。不幸的是,我没有使用 graphviz4net 的经验。我看过这个项目,但对我来说,这似乎是一种过于复杂的包装 Graphviz 的方式。由于该项目的文档非常很少,我也不会指向源代码以外的地方:-(如果您知道如何更改节点的颜色,则可以将其设置为与背景相同的颜色? 除此之外,我认为将 DOT 语法提供给 AntlrParserAdapter class 可能是您最好的选择。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-10
  • 1970-01-01
  • 2015-07-23
  • 2017-07-25
  • 2018-12-31
  • 1970-01-01
  • 2015-11-15
相关资源
最近更新 更多