Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an edge from a node to a subgraph in Graphviz Dot?

Tags:

graphviz

dot

I want to create a graph that looks like this, i. e. where an edge goes from the node Manufacturer of means of production to the subgraph with the same name.

Expected result

I wrote the following code for this:

digraph G {
    rankdir=LR;
    compound=true;

    graph [fontname="Liberation Mono"];
    node [fontname="Liberation Mono"];
    edge [fontname="Liberation Mono"];

    subgraph cluster0 {
        label="System components";
        mmp [label="Manufacturer of means of production", shape=box];
    }

    subgraph cluster1 {
        t1start [label="Start of tact 1", shape=point]
        t1end [label="End of tact 1", shape=point ]
        subgraph cluster1_mmp {
            label="Manufacturer of means of production"

            cluster1_1 [label="Node 1", color=white]


            subgraph cluster1_1_1 {
                label="Technological cycle 1"

                cluster1_1_1 [label="Node 2", color=white]
            }
            subgraph cluster1_1_2 {
                label="Technological cycle 2"

                cluster1_1_2 [label="Node 2", color=white]
            }
        }
    }

    subgraph cluster2 {
        label="Такт 2"
        t2start [label="Start of tact 2", shape=point]
        t2end [label="End of tact 2", shape=point]

    }
    t1end -> t2start
    mmp -> cluster1_1 [ltail=cluster1_mmp]; 
}

If I try to compile this code ("C:\Program Files (x86)\Graphviz2.38\bin\"dot.exe -Tpng -ograph.png graph.dot ), I get the warning Warning: mmp -> cluster1_1: tail not inside tail cluster cluster1_mmp.

How can I fix it and make the edge go to the subgraph?

Update 1:

Below you can find the image of the expected result -- an edge that goes from a node to a subgraph (subgraph, not a node inside the subgraph). This edge is red in the image below.

Expected result

Update 2: Changed the code like shown below.

digraph G {
    rankdir=LR;
    compound=true;

    graph [fontname="Liberation Mono"];
    node [fontname="Liberation Mono"];
    edge [fontname="Liberation Mono"];

    subgraph cluster0 {
        label="System components";
        mmp [label="Manufacturer of means of production", shape=box];
    }

    subgraph cluster1 {
        t1start [label="Start of tact 1", shape=point]
        t1end [label="End of tact 1", shape=point ]
        subgraph cluster1_mmp {
            label="Manufacturer of means of production"

            testNode [label="Node 1", color=white]

            subgraph cluster1_1_1 {
                label="Technological cycle 1"

                cluster1_1_1 [label="Node 2", color=white]
            }
            subgraph cluster1_1_2 {
                label="Technological cycle 2"

                cluster1_1_2 [label="Node 2", color=white]
            }
        }
    }

    subgraph cluster2 {
        label="Такт 2"
        t2start [label="Start of tact 2", shape=point]
        t2end [label="End of tact 2", shape=point]

    }
    t1end -> t2start
    mmp -> cluster1 [ltail=cluster0, lhead=cluster1, label="           "];

}

Second attempt

like image 425
Dmitrii Pisarenko Avatar asked Apr 13 '18 09:04

Dmitrii Pisarenko


1 Answers

You need to change your last line

mmp -> cluster1_1 [ltail=cluster1_mmp];

to

mmp -> cluster1_1 [lhead=cluster1 label="           "]

And then the graph comes as expected

Issue fixed

Also if you want the edge to start from outside the box then you would do

mmp -> cluster1_1 [ltail=cluster0 lhead=cluster1 label="           "];

Box outside

Edit

The final code used

digraph G {
    rankdir=LR;
    compound=true;

    graph [fontname="Liberation Mono"];
    node [fontname="Liberation Mono"];
    edge [fontname="Liberation Mono"];

    subgraph cluster0 {
        label="System components";
        mmp [label="Manufacturer of means of production", shape=box];
    }

    subgraph cluster1 {
        t1start [label="Start of tact 1", shape=point]
        t1end [label="End of tact 1", shape=point ]
        subgraph cluster1_mmp {
            label="Manufacturer of means of production"

            cluster1_1 [label="Node 1", color=white]


            subgraph cluster1_1_1 {
                label="Technological cycle 1"

                cluster1_1_1 [label="Node 2", color=white]
            }
            subgraph cluster1_1_2 {
                label="Technological cycle 2"

                cluster1_1_2 [label="Node 2", color=white]
            }
        }
    }

    subgraph cluster2 {
        label="Такт 2"
        t2start [label="Start of tact 2", shape=point]
        t2end [label="End of tact 2", shape=point]

    }
    t1end -> t2start
    mmp -> cluster1_1 [lhead=cluster1 label="           "]
}

The fiddle link for the same

Fiddle

like image 89
Tarun Lalwani Avatar answered Jan 02 '23 18:01

Tarun Lalwani