Graphviz(4net)到DOT的转换 [英] Graphviz (4net) to DOT conversion

查看:122
本文介绍了Graphviz(4net)到DOT的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码(使用graphviz4net从C#转换):

I have the following code (converted from C# using graphviz4net):

digraph g {
graph [rankdir="LR" ,compound="true" ];
    subgraph cluster0 {
        graph [label="Ready" ];
        1 [  ];
    };
    subgraph cluster2 {
        graph [label="Paused" ];
        3 [  ];
    };
    1 -> 3 [ ltail="cluster0" ,lhead="cluster2" ,comment="4"  ];
    3 -> 1 [ ltail="cluster2" ,lhead="cluster0" ,comment="5"  ];
}

我正在检查 http://www.graphviz-dev.appspot上的转换图像. com/.

图片是这样的:

我正在用C#编程.我有两个问题:

I'm programming in C#. I have 2 questions:

1-如何在C#中修复箭头?

1 - How to fix the arrows in C#?

2-如何使椭圆在C#中消失?

2 - How to make the ellipses disapear in C#?

*我知道我可以使用节点[shape = none],但是我不知道如何在C#中进行设置.

*I know I can use node [shape = none], but I don't know how to set it in C#.

更新:

现在我有以下代码:

digraph g {
graph [rankdir="LR" ,compound="true" ];
    subgraph cluster0 {
        graph [label="Ready\n\nPurchaser:\noperation1,operation2,Supplier:\noperation1,operation3," ];
        1 [ shape="none" ,fontcolor="white"  ];
    };
    subgraph cluster2 {
        graph [label="Paused\n\nPurchaser:\noperation1,operation3,Supplier:\noperation2,operation3," ];
        3 [ shape="none" ,fontcolor="white"  ];
    };
    subgraph cluster4 {
        graph [label="Completed\n\nPurchaser:\noperation4,Supplier:\noperation4," ];
        5 [ shape="none" ,fontcolor="white"  ];
    };
    1 -> 3 [ ltail="cluster0" ,lhead="cluster2" ,comment="6"  ];
    1 -> 5 [ ltail="cluster0" ,lhead="cluster4" ,comment="7"  ];
    3 -> 1 [ ltail="cluster2" ,lhead="cluster0" ,comment="8"  ];
    3 -> 5 [ ltail="cluster2" ,lhead="cluster4" ,comment="9"  ];
}

哪个给我:

不用担心标签问题,我会解决的.

Don't worry about the label problems, I'll fix that.

C#代码如下:

Graph<State> Graph = new Graph<State> { Rankdir = RankDirection.LeftToRight };

stringBuilder生成子图

A stringBuilder generates the subgraphs

// returns new SubGraph<State>{ Label = stringBuilder.ToString()};
var stringNewBlock = ConvertBlockToSubgraph(state); 

在ConvertBlockToSubgraph内部

Inside ConvertBlockToSubgraph

foreach (var allowedOperation in allowedOperationList)
            {
                stringBuilder.Append(allowedOperation.Key +":\\n");

                foreach (var operation in allowedOperation.Value)
                {
                    stringBuilder.Append(!operation.Equals(lastAllowedOperation) ? operation + ",": operation);
                }
            }

回到外面的世界:

var subgraphNewBlock = new SubGraph<State>{ Label = stringBuilder.ToString()};


stringNewBlock.AddVertex(state);
Graph.AddSubGraph(stringNewBlock);

然后我用以下方法生成边线:

Then I generate the Edges with:

public override IBlockHandling<State> GenerateLinks()
{
    foreach (var state in statesDictionary.Values)
    {
        foreach (var nextPossibleState in state.GetNextPossibleStateList())
        {
            if (statesDictionary.ContainsKey(nextPossibleState))
            {
                var sourceSubGraph = Graph.SubGraphs.Single(x => x.Label.Contains(state.GetMainHeaderName()));
                var destinationSubGraph = Graph.SubGraphs.Single(x => x.Label.Contains(nextPossibleState));
                var edge = new Edge<SubGraph<State>>(sourceSubGraph, destinationSubGraph);
                Graph.AddEdge(edge);
            }

        }
    }

    return this;
}

然后我使用以下方法转换为DOT格式:

Then I convert to the DOT Format with:

    public override IBlockHandling<State> ConvertDtoToDot()
    {
        var writer = new StringWriter();
        new GraphToDotConverter().Convert(writer, Graph, new AttributesProvider());
        var result = writer.GetStringBuilder().ToString().Trim();

        Console.WriteLine(result);

        return this;
    }

我仍然遇到的问题是看起来很奇怪的箭头.

有什么建议吗?

推荐答案

如果您的问题是箭头形状,请参见以下代码:

If your problem is in the arrows shape, please see the below code:

var edge = new Edge<SubGraph<State>>(sourceSubGraph, destinationSubGraph , 
     new Arrow(),  new DiamondArrow());

有关更多信息,请检查以下内容:

For more info please check the below :

Graphviz4Net

这篇关于Graphviz(4net)到DOT的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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