1GraphViz(3)           User Contributed Perl Documentation          GraphViz(3)
2
3
4

NAME

6       Tk::GraphViz - Render an interactive GraphViz graph
7

SYNOPSIS

9           use Tk::GraphViz;
10           my $gv = $mw->GraphViz ( qw/-width 300 -height 300/ )
11             ->pack ( qw/-expand yes -fill both/ );
12           $gv->show ( $dotfile );
13

DESCRIPTION

15       The GraphViz widget is derived from Tk::Canvas.  It adds the ability to
16       render graphs in the canvas.  The graphs can be specified either using
17       the DOT graph-description language, or using via a GraphViz object.
18
19       When show() is called, the graph is passed to the dot command to
20       generate the layout info.  That info is then used to create rectangles,
21       lines, etc in the canvas that reflect the generated layout.
22
23       Once the items have been created in the graph, they can be used like
24       any normal canvas items: events can be bound, etc.  In this way,
25       interactive graphing applications can be created very easily.
26

METHODS

28   $gv->show ( graph, ?opt => val, ...? )
29       Renders the given graph in the canvas.  The graph itself can be
30       specified in a number of formats.  'graph' can be one of the following:
31
32       - An instance of the GraphViz class (or subclass thereof)
33       - A scalar containing a graph in DOT format.  The scalar must match
34       /^\s*(?:di)?graph /.
35       - An instance of the IO::Handle class (or subclass thereof), from which
36       to read a graph in DOT format.
37       - The name / path of a file that contains a graph in DOT format.
38
39       show() will recognize some options that control how the graph is
40       rendered, etc.  The recognized options:
41
42       layout => CMD
43           Specifies an alternate command to invoke to generate the layout of
44           the graph.  If not given, then default is 'dot'.  This can be used,
45           for example, to use 'neato' instead of 'dot'.
46
47       graphattrs => [ name => value, ... ]
48           Allows additional default graph attributes to be specified.  Each
49           name => value pair will be passed to dot as '-Gname=value' on the
50           command-line.
51
52       nodeattrs => [ name => value, ... ]
53           Allows additional default node attributes to be specified.  Each
54           name => value pair will be passed to dot as '-Nname=value' on the
55           command-line.
56
57       edgeattrs => [ name => value, ... ]
58           Allows additional default edge attributes to be specified.  Each
59           name => value pair will be passed to dot as '-Ename=value' on the
60           command-line.
61
62       For example, to use neato to generate a layout with non-overlapping
63       nodes and spline edges:
64
65           $gv->show ( $file, layout => 'neato',
66                       graphattrs => [qw( overlap false spline true )] );
67
68   $gv->createBindings ( ?option => value? )
69       The Tk::GraphViz canvas can be configured with some bindings for
70       standard operations.  If no options are given, the default bindings for
71       zooming and scrolling will be enabled.  Alternative bindings can be
72       specified via these options:
73
74       -zoom => true
75           Creates the default bindings for zooming.  Zooming in or out in the
76           canvas will be bound to <Shift-2> (Shift + mouse button 2).  To
77           zoom in, click and drag out a zoom rectangle from top left to
78           bottom right.  To zoom out, click and drag out a zoom rectangle
79           from bottom left to top right.
80
81       -zoom => spec
82           This will bind zooming to an alternative event sequence.  Examples:
83
84               -zoom => '<1>'      # Zoom on mouse button 1
85               -zoom => '<Ctrl-3>' # Zoom on Ctrl + mouse button 3
86
87       -scroll => true
88           Creates the default bindings for scrolling / panning.  Scrolling
89           the canvas will be bound to <2> (Mouse button 2).
90
91       -scroll => spec
92           This will bind scrolling to an alternative event sequence.
93           Examples:
94
95               -scroll => '<1>'      # Scroll on mouse button 1
96               -scroll => '<Ctrl-3>' # Scroll on Ctrl + mouse button 3
97
98       -keypad => true
99           Binds the keypad arrow / number keys to scroll the canvas, and the
100           keypad +/- keys to zoom in and out.  Note that the canvas must have
101           the keyboard focus for these bindings to be activated.  This is
102           done by default when createBindings() is called without any
103           options.
104
105   $gv->fit()
106       Scales all of the elements in the canvas to fit the canvas' width and
107       height.
108
109   $gv->zoom( -in => factor )
110       Zoom in by scaling everything up by the given scale factor.  The factor
111       should be > 1.0 in order to get reasonable behavior.
112
113   $gv->zoom( -out => factor )
114       Zoom out by scaling everything down by the given scale factor.  This is
115       equivalent to
116
117           $gv->zoom ( -in => 1/factor )
118
119       The factor show be > 1.0 in order to get reasonable behavior.
120

