lib/SVG/Sparkline/RangeArea.pm

filter: Statementstmt 95.6% 66 / 69 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 94.5% 86 / 91 CC 7 SCAR 9.4
CC
7
Cov
95%
make
5.0
_make_mark
2.0
valid_param
2.0
CRAP 2.6
« lib/SVG/Sparkline.pm ↑ Summary lib/SVG/Sparkline/Line.pm »
1 package SVG::Sparkline::RangeArea;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use SVG;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use SVG::Sparkline::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 our $VERSION = 1.11;
11  
12 # aliases to make calling shorter.
13 3 *_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 21 ▶ my ($class, $args) = @_;
Subroutine make: called CC=5 SCAR=16.1
Pod documented
22 # validate parameters
23 21 SVG::Sparkline::Utils::validate_array_param( $args, 'values' );
24 croak "'values' must be an array of pairs.\n"
25 17 ▶ if grep { 'ARRAY' ne ref $_ || 2 != @{$_} } @{$args->{values}};
Branch: 2 branches
BranchTrueFalseTotal
if grep {"ARRAY" ne ref $_ or 2 != @{$_;};} @{$$args{"values"};} 1 16 17
"ARRAY" ne ref $_ or 2 != @{$_;} 81 4 85
26 my $valdesc = SVG::Sparkline::Utils::summarize_xy_values(
27 16 [ (map { $_->[0] } @{$args->{values}}), (reverse map { $_->[1] } @{$args->{values}}) ]
28 );
29 16 $valdesc->{xrange} = $#{$args->{values}};
30 16 $valdesc->{xmax} = $#{$args->{values}};
31 16 my $off = $valdesc->{xrange};
32 16 foreach my $v (@{$valdesc->{vals}}[($off+1) .. $#{$valdesc->{vals}}])
33 {
34 81 $v->[0] = $off--;
35 }
36  
37 16 SVG::Sparkline::Utils::calculate_xscale( $args, $valdesc->{xrange} );
38 16 SVG::Sparkline::Utils::calculate_yscale_and_offset( $args, $valdesc->{yrange}, $valdesc->{offset} );
39 16 my $svg = SVG::Sparkline::Utils::make_svg( $args );
40  
41 my $points = SVG::Sparkline::Utils::xypairs_to_points_str(
42 $valdesc->{vals}, $args->{xscale}, $args->{yscale}
43 16 );
44 16 $svg->polygon( fill=>$args->{color}, points=>$points, stroke=>'none' );
45  
46 16 ▶ if( exists $args->{mark} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"mark"}) 5 11 16
47 {
48 _make_marks( $svg,
49 xscale=>$args->{xscale}, yscale=>$args->{yscale},
50 values=>$args->{values}, mark=>$args->{mark},
51 base=>$valdesc->{base}
52 5 );
53 }
54  
55 16 return $svg;
56 }
57  
58 sub _make_marks
59 {
60 5 ▶ my ($svg, %args) = @_;
Subroutine _make_marks: called CC=2 SCAR=6.9
61
62 5 my @marks = @{$args{mark}};
63 5 ▶ while(@marks)
Branch: 1 branch
BranchTrueFalseTotal
if (@marks) 5 5 10
64 {
65 5 my ($index,$color) = splice( @marks, 0, 2 );
66 5 $index = SVG::Sparkline::Utils::range_mark_to_index( 'RangeArea', $index, $args{values} );
67 5 _make_mark( $svg, %args, index=>$index, color=>$color );
68 }
69 5 return;
70 }
71  
72 sub _make_mark
73 {
74 5 ▶ my ($svg, %args) = @_;
Subroutine _make_mark: called CC=2 SCAR=7.0
75 5 my $index = $args{index};
76 5 my ($lo, $hi) = @{$args{values}->[$index]};
77 5 my $y = _f( ($lo-$args{base}) * $args{yscale} );
78 5 my $yh = _f( ($hi-$args{base}) * $args{yscale} );
79 5 my $x = _f($index * $args{xscale});
80  
81 5 ▶ if(abs($hi-$lo) <= 0.01)
Branch: 1 branch
BranchTrueFalseTotal
if (abs $hi - $lo <= 0.01) { } 0 5 5
82 {
83 0 $svg->circle( cx=>$x, cy=>$y, r=>1, fill=>$args{color}, stroke=>'none' );
84 }
85 else
86 {
87 $svg->line( x1=>$x, y1=>$y, x2=>$x, y2=>$yh,
88 5 fill=>'none', stroke=>$args{color}, 'stroke-width'=>1
89 );
90 }
91 5 return;
92 }
93  
94 3 1;
95  
96 __END__
« lib/SVG/Sparkline.pm ↑ Summary lib/SVG/Sparkline/Line.pm »