line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Map::Tube::GraphViz::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
26166
|
use base qw(Exporter); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
259
|
|
5
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
89
|
|
6
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
82
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
3
|
|
|
3
|
|
1362
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
26062
|
|
|
3
|
|
|
|
|
58
|
|
10
|
3
|
|
|
3
|
|
171
|
use Readonly; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1219
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Constants. |
13
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(node_color node_color_without_label |
14
|
|
|
|
|
|
|
color_line); |
15
|
|
|
|
|
|
|
Readonly::Array our @COLORS => qw(red green yellow cyan magenta blue grey |
16
|
|
|
|
|
|
|
orange brown white greenyellow red4 violet tomato cadetblue aquamarine |
17
|
|
|
|
|
|
|
lawngreen indigo deeppink darkslategrey khaki thistle peru darkgreen |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Version. |
21
|
|
|
|
|
|
|
our $VERSION = 0.05; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Create GraphViz color node. |
24
|
|
|
|
|
|
|
sub node_color { |
25
|
0
|
|
|
0
|
1
|
|
my ($obj, $node) = @_; |
26
|
0
|
|
|
|
|
|
my %params = _node_color_params($obj, $node); |
27
|
0
|
|
|
|
|
|
$obj->{'g'}->add_node( |
28
|
|
|
|
|
|
|
'label' => $node->name, |
29
|
|
|
|
|
|
|
'name' => $node->id, |
30
|
|
|
|
|
|
|
%params, |
31
|
|
|
|
|
|
|
); |
32
|
0
|
|
|
|
|
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Create GraphViz color node without label. |
36
|
|
|
|
|
|
|
sub node_color_without_label { |
37
|
0
|
|
|
0
|
1
|
|
my ($obj, $node) = @_; |
38
|
0
|
|
|
|
|
|
my %params = _node_color_params($obj, $node); |
39
|
0
|
|
|
|
|
|
$obj->{'g'}->add_node( |
40
|
|
|
|
|
|
|
'label' => '', |
41
|
|
|
|
|
|
|
'name' => $node->id, |
42
|
|
|
|
|
|
|
%params, |
43
|
|
|
|
|
|
|
); |
44
|
0
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Get line color. |
48
|
|
|
|
|
|
|
sub color_line { |
49
|
0
|
|
|
0
|
1
|
|
my ($obj, $line) = @_; |
50
|
0
|
|
0
|
|
|
|
my $line_name = $line->id || $line->name; |
51
|
0
|
0
|
|
|
|
|
if (! exists $obj->{'_color_line'}->{$line_name}) { |
52
|
0
|
0
|
|
|
|
|
if ($line->color) { |
53
|
0
|
|
|
|
|
|
$obj->{'_color_line'}->{$line_name} = $line->color; |
54
|
|
|
|
|
|
|
} else { |
55
|
0
|
0
|
|
|
|
|
if (! exists $obj->{'_color_index'}) { |
56
|
0
|
|
|
|
|
|
$obj->{'_color_index'} = 0; |
57
|
|
|
|
|
|
|
} else { |
58
|
0
|
|
|
|
|
|
$obj->{'_color_index'}++; |
59
|
0
|
0
|
|
|
|
|
if ($obj->{'_color_index'} > $#COLORS) { |
60
|
0
|
|
|
|
|
|
err "No color for line '$line'."; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
my $rand_color = $COLORS[$obj->{'_color_index'}]; |
64
|
0
|
|
|
|
|
|
$obj->{'_color_line'}->{$line_name} = $rand_color; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
return $obj->{'_color_line'}->{$line_name}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Get color node parameters. |
71
|
|
|
|
|
|
|
sub _node_color_params { |
72
|
0
|
|
|
0
|
|
|
my ($obj, $node) = @_; |
73
|
0
|
|
|
|
|
|
my @node_lines = @{$node->line}; |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my %params; |
75
|
0
|
0
|
|
|
|
|
if (@node_lines == 1) { |
76
|
0
|
|
|
|
|
|
%params = ( |
77
|
|
|
|
|
|
|
'style' => 'filled', |
78
|
|
|
|
|
|
|
'fillcolor' => color_line($obj, $node_lines[0]), |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
} else { |
81
|
0
|
|
|
|
|
|
%params = ( |
82
|
|
|
|
|
|
|
'style' => 'wedged', |
83
|
|
|
|
|
|
|
'fillcolor' => (join ':', map { |
84
|
0
|
|
|
|
|
|
color_line($obj, $_); |
85
|
|
|
|
|
|
|
} @node_lines), |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
return %params; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |