0

I'm trying to show the attributes of the statuses under the nodes label.

It's currently like this:

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

I have the code:

        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()"});

I want to show it more or less like this:

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

As it's difficult to find examples of implementations using graphviz, I don't know how to add the values in the nodes. Does somebody know what i should do before converting it?

Th3B0Y
  • 884
  • 1
  • 12
  • 30
  • Are you using QuickGraph? – marapet Oct 11 '13 at 15:44
  • @marapet i'm using graphviz4net – Th3B0Y Oct 11 '13 at 23:07
  • Unfortunately, the question was not tagged with graphviz4net, but better late, than never. A short article about customizing graph elements in WPF: http://graphviz4net.codeplex.com/wikipage?title=Customization%20of%20various%20graph%20elements&referringTitle=Documentation – Steves Oct 24 '13 at 07:33
  • @Steves I can't add tags and graphviz4net doesn't exist on stack overflow. I read that link (I had read it before as well). Thank you. – Th3B0Y Oct 25 '13 at 07:49

1 Answers1

1

I don't know anything about graphviz4net but this is fairly easy to achieve just using Graphviz's DOT language utilizing clusters:

graph

The DOT file for this graph is as follows:

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()"]
}

You can fairly easy tweak the look by changing the font, color and style of the various elements. To play around with it I would suggest using GraphViz Workspace to get a quick feel for what which attribute (and it's setting) does. The attribute manual can be a bit overwhelming but it has everything you need.

Potherca
  • 13,207
  • 5
  • 76
  • 94
  • Your answer clarified a lot, thank you. Do you know how I could set node [shape = "none"] in C#? I'm using graphviz4net. – Th3B0Y Oct 15 '13 at 14:05
  • You are welcome, glad to help. Unfortunately, I have no experience with graphviz4net. I've taken a look at the project but to me it seems like an overly complex way of wrapping Graphviz. As the project is *very* sparsely documented I also wouldn't where to point to other than the sourcecode :-( If you know how to change the color for nodes you could set it the same colour as the background? Other than that I think that feeding DOT syntax to the [AntlrParserAdapter class](http://graphviz4net.codeplex.com/wikipage?title=DOT%20parsing%20with%20Graphviz4Net) might be your best bet. – Potherca Oct 15 '13 at 18:29