GraphViz2

 view release on metacpan or  search on metacpan

t/gen.macro.5.t  view on Meta::CPAN

# Annotation: Demonstrates compound cluster subgraphs via a macro.

use strict;
use warnings;
use File::Spec;
use GraphViz2;

sub macro {
	my ($graph, $name, $node_1, $node_2) = @_;
	$graph->push_subgraph(
		name  => $name,
		graph => {label => $name},
		node  => {color => 'magenta', shape => 'diamond'},
	);
	$graph->add_node(name => $node_1, shape => 'hexagon');
	$graph->add_node(name => $node_2, color => 'orange');
	$graph->add_edge(from => $node_1, to => $node_2);
	$graph->pop_subgraph;
}

my $id    = '5';
my $graph = GraphViz2->new(
	edge   => {color => 'grey'},
	global => {directed => 1},
	graph  => {
		compound => 'true',
		label => "Macro demo $id - Compound cluster sub-graphs",
		rankdir => 'TB',
        },
);

macro($graph, 'cluster 1', 'Chadstone', 'Waverley');
macro($graph, 'cluster 2', 'Hughesdale', 'Notting Hill');

$graph->add_edge(
	from => 'Chadstone',
	to => 'Notting Hill',
	lhead => 'cluster 2',
	ltail => 'cluster 1',
	minlen => 2,
);

if (@ARGV) {
  my($format)      = shift || 'svg';
  my($output_file) = shift || File::Spec -> catfile('html', "macro.$id.$format");
  $graph -> run(format => $format, output_file => $output_file);
} else {
  # run as a test
  require Test::More;
  require Test::Snapshot;
  Test::Snapshot::is_deeply_snapshot($graph->dot_input, 'dot file');
  Test::More::done_testing();
}



( run in 1.658 second using v1.01-cache-2.11-cpan-39bf76dae61 )