Skip to content

Instantly share code, notes, and snippets.

@sitetechie
Created March 9, 2015 21:55
Show Gist options
  • Save sitetechie/c0014b19e4aebb68f1f8 to your computer and use it in GitHub Desktop.
Save sitetechie/c0014b19e4aebb68f1f8 to your computer and use it in GitHub Desktop.
BPM::Engine::Trait::GraphViz
package BPM::Engine::Trait::GraphViz;
## no critic (RequireEndWithOne)
use MooseX::Declare;
role BPM::Engine::Trait::GraphViz {
use GraphViz;
use BPM::Engine::Types qw/UUID/;
method get_process_graphviz (UUID|HashRef $id, HashRef $args = {}) {
my $process = $self->get_process_definition($id, $args);
my $graphViz = GraphViz->new(
overlap => 'compress',
rankdir => 1, # left-right
directed => 1,
node => {
fontname => "Verdana",
name => "graph",
shape => 'box',
style => 'filled',
fillcolor => '#EFEFEF',
},
);
foreach my $activity($process->activities->all) {
my %args = ();
$args{style} = $activity->is_implementation_type ?
'filled,rounded' : 'filled';
$graphViz->add_node(
$activity->activity_uid,
label => $activity->activity_name || $activity->activity_uid,
#URL => "javascript:alert('node')",
fillcolor =>
$activity->is_implementation_type ? '#EFEFEF' :
($activity->is_event_type ? '#ABABAB' : '#BCBCBC'),
shape =>
$activity->is_route_type ? 'diamond' :
($activity->is_event_type ?
($activity->is_end_activity ? 'doublecircle' : 'circle')
: 'box'),
%args,
);
}
my @transitions = $process->transitions(
{}, { prefetch => ['from_activity', 'to_activity'] }
)->all;
foreach my $transition(@transitions) {
$graphViz->add_edge(
$transition->from_activity->activity_uid,
$transition->to_activity->activity_uid,
#URL => "javascript:alert('edge')",
);
}
return $graphViz;
}
}
1;
__END__
=pod
=head1 NAME
BPM::Engine::Trait::GraphViz
=head1 SYNOPSIS
my $engine = BPM::Engine->new_with_traits(
traits => [qw/GraphViz/],
connect_info => { dsn => 'dbi:SQLite:dbname=/Data/Source/BPM-Engine/t/var/bpmengine.db' }
);
my $gv = $engine->get_process_graphviz(1);
$gv->as_png('1.png');
=head1 DESCRIPTION
A L<BPM::Engine> trait that creates a GraphViz object for a process
=head1 METHODS
=head2 get_process_graphviz
Returns a GraphViz object for the specified process definition
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment