| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Graph::Renderer - draw the graph onto a real plane |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=cut |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Graph::Renderer; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4915
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
51
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use Carp qw (croak); |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
467
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
8
|
use vars qw ($VERSION @ISA @EXPORT_OK); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
106
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# $Id: Renderer.pm,v 1.4 2006/02/11 17:11:39 pasky Exp $ |
|
16
|
|
|
|
|
|
|
$VERSION = 0.03; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $graph = new Graph; |
|
22
|
|
|
|
|
|
|
... |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Graph::Layouter; |
|
25
|
|
|
|
|
|
|
Graph::Layouter::layout($graph); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Graph::Renderer; |
|
28
|
|
|
|
|
|
|
Graph::Renderer::render($graph, $img); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
7
|
use base qw (Graph::Layouter); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
620
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
require Exporter; |
|
36
|
|
|
|
|
|
|
push @ISA, 'Exporter'; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
@EXPORT_OK = qw (render); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This module provides an abstract class for drawing a given layouted graph |
|
44
|
|
|
|
|
|
|
(created usually by C) through various image creation |
|
45
|
|
|
|
|
|
|
interfaces (C, C). |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
All the relevant layouting information used for nodes positioning is load from |
|
48
|
|
|
|
|
|
|
the graph, as saved by C (see its documentation for the |
|
49
|
|
|
|
|
|
|
relevant attributes description). In addition, relevant rendering information |
|
50
|
|
|
|
|
|
|
can be load from the graph attributes as well, if necessary and available. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This module contains only the abstract class, you will probably want to get an |
|
53
|
|
|
|
|
|
|
instance of some particular drawing tool interface instead; |
|
54
|
|
|
|
|
|
|
C is bundled with this distribution. The general |
|
55
|
|
|
|
|
|
|
interface for all the subclasses is described below, but be sure consult also |
|
56
|
|
|
|
|
|
|
the particular class' documentation for remarks, special notes and specific |
|
57
|
|
|
|
|
|
|
extensions. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=over 4 |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
1
|
|
|
1
|
|
8
|
use Graph; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
614
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item B |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This subroutine is the only entry point of this module, taking a given graph |
|
71
|
|
|
|
|
|
|
and rendering it accordingly to its attributes. The subroutine can be called in |
|
72
|
|
|
|
|
|
|
several ways: |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over 4 |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item I |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The subroutine can be called as a function (it is not automatically exported, |
|
79
|
|
|
|
|
|
|
but you can import it on your own if you really want; see the synopsis above). |
|
80
|
|
|
|
|
|
|
It takes two parameters, the C class (or any descendant) instance and |
|
81
|
|
|
|
|
|
|
instance of the appropriate image object (see subclasses documentation). It |
|
82
|
|
|
|
|
|
|
will load the rendering information from graph's both global and per-vertex |
|
83
|
|
|
|
|
|
|
attributes. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item I |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
TODO |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item I |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
TODO |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The subroutine returns the image object if it all went well, undef otherwise. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The common rendering attributes not generated by the layouter are: |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item I |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over 4 |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item B |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This should contain information about the font used for vertex titles; the |
|
108
|
|
|
|
|
|
|
specific format depends on the subclass. If this information is not made |
|
109
|
|
|
|
|
|
|
available by the caller, the given backend can try to figure it out but it |
|
110
|
|
|
|
|
|
|
might well fail. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item I |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over 4 |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item B |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is identical to the global B attribute, but used |
|
121
|
|
|
|
|
|
|
only for the single vertex. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item B |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Title of the vertex, which is displayed nearby. The vertex number is displayed |
|
126
|
|
|
|
|
|
|
if no title is attached. You can attach an empty string to the vertex if you |
|
127
|
|
|
|
|
|
|
want no title shown at all. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub render { |
|
136
|
0
|
|
|
0
|
1
|
|
my $graph = shift; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
croak "Graph::Renderer::render() called instead of something of a subclass!"; |
|
139
|
0
|
|
|
|
|
|
$graph; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Internal use only, for subclasses; get maximal weight in the graph. |
|
144
|
|
|
|
|
|
|
sub _max_weight($) { |
|
145
|
0
|
|
|
0
|
|
|
my $graph = shift; |
|
146
|
0
|
|
|
|
|
|
my $max_weight = 0; |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
my @edges = $graph->edges; |
|
149
|
0
|
|
|
|
|
|
foreach my $edge (@edges) { |
|
150
|
0
|
|
|
|
|
|
my $weight = $graph->get_edge_attribute(@$edge, 'weight'); |
|
151
|
0
|
|
0
|
|
|
|
$weight ||= 1; # TODO : configurable |
|
152
|
0
|
0
|
|
|
|
|
$max_weight = $weight if $max_weight < $weight; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$max_weight; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Internal use only, for subclasses; maps virtual coord to physical pane |
|
159
|
|
|
|
|
|
|
sub _transpose_coord($$$$) { |
|
160
|
0
|
|
|
0
|
|
|
my ($virtual, $min, $max, $size) = @_; |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
$max++ if $max == $min; # Division by zero protector |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$size * ($virtual - $min) / ($max - $min); |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
C, C |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 BUGS |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
The object-oriented interface is missing as well as some more universal render |
|
180
|
|
|
|
|
|
|
calling interface (hash parameters). Also, some more rendering attributes |
|
181
|
|
|
|
|
|
|
(ie. color settings, own dimensions) are missing. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Copyright 2004 by Petr Baudis Epasky@ucw.czE. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This code is distributed under the same copyright terms as |
|
189
|
|
|
|
|
|
|
Perl itself. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 VERSION |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Version 0.03 |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
$Id: Renderer.pm,v 1.4 2006/02/11 17:11:39 pasky Exp $ |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |