odrevet has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Is it possible to make subgraphs with the module GraphViz to have rectangles like in this example : http://www.graphviz.org/Gallery/directed/cluster.html

Replies are listed 'Best First'.
Re: Module GraphViz : make subgraphs ?
by djibel (Novice) on Jun 01, 2010 at 11:20 UTC
    Yes it is possible. See cluster2.pl example in GraphViz CPAN module.
    #!/usr/bin/perl use strict; use warnings; use GraphViz; my $g = GraphViz->new(); my @default_attrs = ( fontsize => '8', fontname => 'arial', ); my $eurocluster = {name=>'Europe', style=>'filled', fillcolor=>'lightgray', fontname=>'arial', fontsize=>'12', }; $g->add_node('London', cluster=>$eurocluster, @default_attrs); $g->add_node('Paris', cluster=>$eurocluster, @default_attrs); $g->add_node('New York', @default_attrs); $g->add_edge('London' => 'Paris', @default_attrs); $g->add_edge('London' => 'New York', label => 'Far', @default_attrs); $g->add_edge('Paris' => 'London', @default_attrs); $g->as_gif("nodes.gif"); $g->as_dot("nodes.dot");
    That is the result nodes.dot files
    digraph test { graph [ratio=fill]; node [label="\N"]; graph [bb="0,0,150,174"]; subgraph cluster_Europe { graph [fillcolor=lightgray, fontname=arial, fontsize=12, label=Europe, style=filled, bb="8,8,78,166"]; London [label=London, fontname=arial, fontsize=8, pos="43,118" +, width="0.75", height="0.5"]; Paris [label=Paris, fontname=arial, fontsize=8, pos="43,34", w +idth="0.75", height="0.5"]; London -> Paris [fontname=arial, fontsize=8, pos="e,37.367,51. +789 37.364,100.19 36.203,89.049 35.949,74.471 36.604,61.831"]; Paris -> London [fontname=arial, fontsize=8, pos="e,48.636,100 +.19 48.633,51.789 49.796,62.92 50.051,77.497 49.398,90.14"]; } "New York" [label="New York", fontname=arial, fontsize=8, pos="119 +,34", width="0.86111", height="0.5"]; London -> "New York" [fontname=arial, fontsize=8, label=Far, pos=" +e,104.51,50.015 57.295,102.2 68.687,89.609 84.811,71.787 97.72,57.52" +, lp="91.5,76"]; }
Re: Module GraphViz : make subgraphs ?
by marto (Cardinal) on Jun 01, 2010 at 10:43 UTC

    I've never used GraphViz, since the example you link to is named 'clusters', the GraphViz documentation has examples for 'clusters':

    "Nodes can be clustered together with the "cluster" attribute, which is drawn by having a labelled rectangle around all the nodes in a cluster. An empty string means not clustered...."