Clicker/Renderer/Area.pm

filter: Statementstmt 37.5% 33 / 88 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 37.5% 42 / 112 CC 11 SCAR 42.9
CC
11
Cov
32%
__ANON__
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 73.0
« Clicker/Renderer/Bar.pm ↑ Summary Clicker/Axis/DateTime.pm »
1 package Chart::Clicker::Renderer::Area;
2 1 $Chart::Clicker::Renderer::Area::VERSION = '2.89';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 extends 'Chart::Clicker::Renderer';
6  
7 # ABSTRACT: Area renderer
8  
9 1 ▶use Graphics::Primitive::Brush;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Graphics::Primitive::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Graphics::Primitive::Operation::Fill;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Graphics::Primitive::Operation::Stroke;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Graphics::Primitive::Paint::Gradient::Linear;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Graphics::Primitive::Paint::Solid;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 has 'brush' => (
18 is => 'rw',
19 isa => 'Graphics::Primitive::Brush',
20 1 ▶ default => sub { Graphics::Primitive::Brush->new }
Subroutine __ANON__: called CC=1 SCAR=0.0
21 1 );
22  
23  
24 1 has 'fade' => (
25 is => 'rw',
26 isa => 'Bool',
27 default => 0
28 );
29  
30  
31 1 has 'opacity' => (
32 is => 'rw',
33 isa => 'Num',
34 default => 0
35 );
36  
37 override('finalize', sub {
38 0 ▶ my ($self) = @_;
Subroutine __ANON__: not called CC=11 SCAR=48.8
39  
40 0 my $height = $self->height;
41 0 my $width = $self->width;
42 0 my $clicker = $self->clicker;
43  
44 0 my $dses = $clicker->get_datasets_for_context($self->context);
45 0 foreach my $ds (@{ $dses }) {
46 0 foreach my $series (@{ $ds->series }) {
47  
48 # TODO if undef...
49 0 my $ctx = $clicker->get_context($ds->context);
50 0 my $domain = $ctx->domain_axis;
51 0 my $range = $ctx->range_axis;
52  
53 0 my $lastx; # used for completing the path
54 0 my @vals = @{ $series->values };
55 0 my @keys = @{ $series->keys };
56  
57 0 my $startx;
58  
59 my $biggest;
60 0 for(0..($series->key_count - 1)) {
61  
62 0 my $x = $domain->mark($width, $keys[$_]);
63 0 ▶ next unless defined($x);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 0 0 0
64  
65 0 my $ymark = $range->mark($height, $vals[$_]);
66 0 ▶ next unless defined($ymark);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ymark 0 0 0
67 0 my $y = $height - $ymark;
68  
69 0 ▶ if(defined($biggest)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $biggest) { } 0 0 0
70 0 ▶ $biggest = $y if $y > $biggest;
Branch: 1 branch
BranchTrueFalseTotal
if $y > $biggest 0 0 0
71 } else {
72 0 $biggest = $y;
73 }
74  
75 0 ▶ if($_ == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ == 0) { } 0 0 0
76 0 $startx = $x;
77 0 $self->move_to($x, $y);
78 } else {
79 0 $self->line_to($x, $y);
80 }
81 0 $lastx = $x;
82 }
83 0 my $color = $self->clicker->color_allocator->next;
84  
85 0 my $op = Graphics::Primitive::Operation::Stroke->new;
86 0 $op->preserve(1);
87 0 $op->brush($self->brush->clone);
88 0 $op->brush->color($color);
89  
90 0 $self->do($op);
91  
92 0 $self->line_to($lastx, $height);
93 0 $self->line_to($startx, $height);
94 0 $self->close_path;
95  
96 0 my $paint;
97 0 ▶ if($self->opacity) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->opacity) { } 0 0 0
elsif ($self->fade) { } 0 0 0
98  
99 0 my $clone = $color->clone;
100 0 $clone->alpha($self->opacity);
101 0 $paint = Graphics::Primitive::Paint::Solid->new(
102 color => $clone
103 );
104 } elsif($self->fade) {
105  
106 0 my $clone = $color->clone;
107 0 $clone->alpha($self->opacity);
108  
109 0 $paint = Graphics::Primitive::Paint::Gradient::Linear->new(
110 line => Geometry::Primitive::Line->new(
111 start => Geometry::Primitive::Point->new(x => 0, y => 0),
112 end => Geometry::Primitive::Point->new(x => 1, y => $biggest),
113 ),
114 style => 'linear'
115 );
116 0 $paint->add_stop(1.0, $color);
117 0 $paint->add_stop(0, $clone);
118 } else {
119  
120 0 $paint = Graphics::Primitive::Paint::Solid->new(
121 color => $color->clone
122 );
123 }
124 0 my $fillop = Graphics::Primitive::Operation::Fill->new(
125 paint => $paint
126 );
127  
128 0 $self->do($fillop);
129 }
130 }
131  
132 0 return 1;
133 1 });
134  
135 1 __PACKAGE__->meta->make_immutable;
136  
137 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 1 1;
140  
141 __END__
142  
143 =pod
144  
145 =head1 NAME
146  
147 Chart::Clicker::Renderer::Area - Area renderer
148  
149 =head1 VERSION
150  
151 version 2.89
152  
153 =head1 SYNOPSIS
154  
155 my $ar = Chart::Clicker::Renderer::Area->new({
156 fade => 1,
157 brush => Graphics::Primitive::Brush->new({
158 width => 2
159 })
160 });
161  
162 =head1 DESCRIPTION
163  
164 Chart::Clicker::Renderer::Area renders a dataset as line-like polygons with
165 their interior areas filled.
166  
167 =for HTML <p><img src="http://gphat.github.com/chart-clicker/static/images/examples/area.png" width="500" height="250" alt="Area Chart" /></p>
168  
169 =head1 ATTRIBUTES
170  
171 =head2 brush
172  
173 Set/Get the L<brush|Graphics::Primitive::Brush> that informs the line surrounding the area renders
174 individual segments.
175  
176 =head2 fade
177  
178 Set/Get the fade flag, which turns on or off a gradient in the area renderer.
179  
180 =head2 opacity
181  
182 Set the alpha value for the renderer, which makes things more or less opaque.
183  
184 =head1 AUTHOR
185  
186 Cory G Watson <gphat@cpan.org>
187  
188 =head1 COPYRIGHT AND LICENSE
189  
190 This software is copyright (c) 2016 by Cory G Watson.
191  
192 This is free software; you can redistribute it and/or modify it under
193 the same terms as the Perl 5 programming language system itself.
194  
195 =cut
« Clicker/Renderer/Bar.pm ↑ Summary Clicker/Axis/DateTime.pm »