lib/SVG/Sparkline/Line.pm

filter: Statementstmt 100% 51 / 51 Branchbran 100% 4 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 70 / 70 CC 4 SCAR 4.8
CC
4
Cov
100%
make
3.0
_make_marks
2.0
BEGIN
1.0
CRAP 1.6
« lib/SVG/Sparkline/RangeArea.pm ↑ Summary lib/SVG/Sparkline/Area.pm »
1 package SVG::Sparkline::Line;
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 2 ▶ return scalar grep { $_[1] eq $_ } qw/thick xrange yrange/;
Subroutine valid_param: called CC=1 SCAR=0.0
Pod documented
17 }
18  
19 sub make
20 {
21 36 ▶ my ($class, $args) = @_;
Subroutine make: called CC=3 SCAR=11.0
Pod documented
22 # validate parameters
23 36 SVG::Sparkline::Utils::validate_array_param( $args, 'values' );
24 33 my $valdesc = SVG::Sparkline::Utils::summarize_xy_values( $args->{values} );
25  
26 31 ▶ my $thick = $args->{thick} || 1;
Condition100%2/2
$args->{'thick'} || 1
l!l
229
MC/DC100%1/1
$args->{'thick'} || 1
$args->{'thick'}
Truth table100%2/2
A
A= $args->{'thick'}
Aresult
11
00
27 31 SVG::Sparkline::Utils::calculate_xscale( $args, $valdesc->{xrange} );
28 31 SVG::Sparkline::Utils::calculate_yscale_and_offset( $args, $valdesc->{yrange}, $valdesc->{offset} );
29 31 my $svg = SVG::Sparkline::Utils::make_svg( $args );
30  
31 my $points = SVG::Sparkline::Utils::xypairs_to_points_str(
32 $valdesc->{vals}, $args->{xscale}, $args->{yscale}
33 31 );
34 31 $svg->polyline( fill=>'none', 'stroke-width'=>$thick, stroke=>$args->{color}, 'stroke-linecap'=>'round', points=>$points );
35  
36 31 ▶ if( exists $args->{mark} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"mark"}) 16 15 31
37 {
38 _make_marks( $svg,
39 thick=>$thick, xscale=>$args->{xscale}, yscale=>$args->{yscale},
40 values=>$valdesc->{vals}, mark=>$args->{mark}
41 16 );
42 }
43  
44 31 return $svg;
45 }
46  
47 sub _make_marks
48 {
49 16 ▶ my ($svg, %args) = @_;
Subroutine _make_marks: called CC=2 SCAR=6.9
50
51 16 my @marks = @{$args{mark}};
52 16 my @yvalues = map { $_->[1] } @{$args{values}};
53 16 ▶ while(@marks)
Branch: 1 branch
BranchTrueFalseTotal
if (@marks) 16 16 32
54 {
55 16 my ($index,$color) = splice( @marks, 0, 2 );
56 16 $index = SVG::Sparkline::Utils::mark_to_index( 'Line', $index, \@yvalues );
57 16 _make_mark( $svg, %args, index=>$index, color=>$color );
58 }
59 16 return;
60 }
61  
62 sub _make_mark
63 {
64 16 ▶ my ($svg, %args) = @_;
Subroutine _make_mark: called CC=1 SCAR=0.0
65 16 my $index = $args{index};
66 16 my $x = _f($args{xscale} * $args{values}->[$index]->[0]);
67 16 my $y = _f($args{yscale} * $args{values}->[$index]->[1]);
68 $svg->circle( cx=>$x, cy=>$y, r=>$args{thick},
69 stroke=>'none', fill=>$args{color}
70 16 );
71 16 return;
72 }
73  
74 7 1;
75  
76 __END__
« lib/SVG/Sparkline/RangeArea.pm ↑ Summary lib/SVG/Sparkline/Area.pm »