/usr/share/perl5/Graph/Writer/VCG.pm is in libgraph-readwrite-perl 2.06-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | #
# Graph::Writer::VCG - write a directed graph out in VCG format
#
package Graph::Writer::VCG;
use strict;
use warnings;
use parent 'Graph::Writer';
our $VERSION = '2.06';
#-----------------------------------------------------------------------
# Attribute type information
#-----------------------------------------------------------------------
use constant VCG_ATTR_TYPE_INTEGER => 1;
use constant VCG_ATTR_TYPE_STRING => 2;
use constant VCG_ATTR_TYPE_FLOAT => 3;
my $enum_color = [qw(aquamarine black blue cyan darkblue darkcyan darkgreen
darkgrey darkmagenta darkred darkyellow gold green khaki
lightblue lightcyan lightgreen lightgrey lightmagenta
lightred lightyellow lilac magenta orange orchid pink
purple red turquoise white yellow yellowgreen)];
my $enum_yes_no = [qw(yes no)];
my $enum_textmode = [qw(center left_justify right_justify)];
my $enum_shape = [qw(box rhomb ellipse triangle)];
my $enum_arrowstyle = [qw(none line solid)];
my %common_attrs =
(
label => VCG_ATTR_TYPE_STRING,
color => $enum_color,
textcolor => $enum_color,
);
#-----------------------------------------------------------------------
# List of valid dot attributes for the entire graph, per node,
# and per edge. You can set other attributes, but they won't get
# written out.
#-----------------------------------------------------------------------
my %valid_attributes =
(
graph => {
%common_attrs,
title => VCG_ATTR_TYPE_STRING,
info1 => VCG_ATTR_TYPE_STRING,
info2 => VCG_ATTR_TYPE_STRING,
info3 => VCG_ATTR_TYPE_STRING,
bordercolor => $enum_color,
width => VCG_ATTR_TYPE_INTEGER,
height => VCG_ATTR_TYPE_INTEGER,
borderwidth => VCG_ATTR_TYPE_INTEGER,
x => VCG_ATTR_TYPE_INTEGER,
y => VCG_ATTR_TYPE_INTEGER,
# loc
folding => VCG_ATTR_TYPE_INTEGER,
scaling => VCG_ATTR_TYPE_FLOAT,
shrink => VCG_ATTR_TYPE_INTEGER,
stretch => VCG_ATTR_TYPE_INTEGER,
textmode => $enum_textmode,
shape => $enum_shape,
level => VCG_ATTR_TYPE_INTEGER,
vertical_order => VCG_ATTR_TYPE_INTEGER,
horizontal_order => VCG_ATTR_TYPE_INTEGER,
status => [qw(black grey white)],
xmax => VCG_ATTR_TYPE_INTEGER,
ymax => VCG_ATTR_TYPE_INTEGER,
xbase => VCG_ATTR_TYPE_INTEGER,
ybase => VCG_ATTR_TYPE_INTEGER,
xspace => VCG_ATTR_TYPE_INTEGER,
xlspace => VCG_ATTR_TYPE_INTEGER,
yspace => VCG_ATTR_TYPE_INTEGER,
xraster => VCG_ATTR_TYPE_INTEGER,
xlraster => VCG_ATTR_TYPE_INTEGER,
invisble => VCG_ATTR_TYPE_INTEGER,
hidden => VCG_ATTR_TYPE_INTEGER,
# classname
# colorentry
# infoname
layoutalgorithm => [qw(tree maxdepth mindepth maxdepthslow
mindepthslow maxdegree mindegree
maxindegree minindegree maxoutdegree
minoutdegree minbackward dfs)],
layout_downfactor => VCG_ATTR_TYPE_INTEGER,
layout_upfactor => VCG_ATTR_TYPE_INTEGER,
layout_nearfactor => VCG_ATTR_TYPE_INTEGER,
splinefactor => VCG_ATTR_TYPE_INTEGER,
late_edge_labels => $enum_yes_no,
display_edge_labels => $enum_yes_no,
dirty_edge_labels => $enum_yes_no,
finetuning => $enum_yes_no,
ignoresingles => $enum_yes_no,
straight_phase => $enum_yes_no,
priority_phase => $enum_yes_no,
manhattan_edges => $enum_yes_no,
smanhattan_edges => $enum_yes_no,
nearedges => $enum_yes_no,
orientation => [qw(top_to_bottom bottom_to_top
left_to_right right_to_left)],
node_alignment => [qw(bottom top center)],
port_sharing => $enum_yes_no,
arrowmode => [qw(fixed free)],
spreadlevel => VCG_ATTR_TYPE_INTEGER,
treefactor => VCG_ATTR_TYPE_FLOAT,
crossingphase2 => $enum_yes_no,
crossingoptimization=> $enum_yes_no,
crossingweight => [qw(bary median barymedian medianbary)],
view => [qw(cfish fcfish pfish fpfish)],
edges => $enum_yes_no,
nodes => $enum_yes_no,
splines => $enum_yes_no,
bmax => VCG_ATTR_TYPE_INTEGER,
cmax => VCG_ATTR_TYPE_INTEGER,
cmin => VCG_ATTR_TYPE_INTEGER,
pmax => VCG_ATTR_TYPE_INTEGER,
pmin => VCG_ATTR_TYPE_INTEGER,
rmax => VCG_ATTR_TYPE_INTEGER,
rmin => VCG_ATTR_TYPE_INTEGER,
smax => VCG_ATTR_TYPE_INTEGER,
},
node => {
%common_attrs,
info1 => VCG_ATTR_TYPE_STRING,
info2 => VCG_ATTR_TYPE_STRING,
info3 => VCG_ATTR_TYPE_STRING,
bordercolor => $enum_color,
width => VCG_ATTR_TYPE_INTEGER,
height => VCG_ATTR_TYPE_INTEGER,
borderwidth => VCG_ATTR_TYPE_INTEGER,
# loc
folding => VCG_ATTR_TYPE_INTEGER,
scaling => VCG_ATTR_TYPE_FLOAT,
shrink => VCG_ATTR_TYPE_INTEGER,
stretch => VCG_ATTR_TYPE_INTEGER,
textmode => $enum_textmode,
shape => $enum_shape,
level => VCG_ATTR_TYPE_INTEGER,
vertical_order => VCG_ATTR_TYPE_INTEGER,
horizontal_order => VCG_ATTR_TYPE_INTEGER,
},
edge => {
%common_attrs,
thickness => VCG_ATTR_TYPE_INTEGER,
class => VCG_ATTR_TYPE_INTEGER,
priority => VCG_ATTR_TYPE_INTEGER,
arrowcolor => $enum_color,
backarrowcolor => $enum_color,
arrowsize => VCG_ATTR_TYPE_INTEGER,
backarrowsize => VCG_ATTR_TYPE_INTEGER,
arrowstyle => $enum_arrowstyle,
backarrowstyle => $enum_arrowstyle,
linestyle => [qw(continuous solid dotted
dashed invisible)],
anchor => VCG_ATTR_TYPE_INTEGER,
horizontal_order => VCG_ATTR_TYPE_INTEGER,
},
);
#=======================================================================
#
# _write_graph()
#
# The private method which actually does the writing out in
# VCG format.
#
# This is called from the public method, write_graph(), which is
# found in Graph::Writer.
#
#=======================================================================
sub _write_graph
{
my $self = shift;
my $graph = shift;
my $FILE = shift;
my $v;
my $from;
my $to;
my $aref;
my @keys;
#-------------------------------------------------------------------
#-------------------------------------------------------------------
print $FILE "graph: {\n";
#-------------------------------------------------------------------
# Dump out any overall attributes of the graph
#-------------------------------------------------------------------
$aref = $graph->get_graph_attributes();
_render_attributes('graph', $aref, $FILE);
#-------------------------------------------------------------------
# Dump out a list of the nodes, along with any defined attributes
#-------------------------------------------------------------------
foreach $v (sort $graph->vertices)
{
print $FILE " node: { title: \"$v\"";
$aref = $graph->get_vertex_attributes($v);
_render_attributes('node', $aref, $FILE, 1);
print $FILE " }\n";
}
print $FILE "\n";
#-------------------------------------------------------------------
# Dump out a list of the edges, along with any defined attributes
#-------------------------------------------------------------------
foreach my $edge (sort _by_vertex $graph->edges)
{
($from, $to) = @$edge;
print $FILE " edge: { sourcename: \"$from\" targetname: \"$to\"";
$aref = $graph->get_edge_attributes($from, $to);
_render_attributes('edge', $aref, $FILE, 1);
print $FILE " }\n";
}
print $FILE "}\n";
return 1;
}
sub _by_vertex
{
return $a->[0].$a->[1] cmp $b->[0].$b->[1];
}
#=======================================================================
#
# _render_attributes
#
# Take a hash of attribute names and values and format
# as VCG attribute specs, quoting the value if needed.
# We filter the hash against legal attributes, since VCG will
# barf on unknown attribute names.
#
# Returns the number of attributes written out.
#
#=======================================================================
sub _render_attributes
{
my $entity = shift; # 'graph' or 'node' or 'edge'
my $attref = shift;
my $FILE = shift;
my $depth = @_ > 0 ? shift : 0;
my @keys;
my $type;
@keys = grep(exists $attref->{$_}, keys %{$valid_attributes{$entity}});
if (@keys > 0)
{
print $FILE "\n";
foreach my $a (@keys)
{
$type = $valid_attributes{$entity}->{$a};
if (ref $type || $type == VCG_ATTR_TYPE_INTEGER
|| $type == VCG_ATTR_TYPE_FLOAT)
{
print $FILE " ", ' ' x $depth, "$a: ", $attref->{$a}, "\n";
}
else
{
print $FILE " ", ' ' x $depth,
"$a: \"", $attref->{$a}, "\"\n";
}
}
}
return int @keys;
}
1;
__END__
=head1 NAME
Graph::Writer::VCG - write out directed graph in VCG format
=head1 SYNOPSIS
use Graph;
use Graph::Writer::VCG;
$graph = Graph->new();
# add edges and nodes to the graph
$writer = Graph::Writer::VCG->new();
$writer->write_graph($graph, 'mygraph.vcg');
=head1 DESCRIPTION
B<Graph::Writer::VCG> is a class for writing out a directed graph
in the file format used by the I<VCG> tool, originally developed
for Visualising Compiler Graphs.
The graph must be an instance of the Graph class, which is
actually a set of classes developed by Jarkko Hietaniemi.
If you have defined any attributes for the graph,
nodes, or edges, they will be written out to the file,
as long as they are attributes understood by VCG.
=head1 METHODS
=head2 new()
Constructor - generate a new writer instance.
$writer = Graph::Writer::VCG->new();
This doesn't take any arguments.
=head2 write_graph()
Write a specific graph to a named file:
$writer->write_graph($graph, $file);
The C<$file> argument can either be a filename,
or a filehandle for a previously opened file.
=head1 KNOWN BUGS AND LIMITATIONS
=over 4
=item *
Attributes with non-atomic values aren't currently handled.
This includes the B<loc>, B<classname>, B<colorentry>,
and B<infoname> attributes for graphs,
and the B<loc> attribute for nodes,
=item *
Can currently only handle B<graph>, B<node>, and B<edge> elements
and their attributes.
So doesn't know about B<foldnode_defaults> and things like that.
=back
=head1 SEE ALSO
=over 4
=item http://www.cs.uni-sb.de/RW/users/sander/html/gsvcg1.html
The home page for VCG.
=item Graph
Jarkko Hietaniemi's modules for representing directed graphs,
available from CPAN under modules/by-module/Graph/
=item Algorithms in Perl
The O'Reilly book which has a chapter on directed graphs,
which is based around Jarkko's modules.
=item Graph::Writer
The base-class for Graph::Writer::VCG
=back
=head1 AUTHOR
Neil Bowers E<lt>neil@bowers.comE<gt>
=head1 COPYRIGHT
Copyright (c) 2001-2012, Neil Bowers. All rights reserved.
Copyright (c) 2001, Canon Research Centre Europe. All rights reserved.
This script is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|