Clicker/Renderer/Bar.pm

filter: Statementstmt 27.6% 29 / 105 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod n/a totaltotal 25.5% 36 / 141 CC 17 SCAR 49.8
CC
17
Cov
22%
__ANON__
240.0
__ANON__
12.0
BEGIN
1.0
CRAP 145.7
« Clicker/Axis.pm ↑ Summary Clicker/Renderer/Area.pm »
1 package Chart::Clicker::Renderer::Bar;
2 2 $Chart::Clicker::Renderer::Bar::VERSION = '2.90';
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 extends 'Chart::Clicker::Renderer';
6  
7 # ABSTRACT: Bar renderer
8  
9 2 ▶use Graphics::Primitive::Brush;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Graphics::Primitive::Operation::Fill;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Graphics::Primitive::Operation::Stroke;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Graphics::Primitive::Paint::Solid;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 2 has 'bar_padding' => (
17 is => 'rw',
18 isa => 'Int',
19 default => 0
20 );
21  
22  
23 2 has 'bar_width' => (
24 is => 'rw',
25 isa => 'Num',
26 predicate => 'has_bar_width'
27 );
28  
29  
30 has 'brush' => (
31 is => 'rw',
32 isa => 'Graphics::Primitive::Brush',
33 3 ▶ default => sub { Graphics::Primitive::Brush->new }
Subroutine __ANON__: called CC=1 SCAR=0.0
34 2 );
35  
36  
37 2 has 'opacity' => (
38 is => 'rw',
39 isa => 'Num',
40 default => 1
41 );
42  
43 0 ▶override('prepare', sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
44 0 my $self = shift;
45  
46 0 super;
47  
48 0 my $datasets = $self->clicker->get_datasets_for_context($self->context);
49  
50 0 $self->{KEYCOUNT} = 0;
51 0 foreach my $ds (@{ $datasets }) {
52 0 $self->{SCOUNT} += $ds->count;
53 0 ▶ if($ds->max_key_count > $self->{KEYCOUNT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ds->max_key_count > $self->{"KEYCOUNT"}) 0 0 0
54 0 $self->{KEYCOUNT} = $ds->max_key_count;
55 }
56 }
57  
58 0 return 1;
59 2 });
60  
61 0 ▶override('finalize', sub {
Subroutine __ANON__: not called CC=15 SCAR=54.8
62 0 my ($self) = @_;
63  
64 0 my $clicker = $self->clicker;
65  
66 0 my $height = $self->height;
67 0 my $width = $self->width;
68  
69 0 my $dses = $clicker->get_datasets_for_context($self->context);
70  
71 0 my $brwidth = $self->brush->width;
72  
73 0 my $padding = $self->bar_padding + $brwidth * 2;
74  
75 0 my $offset = 1;
76 0 foreach my $ds (@{ $dses }) {
77 0 foreach my $series (@{ $ds->series }) {
78 # TODO if undef...
79 0 my $ctx = $clicker->get_context($ds->context);
80 0 my $domain = $ctx->domain_axis;
81 0 my $range = $ctx->range_axis;
82  
83 0 my $owidth = $width - ($width * $domain->fudge_amount);
84 0 my $bwidth;
85 0 ▶ if($self->has_bar_width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_bar_width) { } 0 0 0
86 0 $bwidth = $self->bar_width;
87 } else {
88 0 $bwidth = int(($owidth / $self->{KEYCOUNT})) - $padding;
89 }
90 0 my $hbwidth = int($bwidth / 2);
91  
92 # Fudge amounts mess up the calculation of bar widths, so
93 # we compensate for them here.
94 0 my $cbwidth = $bwidth / $self->{SCOUNT};
95 0 my $chbwidth = int($cbwidth / 2);
96  
97 0 my $color = $clicker->color_allocator->next;
98  
99 0 my $base = $range->baseline;
100 0 my $basey;
101 0 ▶ if(defined($base)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base) { } 0 0 0
102 0 $basey = $height - $range->mark($height, $base);
103 } else {
104 0 $basey = $height;
105 0 $base = $range->range->lower;
106 }
107  
108 0 my @vals = @{ $series->values };
109 0 my @keys = @{ $series->keys };
110  
111 0 my $sksent = $series->key_count;
112 0 for(0..($sksent - 1)) {
113  
114 # Skip drawing anything if the value is equal to the baseline
115 0 ▶ next if $vals[$_] == $range->baseline;
Branch: 1 branch
BranchTrueFalseTotal
if $vals[$_] == $range->baseline 0 0 0
116  
117 0 my $x = $domain->mark($width, $keys[$_]);
118 0 my $y = $range->mark($height, $vals[$_]);
119  
120 0 ▶ if($vals[$_] >= $base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vals[$_] >= $base) { } 0 0 0
121 0 ▶ if($self->{SCOUNT} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'SCOUNT'} == 1) { } 0 0 0
122 0 $self->move_to($x + $chbwidth, $basey);
123 0 $self->rectangle(
124 -int($cbwidth), -int($y - ($height - $basey))
125 );
126 } else {
127 0 $self->move_to(
128 $x - $hbwidth + ($offset * $cbwidth), $basey
129 );
130 0 $self->rectangle(
131 -int($cbwidth) + $brwidth, -int($y - ($height - $basey))
132 );
133 }
134 } else {
135 0 ▶ if($self->{SCOUNT} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'SCOUNT'} == 1) { } 0 0 0
136 0 $self->move_to($x + $chbwidth, $basey);
137 0 $self->rectangle(
138 -int($cbwidth), -int($y - ($height - $basey))
139 );
140 } else {
141 0 $self->move_to(
142 $x - $hbwidth + ($offset * $cbwidth), $basey
143 );
144 0 $self->rectangle(
145 -int($cbwidth) + $brwidth, int($height - $basey - $y)
146 );
147 }
148 }
149 }
150  
151 0 my $fillop = Graphics::Primitive::Operation::Fill->new(
152 paint => Graphics::Primitive::Paint::Solid->new
153 );
154  
155 0 ▶ if($self->opacity < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opacity < 1) { } 0 0 0
156 0 my $fillcolor = $color->clone;
157 0 $fillcolor->alpha($self->opacity);
158 0 $fillop->paint->color($fillcolor);
159 # Since we're going to stroke this, we want to preserve it.
160 0 ▶ $fillop->preserve(1) if $brwidth;
Branch: 1 branch
BranchTrueFalseTotal
if $brwidth 0 0 0
161 } else {
162 0 $fillop->paint->color($color);
163 }
164  
165 0 $self->do($fillop);
166  
167 0 ▶ if(($self->opacity < 1) && ($brwidth > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opacity < 1 and $brwidth > 0) 0 0 0
Condition0%0/3
$self->opacity < 1 and $brwidth > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->opacity < 1 and $brwidth > 0
$self->opacity < 1 $brwidth > 0
Truth table0%0/3
A and B
A= $self->opacity < 1B= $brwidth > 0
ABresult
0X0
100
111
168 0 my $strokeop = Graphics::Primitive::Operation::Stroke->new;
169 0 $strokeop->brush($self->brush->clone);
170 0 ▶ unless(defined($self->brush->color)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->brush->color) 0 0 0
171 0 $strokeop->brush->color($color);
172 }
173 0 $self->do($strokeop);
174 }
175  
176 0 $offset++;
177 }
178 }
179  
180 0 return 1;
181 2 });
182  
183 2 __PACKAGE__->meta->make_immutable;
184  
185 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
186  
187 2 1;
188  
189 __END__
« Clicker/Axis.pm ↑ Summary Clicker/Renderer/Area.pm »