lib/SVG/Sparkline/Area.pm

filter: Statementstmt 96.2% 51 / 53 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 95.7% 68 / 71 CC 4 SCAR 4.3
CC
4
Cov
97%
valid_param
2.0
make
2.0
_make_marks
2.0
CRAP 1.5
« lib/SVG/Sparkline/Line.pm ↑ Summary
1 package SVG::Sparkline::Area;
2  
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use SVG;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use SVG::Sparkline::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 our $VERSION = 1.11;
11  
12 # aliases to make calling shorter.
13 7 *_f = *SVG::Sparkline::Utils::format_f;
14  
15 sub valid_param {
16 0 ▶ return scalar grep { $_[1] eq $_ } qw/xrange yrange/;
Subroutine valid_param: not called CC=1 SCAR=6.9
Pod documented
17 }
18  
19 sub make
20 {
21 34 ▶ my ($class, $args) = @_;
Subroutine make: called CC=2 SCAR=6.9
Pod documented
22 # validate parameters
23 34 SVG::Sparkline::Utils::validate_array_param( $args, 'values' );
24 31 my $valdesc = SVG::Sparkline::Utils::summarize_xy_values( $args->{values} );
25  
26 29 SVG::Sparkline::Utils::calculate_xscale( $args, $valdesc->{xrange} );
27 29 SVG::Sparkline::Utils::calculate_yscale_and_offset( $args, $valdesc->{yrange}, $valdesc->{offset} );
28 29 my $svg = SVG::Sparkline::Utils::make_svg( $args );
29  
30 my $points = SVG::Sparkline::Utils::xypairs_to_points_str(
31 29 [ [0,0], @{$valdesc->{vals}}, [$valdesc->{vals}->[-1]->[0],0] ],
32 $args->{xscale}, $args->{yscale}
33 29 );
34 29 $svg->polygon( fill=>$args->{color}, points=>$points, stroke=>'none' );
35  
36 29 ▶ if( exists $args->{mark} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"mark"}) 15 14 29
37 {
38 _make_marks( $svg,
39 xscale=>$args->{xscale}, yscale=>$args->{yscale},
40 values=>$valdesc->{vals}, mark=>$args->{mark}
41 15 );
42 }
43  
44 29 return $svg;
45 }
46  
47 sub _make_marks
48 {
49 15 ▶ my ($svg, %args) = @_;
Subroutine _make_marks: called CC=2 SCAR=6.9
50
51 15 my @marks = @{$args{mark}};
52 15 my @yvalues = map { $_->[1] } @{$args{values}};
53 15 ▶ while(@marks)
Branch: 1 branch
BranchTrueFalseTotal
if (@marks) 15 15 30
54 {
55 15 my ($index,$color) = splice( @marks, 0, 2 );
56 15 $index = SVG::Sparkline::Utils::mark_to_index( 'Area', $index, \@yvalues );
57 15 _make_mark( $svg, %args, index=>$index, color=>$color );
58 }
59 15 return;
60 }
61  
62 sub _make_mark
63 {
64 15 ▶ my ($svg, %args) = @_;
Subroutine _make_mark: called CC=2 SCAR=6.9
65 15 my $index = $args{index};
66 15 my $x = _f($args{xscale} * $args{values}->[$index]->[0]);
67 15 my $y = _f($args{yscale} * ($args{values}->[$index]->[1]));
68 15 ▶ if(abs($y) <= 0.01)
Branch: 1 branch
BranchTrueFalseTotal
if (abs $y <= 0.01) { } 2 13 15
69 {
70 2 $svg->circle( cx=>$x, cy=>$y, r=>1, fill=>$args{color}, stroke=>'none' );
71 }
72 else
73 {
74 $svg->line( x1=>$x, y1=>0, x2=>$x, y2=>$y,
75 13 fill=>'none', stroke=>$args{color}, 'stroke-width'=>1
76 );
77 }
78 15 return;
79 }
80  
81 7 1;
82  
83 __END__
« lib/SVG/Sparkline/Line.pm ↑ Summary