« blib/lib/Gtk2/Ex/MindMapView/Content/Picture.pm
↑ Summary
blib/lib/Gtk2/Ex/MindMapView/ArgUtils.pm »
| 1 | package Gtk2::Ex::MindMapView::Layout::Column; | ||||||||||
| 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 | 1 | ▶ | use Gtk2::Ex::MindMapView::Layout::Cluster; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | use base 'Gtk2::Ex::MindMapView::Layout::Group'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | sub new | ||||||||||
| 17 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 18 | 0 | my $class = shift(@_); | |||||||||
| 19 | |||||||||||
| 20 | 0 | my $self = $class->SUPER::new(@_); | |||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | if (!defined $self->{column_no}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | { | ||||||||||
| 24 | 0 | croak "Gtk2::Ex::MindMapView::Layout::Column requires a 'column_no'\n"; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 0 | $self->{clusters} = {}; # Hash of clusters. | |||||||||
| 28 | |||||||||||
| 29 | 0 | return $self; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | # $column->add($predecessor_item, $item) | ||||||||||
| 34 | |||||||||||
| 35 | sub add | ||||||||||
| 36 | 0 | ▶ | { | ||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 37 | 0 | my ($self, $predecessor_item, $item) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | my $cluster_item = (defined $predecessor_item) ? $predecessor_item : $item; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | my $cluster = $self->{clusters}{$cluster_item}; | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | if (!defined $cluster) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | { | ||||||||||
| 45 | $cluster = Gtk2::Ex::MindMapView::Layout::Cluster->new(column=>$self, | ||||||||||
| 46 | predecessor=>$predecessor_item, | ||||||||||
| 47 | 0 | cluster_no=>(scalar keys(%{$self->{clusters}}))); | |||||||||
| 48 | |||||||||||
| 49 | 0 | $self->{clusters}{$cluster_item} = $cluster; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | $cluster->add($item); | |||||||||
| 53 | |||||||||||
| 54 | 0 | my @clusters = values (%{$self->{clusters}}); | |||||||||
| 55 | |||||||||||
| 56 | 0 | $self->set(height=>_column_height($self, \@clusters)); | |||||||||
| 57 | |||||||||||
| 58 | 0 | $self->set(width=>_column_width($self, \@clusters)); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | # $column->layout(); | ||||||||||
| 63 | |||||||||||
| 64 | sub layout | ||||||||||
| 65 | 0 | ▶ | { | ||||||||
|
Subroutine
layout: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 66 | 0 | my $self = shift(@_); | |||||||||
| 67 | |||||||||||
| 68 | 0 | my ($x, $y) = $self->get(qw(x y)); | |||||||||
| 69 | |||||||||||
| 70 | 0 | my @clusters = values (%{$self->{clusters}}); | |||||||||
| 71 | |||||||||||
| 72 | 0 | my @sorted_clusters = sort { $a->seq_no() <=> $b->seq_no() } @clusters; | |||||||||
| 73 | |||||||||||
| 74 | # my @sorted_clusters = sort { $a->get('cluster_no') <=> $b->get('cluster_no') } @clusters; | ||||||||||
| 75 | |||||||||||
| 76 | 0 | my @visible_clusters = grep { $_->get('height') > 0 } @sorted_clusters; | |||||||||
| 77 | |||||||||||
| 78 | 0 | foreach my $cluster (@visible_clusters) | |||||||||
| 79 | { | ||||||||||
| 80 | 0 | $cluster->set(x=>$x); | |||||||||
| 81 | |||||||||||
| 82 | 0 | $cluster->set(y=>$y); | |||||||||
| 83 | |||||||||||
| 84 | 0 | $cluster->layout(); | |||||||||
| 85 | |||||||||||
| 86 | 0 | $y += ($cluster->get('height') + $self->get_vertical_padding()); | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | sub _column_height | ||||||||||
| 92 | 0 | ▶ | { | ||||||||
|
Subroutine
_column_height: not called CC=2 SCAR=17.9
| |||||||||||
| 93 | 0 | my ($self, $clusters_ref) = @_; | |||||||||
| 94 | |||||||||||
| 95 | 0 | my @clusters = @$clusters_ref; | |||||||||
| 96 | |||||||||||
| 97 | 0 | my @visible_clusters = grep { $_->get('height') > 0 } @clusters; | |||||||||
| 98 | |||||||||||
| 99 | 0 | ▶ | return 0 if (scalar @visible_clusters == 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | |||||||||||
| 101 | 0 | my $total_height = List::Util::sum (map { $_->get('height'); } @visible_clusters); | |||||||||
| 102 | |||||||||||
| 103 | 0 | my $total_pad = ($#visible_clusters * $self->get_vertical_padding()); | |||||||||
| 104 | |||||||||||
| 105 | # print "Column, height: $total_height pad: $total_pad\n"; | ||||||||||
| 106 | |||||||||||
| 107 | 0 | return ($total_height + $total_pad); | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | sub _column_width | ||||||||||
| 111 | 0 | ▶ | { | ||||||||
|
Subroutine
_column_width: not called CC=1 SCAR=6.9
| |||||||||||
| 112 | 0 | my ($self, $clusters_ref) = @_; | |||||||||
| 113 | |||||||||||
| 114 | 0 | my @clusters = @$clusters_ref; | |||||||||
| 115 | |||||||||||
| 116 | 0 | my $max_width = List::Util::max (map { $_->get('width'); } @clusters); | |||||||||
| 117 | |||||||||||
| 118 | 0 | my $width = List::Util::min($max_width, $self->get_max_width()); | |||||||||
| 119 | |||||||||||
| 120 | # print "Column, max_width: $max_width width: $width\n"; | ||||||||||
| 121 | |||||||||||
| 122 | 0 | return $width; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | |||||||||||
| 126 | |||||||||||
| 127 | 1 | 1; # Magic true value required at end of module | |||||||||
| 128 | __END__ | ||||||||||