TAGS

122       In order to facilitate binding, etc, all of the graph elements (nodes,
123       edges, subgraphs) that a created in the cavas.  Specific tags are given
124       to each class of element.  Additionally, all attributes attached to an
125       element in the graph description (e.g. 'color', 'style') will be
126       included as tags.
127
128   Nodes
129       Node elements are identified with a 'node' tag.  For example, to bind
130       something to all nodes in a graph:
131
132           $gv->bind ( 'node', '<Any-Enter>', sub { ... } );
133
134       The value of the 'node' tag is the name of the node in the graph (which
135       is not equivalent to the node label -- that is the 'label' tag)
136
137   Edges
138       Edge elements are identified with a 'edge' tag.  For example, to bind
139       something to all edges in a graph:
140
141           $gv->bind ( 'edge', '<Any-Enter>', sub { ... } );
142
143       The value of the 'edge' tag is an a string of the form "node1 node2",
144       where node1 and node2 are the names of the respective nodes.  To make
145       it convenient to get the individual node names, the edge also has tags
146       'node1' and 'node2', which give the node names separately.
147
148   Subgraphs
149       Subgraph elements are identified with a 'subgraph' tag.  The value of
150       the 'subgraph' is the name of the subgraph / cluster.
151

EXAMPLES

153       The following example creates a GraphViz widgets to display a graph
154       from a file specified on the command line.  Whenever a node is clicked,
155       the node name and label are printed to stdout:
156
157           use GraphViz;
158           use Tk;
159
160           my $mw = new MainWindow ();
161           my $gv = $mw->Scrolled ( 'GraphViz',
162                                    -background => 'white',
163                                    -scrollbars => 'sw' )
164             ->pack ( -expand => '1', -fill => 'both' );
165
166           $gv->bind ( 'node', '<Button-1>', sub {
167                       my @tags = $gv->gettags('current');
168                       push @tags, undef unless (@tags % 2) == 0;
169                       my %tags = @tags;
170                       printf ( "Clicked node: '%s' => %s\n",
171                                $tags{node}, $tags{label} );
172                       } );
173
174           $gv->show ( shift );
175           MainLoop;
176

BUGS AND LIMITATIONS

178       Lots of DOT language features not yet implemented
179
180       Various node shapes and attributes: polygon, skew, ...
181       Edge arrow head types
182

ACKNOWLEDGEMENTS

184       See http://www.graphviz.org/ for more info on the graphviz tools.
185

AUTHOR

187       Jeremy Slade <jeremy@jkslade.net>
188
189       Other contributors: Mike Castle, John Cerney, Phi Kasten, Jogi
190       Kuenstner Tobias Lorenz, Charles Minc, Reinier Post, Slaven Rezic
191
193       Copyright 2003-2008 by Jeremy Slade
194
195       This library is free software; you can redistribute it and/or modify it
196       under the same terms as Perl itself.
197

POD ERRORS

199       Hey! The above document had some coding errors, which are explained
200       below:
201
202       Around line 2294:
203           You forgot a '=back' before '=head1'
204
205
206
207perl v5.32.0                      2020-07-28                       GraphViz(3)
Impressum