Graphviz::DSL - Graphviz Perl interface with DSL
use Graphviz::DSL; my $graph = graph { name 'Sample'; route main => [qw/init parse cleanup printf/]; route init => 'make', parse => 'execute'; route execute => [qw/make compare printf /]; nodes colorscheme => 'piyg8', style => 'filled'; my $index = 1; for my $n ( nodeset() ) { node($n->id, fillcolor => $index++); } edges arrowhead => 'onormal', color => 'magenta4'; edge ['main' => 'printf'], arrowtail => 'diamond', color => '#3355FF'; global bgcolor => 'white'; node 'execute', shape => 'Mrecord', label => '{<x>execute | {a | b | c}}'; node 'printf', shape => 'Mrecord', label => '{printf |<y> format}'; edge ['execute:x' => 'printf:y']; rank 'same', 'cleanup', 'execute'; subgraph { global label => 'SUB'; node 'init'; node 'make'; }; subgraph { global label => 'SUB2'; multi_route +{ 'a' => [qw/b c d/], 'd' => 'e', 'f' => { 'g' => { 'h' => 'i'}, 'j' => 'k', }, }; }; }; $graph->save(path => 'output', type => 'png', encoding => 'utf-8');
Graphviz::DSL is Perl version of Ruby gem Gviz. This module provide DSL for generating DOT file(and image if you install Graphviz dot command). Outputted DOT file may be similar to your DSL, because Graphviz::DSL try to keep objects order in DSL(Order of objects in DSL is very important. If you change some objects order, then output image may be changed).
name $name
Set $name as graph name. Default is 'G'.
$name
type $type
Set $type as graph type. $type should be digraph(directed graph) or graph(undirected graph). Default is 'digraph'.
$type
add, route
Add nodes and them edges. route is alias of add function. You can call these methods like following.
route
add
add $nodes
Add $nodes to this graph. $nodes should be Scalar or ArrayRef.
$nodes
add $node1, \@edges1, $node2, \@edges2 ...
Add nodes and edges. $noden should be Scalar or ArrayRef. For example:
$noden
add [qw/a b/], [qw/c d/]
Add node a and b and add edge a->c, a->d, b->c, b->d.
multi_route(\%routes])
Add multiple routes at once.
multi_route +{ a => [qw/b c/], d => 'e', f => { g => { h => 'i'}, j => 'k', }, };
equals to following:
route a => 'b', a => 'c'; route d => 'e'; route f => 'g', f => 'j'; route g => 'h'; route h => 'i'; route j => 'k';
node($node_id, [%attributes])
Add node or update attribute of specified node.
edge($edge_id, [%attributes])
Add edge or update attribute of specified edge.
nodes(%attributes)
Update attribute of all nodes.
edges(%attributes)
Update attribute of all edges.
nodeset
Return registered nodes.
edgeset
Return registered edges.
global
Update graph attribute.
rank
Set rank.
subgraph($coderef)
Create subgraph.
$graph->save(%args)
Save graph as DOT file.
%args is:
%args
Basename of output file.
Output image type, such as png, gif, if you install Graphviz(dot command). If dot command is not found, it generate only dot file. Graphviz::DSL don't output image if you omit this attribute.
Graphviz::DSL
Encoding of output DOT file. Default is utf-8.
$graph->as_string
Return DOT file as string. This is same as stringify itself. Graphviz::DSL overload stringify operation.
Gviz https://github.com/melborne/Gviz
Graphviz http://www.graphviz.org/
Syohei YOSHIDA <syohex@gmail.com>
Copyright 2013- Syohei YOSHIDA
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Graphviz::DSL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graphviz::DSL
CPAN shell
perl -MCPAN -e shell install Graphviz::DSL
For more information on module installation, please visit the detailed CPAN module installation guide.