« lib/Gtk2/Ex/MindMapView/Layout/Group.pm
↑ Summary
blib/lib/Gtk2/Ex/MindMapView/Content/Picture.pm »
| 1 | package Gtk2::Ex::MindMapView::Layout::Cluster; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.000001'; | |||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use List::Util; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Gtk2::Ex::MindMapView::Layout::Group; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use base 'Gtk2::Ex::MindMapView::Layout::Group'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | # $cluster = Gtk2::Ex::MindMapView::Layout::Cluster->new(); | ||||||||||
| 17 | |||||||||||
| 18 | sub new | ||||||||||
| 19 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 20 | 0 | my $class = shift(@_); | |||||||||
| 21 | |||||||||||
| 22 | 0 | my $self = $class->SUPER::new(@_); | |||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | if (!defined $self->{cluster_no}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | { | ||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 39 | 0 | my ($self, $item) = @_; | |||||||||
| 40 | |||||||||||
| 41 | 0 | push @{$self->{items}}, $item; | |||||||||
| 42 | |||||||||||
| 43 | 0 | my $column = $self->get('column'); | |||||||||
| 44 | |||||||||||
| 45 | 0 | my @items = @{$self->{items}}; | |||||||||
| 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 | 0 | ▶ | { | ||||||||
|
Subroutine
layout: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 57 | 0 | 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}}; | |||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | return if (scalar @visible_items == 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | { | ||||||||
|
Subroutine
seq_no: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 88 | 0 | my $self = shift(@_); | |||||||||
| 89 | |||||||||||
| 90 | 0 | my $predecessor_item = $self->{predecessor}; | |||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | return (defined $predecessor_item) ? $predecessor_item->get('y') : $self->{cluster_no}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | sub _cluster_height | ||||||||||
| 97 | 0 | ▶ | { | ||||||||
|
Subroutine
_cluster_height: not called CC=2 SCAR=17.9
| |||||||||||
| 98 | 0 | my ($self, $items_ref) = @_; | |||||||||
| 99 | |||||||||||
| 100 | 0 | my @visible_items = grep { $_->is_visible(); } @$items_ref; | |||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | return 0 if (scalar @visible_items == 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | |||||||||||
| 104 | 0 | my $total_height = List::Util::sum (map { $_->get('height'); } @visible_items); | |||||||||
| 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 | 0 | ▶ | { | ||||||||
|
Subroutine
_cluster_width: not called CC=2 SCAR=17.9
| |||||||||||
| 116 | 0 | my ($self, $items_ref) = @_; | |||||||||
| 117 | |||||||||||
| 118 | 0 | my @visible_items = grep { $_->is_visible(); } @$items_ref; | |||||||||
| 119 | |||||||||||
| 120 | 0 | ▶ | return 0 if (scalar @visible_items == 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | |||||||||||
| 122 | 0 | my $max_width = List::Util::max (map { $_->get('width'); } @$items_ref); | |||||||||
| 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 | 0 | ▶ | { | ||||||||
|
Subroutine
_justification: not called CC=3 SCAR=24.8
| |||||||||||
| 134 | 0 | my ($column_no, $column_width, $item_width) = @_; | |||||||||
| 135 | |||||||||||
| 136 | 0 | ▶ | return 0 if ($column_no > 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | |||||||||||
| 138 | 0 | ▶ | return ($column_width - $item_width) if ($column_no < 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 139 | |||||||||||
| 140 | 0 | return (($column_width - $item_width) / 2); | |||||||||
| 141 | } | ||||||||||
| 142 | |||||||||||
| 143 | |||||||||||
| 144 | |||||||||||
| 145 | 1 | 1; # Magic true value required at end of module | |||||||||
| 146 | __END__ | ||||||||||