1GraphViz2::Data::GrapheUrs(e3r)Contributed Perl DocumentGartaipohnViz2::Data::Grapher(3)
2
3
4
6 GraphViz2::Data::Grapher - Visualize a data structure as a graph
7
9 #!/usr/bin/env perl
10
11 use strict;
12 use warnings;
13
14 use File::Spec;
15
16 use GraphViz2;
17 use GraphViz2::Data::Grapher;
18
19 use Log::Handler;
20
21 # ------------------------------------------------
22
23 my($logger) = Log::Handler -> new;
24
25 $logger -> add
26 (
27 screen =>
28 {
29 maxlevel => 'debug',
30 message_layout => '%m',
31 minlevel => 'error',
32 }
33 );
34
35 my($sub) = sub{};
36 my($s) =
37 {
38 A =>
39 {
40 a =>
41 {
42 },
43 bbbbbb => $sub,
44 c123 => $sub,
45 d => \$sub,
46 },
47 C =>
48 {
49 b =>
50 {
51 a =>
52 {
53 a =>
54 {
55 },
56 b => sub{},
57 c => 42,
58 },
59 },
60 },
61 els => [qw(element_1 element_2 element_3)],
62 };
63
64 my($graph) = GraphViz2 -> new
65 (
66 edge => {color => 'grey'},
67 global => {directed => 1},
68 graph => {rankdir => 'TB'},
69 logger => $logger,
70 node => {color => 'blue', shape => 'oval'},
71 );
72
73 my($g) = GraphViz2::Data::Grapher -> new(graph => $graph, logger => $logger);
74 my($format) = shift || 'svg';
75 my($output_file) = shift || File::Spec -> catfile('html', "parse.data.$format");
76
77 $g -> create(name => 's', thing => $s);
78 $graph -> run(format => $format, output_file => $output_file);
79
80 # If you did not provide a GraphViz2 object, do this
81 # to get access to the auto-created GraphViz2 object.
82
83 #$g -> create(name => 's', thing => $s);
84 #$g -> graph -> run(format => $format, output_file => $output_file);
85
86 # Or even
87
88 #$g -> create(name => 's', thing => $s)
89 #-> graph
90 #-> run(format => $format, output_file => $output_file);
91
92 See scripts/parse.data.pl ("Scripts Shipped with this Module" in
93 GraphViz2).
94
96 Takes a Perl data structure and recursively converts it into
97 Tree::DAG_Node object, and then graphs it.
98
99 You can write the result in any format supported by Graphviz
100 <http://www.graphviz.org/>.
101
102 Here is the list of output formats
103 <http://www.graphviz.org/content/output-formats>.
104
105 Within the graph:
106
107 o Array names are preceeded by '@'
108 o Code references are preceeded by '&'
109 o Hash names are preceeded by '%'
110 o Scalar names are preceeded by '$'
111
112 Hence, a hash ref will look like '%$h'.
113
114 Further, objects of different type have different shapes.
115
117 This module is available as a Unix-style distro (*.tgz).
118
119 See <http://savage.net.au/Perl-modules/html/installing-a-module.html>
120 for help on unpacking and installing distros.
121
123 Install GraphViz2 as you would for any "Perl" module:
124
125 Run:
126
127 cpanm GraphViz2
128
129 or run:
130
131 sudo cpan GraphViz2
132
133 or unpack the distro, and then either:
134
135 perl Build.PL
136 ./Build
137 ./Build test
138 sudo ./Build install
139
140 or:
141
142 perl Makefile.PL
143 make (or dmake or nmake)
144 make test
145 make install
146
148 Calling new()
149 "new()" is called as "my($obj) = GraphViz2::Data::Grapher -> new(k1 =>
150 v1, k2 => v2, ...)".
151
152 It returns a new object of type "GraphViz2::Data::Grapher".
153
154 Key-value pairs accepted in the parameter list:
155
156 o graph => $graphviz_object
157 This option specifies the GraphViz2 object to use. This allows you
158 to configure it as desired.
159
160 The default is GraphViz2 -> new. The default attributes are the
161 same as in the synopsis, above, except for the graph label of
162 course.
163
164 This key is optional.
165
166 o logger => $logger_object
167 Provides a logger object so $logger_object -> $level($message) can
168 be called at certain times.
169
170 Retrieve and update the value with the logger() method.
171
172 The default is ''.
173
174 At the moment, the logger object is not used. This feature is
175 mainly used for testing.
176
178 create(name => $name, thing => $thing)
179 Creates the graph, which is accessible via the graph() method, or via
180 the graph object you passed to new().
181
182 Returns $self to allow method chaining.
183
184 $name is the string which will be placed in the root node of the tree.
185
186 If $s = {...}, say, use 's', not '$s', because '%$' will be prefixed
187 automatically to the name, because $s is a hashref.
188
189 $thing is the data stucture to graph.
190
191 graph()
192 Returns the graph object, either the one supplied to new() or the one
193 created during the call to new().
194
195 tree()
196 Returns the tree object (of type Tree::DAG_Node) built before it is
197 traversed to generate the nodes and edges.
198
199 Traversal does change the attributes of nodes, by storing {record =>
200 $string} there, so that edges can be plotted from a parent to its
201 daughters.
202
203 Warning: As the GraphViz2::Data::Grapher object exits its scope, $self
204 -> tree -> delete_tree is called.
205
207 See "FAQ" in GraphViz2 and "Scripts Shipped with this Module" in
208 GraphViz2.
209
211 Many thanks are due to the people who chose to make Graphviz
212 <http://www.graphviz.org/> Open Source.
213
214 And thanks to Leon Brocard <http://search.cpan.org/~lbrocard/>, who
215 wrote GraphViz, and kindly gave me co-maint of the module.
216
218 Version numbers < 1.00 represent development versions. From 1.00 up,
219 they are production versions.
220
222 The file Changes was converted into Changelog.ini by
223 Module::Metadata::Changes.
224
226 Email the author, or log a bug on RT:
227
228 <https://rt.cpan.org/Public/Dist/Display.html?Name=GraphViz2>.
229
231 GraphViz2 was written by Ron Savage <ron@savage.net.au> in 2011.
232
233 Home page: <http://savage.net.au/index.html>.
234
236 Australian copyright (c) 2011, Ron Savage.
237
238 All Programs of mine are 'OSI Certified Open Source Software';
239 you can redistribute them and/or modify them under the terms of
240 The Perl License, a copy of which is available at:
241 http://dev.perl.org/licenses/
242
243
244
245perl v5.32.0 2020-07-28 GraphViz2::Data::Grapher(3)