line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gtk2::Ex::MindMapView::Layout::Cluster; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.000001'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
61
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
12
|
use List::Util; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
47
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use Gtk2::Ex::MindMapView::Layout::Group; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use base 'Gtk2::Ex::MindMapView::Layout::Group'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
990
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# $cluster = Gtk2::Ex::MindMapView::Layout::Cluster->new(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
0
|
|
|
0
|
1
|
|
my $class = shift(@_); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if (!defined $self->{cluster_no}) |
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
|
|
|
croak "Gtk2::Ex::MindMapView::Layout::Cluster requires a 'cluster_no'\n"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$self->{items} = []; # Array of view items. |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# $cluster->add($item) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub add |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
0
|
1
|
|
my ($self, $item) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
push @{$self->{items}}, $item; |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $column = $self->get('column'); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my @items = @{$self->{items}}; |
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->set(height=>_cluster_height($self, \@items)); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$self->set(width=>_cluster_width($self, \@items)); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# $cluster->layout(); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub layout |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $column = $self->get('column'); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my ($x, $y) = $self->get(qw(x y)); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $column_no = $column->get('column_no'); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $column_width = $column->get('width'); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my @visible_items = grep { $_->is_visible(); } @{$self->{items}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
return if (scalar @visible_items == 0); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
foreach my $item (@visible_items) |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
|
|
|
my ($item_height, $item_width) = $item->get(qw(height width)); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $justification = _justification($column_no, $column_width, $item_width); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$item->set(x=>($x + $justification)); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$item->set(y=>$y); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$y += ($item_height + $self->get_vertical_padding()); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub seq_no |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
0
|
1
|
|
my $self = shift(@_); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $predecessor_item = $self->{predecessor}; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
return (defined $predecessor_item) ? $predecessor_item->get('y') : $self->{cluster_no}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _cluster_height |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
0
|
|
|
my ($self, $items_ref) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my @visible_items = grep { $_->is_visible(); } @$items_ref; |
|
0
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
return 0 if (scalar @visible_items == 0); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $total_height = List::Util::sum (map { $_->get('height'); } @visible_items); |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $total_pad = ($#visible_items * $self->get_vertical_padding()); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# print "Cluster, height: $total_height pad: $total_pad visible_items: @visible_items\n"; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return ($total_height + $total_pad); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _cluster_width |
115
|
|
|
|
|
|
|
{ |
116
|
0
|
|
|
0
|
|
|
my ($self, $items_ref) = @_; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my @visible_items = grep { $_->is_visible(); } @$items_ref; |
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
return 0 if (scalar @visible_items == 0); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $max_width = List::Util::max (map { $_->get('width'); } @$items_ref); |
|
0
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $width = List::Util::min($max_width, $self->get_max_width()); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# print "Cluster, max_width: $max_width width: $width visible_items: @visible_items\n"; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $width; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _justification |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
0
|
|
|
my ($column_no, $column_width, $item_width) = @_; |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
return 0 if ($column_no > 0); |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
return ($column_width - $item_width) if ($column_no < 0); |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return (($column_width - $item_width) / 2); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
146
|
|
|
|
|
|
|
__END__ |