Map-Tube-GraphViz
view release on metacpan or search on metacpan
GraphViz.pm view on Meta::CPAN
}
if (! blessed($self->{'tube'})
|| ! $self->{'tube'}->DOES('Map::Tube')) {
err "Parameter 'tube' must be 'Map::Tube' object.";
}
# GraphViz2 object.
if (defined $self->{'g'}) {
if (defined $self->{'name'}) {
err "Parameter 'name' cannot be used with ".
"'g' parameter.";
}
# Check GraphViz2 object.
if (! blessed($self->{'g'})
|| ! $self->{'g'}->isa('GraphViz2')) {
err "Parameter 'g' must be 'GraphViz2' object.";
}
} else {
my $name = $self->{'name'};
if (! defined $name) {
$name = $self->{'tube'}->name;
}
$self->{'g'} = GraphViz2->new(
'global' => {
'directed' => 0,
},
$name ? (
'graph' => {
'label' => $name,
'labelloc' => 'top',
},
) : (),
);
}
# Check output format.
if (! defined $self->{'output'}) {
err "Parameter 'output' is required.";
}
if (! exists $self->{'g'}->valid_output_format->{$self->{'output'}}) {
err "Unsupported 'output' parameter '$self->{'output'}'.";
}
# Object.
return $self;
}
# Get graph.
sub graph {
my ($self, $output_file) = @_;
my $node_cache_hr = {};
foreach my $node (values %{$self->{'tube'}->nodes}) {
$self->{'callback_node'}->($self, $node);
$node_cache_hr->{$node->id} = $node;
}
my @processed;
foreach my $node (values %{$self->{'tube'}->nodes}) {
foreach my $link (split m/,/ms, $node->link) {
if (none {
($_->[0] eq $node->id && $_->[1] eq $link)
||
($_->[0] eq $link && $_->[1] eq $node->id)
} @processed) {
# Skip link to myself.
my $link_node = $node_cache_hr->{$link};
if ($self->{'callback_node_id'}->($self, $node)
ne $self->{'callback_node_id'}
->($self, $link_node)) {
$self->{'callback_edge'}->($self, $node,
$link_node);
}
push @processed, [$node->id, $link];
}
}
}
eval {
$self->{'g'}->run(
'driver' => $self->{'driver'},
'format' => $self->{'output'},
'output_file' => $output_file,
);
};
if ($EVAL_ERROR) {
err 'Cannot create GraphViz output.',
'Error', $EVAL_ERROR,
'Dot input', $self->{'g'}->dot_input;
}
return;
}
1;
__END__
=encoding utf8
=head1 NAME
Map::Tube::GraphViz - GraphViz output for Map::Tube.
=head1 SYNOPSIS
use Map::Tube::GraphViz;
my $obj = Map::Tube::GraphViz->new(%params);
$obj->graph($output_file);
=head1 METHODS
=over 8
=item C<new(%params)>
Constructor.
=over 8
( run in 1.695 second using v1.01-cache-2.11-cpan-71847e10f99 )