line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SVG::Sparkline::Line; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
32
|
use warnings; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
238
|
|
4
|
7
|
|
|
7
|
|
27
|
use strict; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
188
|
|
5
|
7
|
|
|
7
|
|
27
|
use Carp; |
|
7
|
|
|
|
|
31
|
|
|
7
|
|
|
|
|
430
|
|
6
|
7
|
|
|
7
|
|
56
|
use SVG; |
|
7
|
|
|
|
|
37
|
|
|
7
|
|
|
|
|
42
|
|
7
|
7
|
|
|
7
|
|
5122
|
use SVG::Sparkline::Utils; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
169
|
|
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
220
|
use 5.008000; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
2938
|
|
10
|
|
|
|
|
|
|
our $VERSION = 1.11; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# aliases to make calling shorter. |
13
|
|
|
|
|
|
|
*_f = *SVG::Sparkline::Utils::format_f; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub valid_param { |
16
|
2
|
|
|
2
|
1
|
5
|
return scalar grep { $_[1] eq $_ } qw/thick xrange yrange/; |
|
6
|
|
|
|
|
23
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub make |
20
|
|
|
|
|
|
|
{ |
21
|
36
|
|
|
36
|
1
|
47
|
my ($class, $args) = @_; |
22
|
|
|
|
|
|
|
# validate parameters |
23
|
36
|
|
|
|
|
95
|
SVG::Sparkline::Utils::validate_array_param( $args, 'values' ); |
24
|
33
|
|
|
|
|
113
|
my $valdesc = SVG::Sparkline::Utils::summarize_xy_values( $args->{values} ); |
25
|
|
|
|
|
|
|
|
26
|
31
|
|
100
|
|
|
916
|
my $thick = $args->{thick} || 1; |
27
|
31
|
|
|
|
|
98
|
SVG::Sparkline::Utils::calculate_xscale( $args, $valdesc->{xrange} ); |
28
|
31
|
|
|
|
|
98
|
SVG::Sparkline::Utils::calculate_yscale_and_offset( $args, $valdesc->{yrange}, $valdesc->{offset} ); |
29
|
31
|
|
|
|
|
70
|
my $svg = SVG::Sparkline::Utils::make_svg( $args ); |
30
|
|
|
|
|
|
|
|
31
|
31
|
|
|
|
|
106
|
my $points = SVG::Sparkline::Utils::xypairs_to_points_str( |
32
|
|
|
|
|
|
|
$valdesc->{vals}, $args->{xscale}, $args->{yscale} |
33
|
|
|
|
|
|
|
); |
34
|
31
|
|
|
|
|
191
|
$svg->polyline( fill=>'none', 'stroke-width'=>$thick, stroke=>$args->{color}, 'stroke-linecap'=>'round', points=>$points ); |
35
|
|
|
|
|
|
|
|
36
|
31
|
100
|
|
|
|
1725
|
if( exists $args->{mark} ) |
37
|
|
|
|
|
|
|
{ |
38
|
16
|
|
|
|
|
35
|
_make_marks( $svg, |
39
|
|
|
|
|
|
|
thick=>$thick, xscale=>$args->{xscale}, yscale=>$args->{yscale}, |
40
|
|
|
|
|
|
|
values=>$valdesc->{vals}, mark=>$args->{mark} |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
31
|
|
|
|
|
210
|
return $svg; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _make_marks |
48
|
|
|
|
|
|
|
{ |
49
|
16
|
|
|
16
|
|
39
|
my ($svg, %args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
16
|
|
|
|
|
11
|
my @marks = @{$args{mark}}; |
|
16
|
|
|
|
|
27
|
|
52
|
16
|
|
|
|
|
37
|
my @yvalues = map { $_->[1] } @{$args{values}}; |
|
128
|
|
|
|
|
128
|
|
|
16
|
|
|
|
|
24
|
|
53
|
16
|
|
|
|
|
31
|
while(@marks) |
54
|
|
|
|
|
|
|
{ |
55
|
16
|
|
|
|
|
24
|
my ($index,$color) = splice( @marks, 0, 2 ); |
56
|
16
|
|
|
|
|
36
|
$index = SVG::Sparkline::Utils::mark_to_index( 'Line', $index, \@yvalues ); |
57
|
16
|
|
|
|
|
42
|
_make_mark( $svg, %args, index=>$index, color=>$color ); |
58
|
|
|
|
|
|
|
} |
59
|
16
|
|
|
|
|
32
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _make_mark |
63
|
|
|
|
|
|
|
{ |
64
|
16
|
|
|
16
|
|
43
|
my ($svg, %args) = @_; |
65
|
16
|
|
|
|
|
17
|
my $index = $args{index}; |
66
|
16
|
|
|
|
|
68
|
my $x = _f($args{xscale} * $args{values}->[$index]->[0]); |
67
|
16
|
|
|
|
|
49
|
my $y = _f($args{yscale} * $args{values}->[$index]->[1]); |
68
|
16
|
|
|
|
|
52
|
$svg->circle( cx=>$x, cy=>$y, r=>$args{thick}, |
69
|
|
|
|
|
|
|
stroke=>'none', fill=>$args{color} |
70
|
|
|
|
|
|
|
); |
71
|
16
|
|
|
|
|
811
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |