line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SVG::Sparkline; |
2
|
|
|
|
|
|
|
|
3
|
31
|
|
|
31
|
|
1316908
|
use warnings; |
|
31
|
|
|
|
|
74
|
|
|
31
|
|
|
|
|
977
|
|
4
|
30
|
|
|
30
|
|
155
|
use strict; |
|
30
|
|
|
|
|
58
|
|
|
30
|
|
|
|
|
10610
|
|
5
|
30
|
|
|
30
|
|
160
|
use Carp; |
|
30
|
|
|
|
|
67
|
|
|
30
|
|
|
|
|
2117
|
|
6
|
30
|
|
|
30
|
|
38552
|
use SVG; |
|
30
|
|
|
|
|
902640
|
|
|
30
|
|
|
|
|
224
|
|
7
|
|
|
|
|
|
|
|
8
|
30
|
|
|
30
|
|
153716
|
use overload '""' => \&to_string; |
|
30
|
|
|
|
|
52627
|
|
|
30
|
|
|
|
|
521
|
|
9
|
|
|
|
|
|
|
|
10
|
30
|
|
|
30
|
|
2770
|
use 5.008000; |
|
30
|
|
|
|
|
121
|
|
|
30
|
|
|
|
|
46843
|
|
11
|
|
|
|
|
|
|
our $VERSION = 1.10; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %valid_parms = map { $_ => 1 } qw( |
14
|
|
|
|
|
|
|
-allns color -sized |
15
|
|
|
|
|
|
|
height width xscale yscale pady padx |
16
|
|
|
|
|
|
|
color bgcolor mark values |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new |
20
|
|
|
|
|
|
|
{ |
21
|
225
|
|
|
225
|
1
|
173330
|
my ($class, $type, $args) = @_; |
22
|
225
|
100
|
|
|
|
886
|
croak "No Sparkline type specified.\n" unless defined $type; |
23
|
|
|
|
|
|
|
# Use eval to load plugin. |
24
|
224
|
|
|
28
|
|
23115
|
eval "use SVG::Sparkline::$type;"; ## no critic (ProhibitStringyEval) |
|
28
|
|
|
28
|
|
22632
|
|
|
27
|
|
|
26
|
|
164
|
|
|
27
|
|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|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
51
|
|
25
|
224
|
100
|
|
|
|
850
|
croak "Unrecognized Sparkline type '$type'.\n" if $@; |
26
|
223
|
100
|
|
|
|
711
|
croak "Missing arguments hash.\n" unless defined $args; |
27
|
222
|
100
|
|
|
|
730
|
croak "Arguments not supplied as a hash reference.\n" unless 'HASH' eq ref $args; |
28
|
221
|
|
|
|
|
634
|
_no_unrecognized_parameters( $type, $args ); |
29
|
|
|
|
|
|
|
|
30
|
221
|
|
|
|
|
1483
|
my $self = bless { |
31
|
|
|
|
|
|
|
-allns => 0, |
32
|
|
|
|
|
|
|
color => '#000', |
33
|
|
|
|
|
|
|
-sized => 1, |
34
|
221
|
|
|
|
|
575
|
%{$args}, |
35
|
|
|
|
|
|
|
}, $class; |
36
|
|
|
|
|
|
|
|
37
|
221
|
|
|
|
|
860
|
$self->_validate_pos_param( 'height', 12 ); |
38
|
219
|
|
|
|
|
2331
|
$self->_validate_pos_param( 'width', 0 ); |
39
|
217
|
|
|
|
|
483
|
$self->_validate_pos_param( 'xscale' ); |
40
|
215
|
|
|
|
|
451
|
$self->_validate_pos_param( 'yscale' ); |
41
|
215
|
|
|
|
|
581
|
$self->_validate_nonneg_param( 'pady', 1 ); |
42
|
214
|
|
|
|
|
465
|
$self->_validate_nonneg_param( 'padx', 0 ); |
43
|
213
|
|
|
|
|
728
|
$self->_validate_mark_param(); |
44
|
203
|
|
|
|
|
390
|
foreach my $arg (qw/color bgcolor/) |
45
|
|
|
|
|
|
|
{ |
46
|
405
|
100
|
|
|
|
7399
|
next unless exists $self->{$arg}; |
47
|
212
|
100
|
|
|
|
592
|
croak "The value of $arg is not a valid color.\n" |
48
|
|
|
|
|
|
|
unless _is_color( $self->{$arg} ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
201
|
|
|
|
|
638
|
$self->{xoff} = -$self->{padx}; |
52
|
201
|
|
|
|
|
600
|
$self->_make( $type ); |
53
|
|
|
|
|
|
|
|
54
|
170
|
|
|
|
|
625
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
1
|
0
|
sub get_height { return $_[0]->{height}; } |
58
|
0
|
|
|
0
|
1
|
0
|
sub get_width { return $_[0]->{width}; } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub to_string |
61
|
|
|
|
|
|
|
{ |
62
|
189
|
|
|
189
|
1
|
7593
|
my ($self) = @_; |
63
|
189
|
|
|
|
|
846
|
my $str = $self->{_SVG}->xmlify(); |
64
|
|
|
|
|
|
|
# Cleanup |
65
|
189
|
100
|
|
|
|
140909
|
$str =~ s/ xmlns:(?:svg|xlink)="[^"]+"//g unless $self->{'-allns'}; |
66
|
189
|
100
|
|
|
|
615
|
unless( $self->{'-sized'} ) |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
# If I try to keep them from being created, default '100%' values |
69
|
|
|
|
|
|
|
# show up instead. |
70
|
6
|
|
|
|
|
58
|
$str =~ s/( |
71
|
6
|
|
|
|
|
46
|
$str =~ s/( |
72
|
|
|
|
|
|
|
} |
73
|
189
|
|
|
|
|
18983
|
return $str; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _make |
77
|
|
|
|
|
|
|
{ |
78
|
201
|
|
|
201
|
|
323
|
my ($self, $type) = @_; |
79
|
201
|
|
|
|
|
1043
|
$self->{_SVG} = "SVG::Sparkline::$type"->make( $self ); |
80
|
170
|
|
|
|
|
394
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _no_unrecognized_parameters { |
84
|
221
|
|
|
221
|
|
384
|
my ( $type, $args ) = @_; |
85
|
221
|
|
|
|
|
527
|
my $class = "SVG::Sparkline::$type"; |
86
|
221
|
|
|
|
|
329
|
foreach my $parm (keys %{$args}) { |
|
221
|
|
|
|
|
869
|
|
87
|
410
|
50
|
66
|
|
|
1809
|
croak "Parameter '$parm' not recognized for '$type'\n" |
88
|
|
|
|
|
|
|
unless exists $valid_parms{$parm} || $class->valid_param( $parm ); |
89
|
|
|
|
|
|
|
} |
90
|
221
|
|
|
|
|
563
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _validate_pos_param |
94
|
|
|
|
|
|
|
{ |
95
|
872
|
|
|
872
|
|
1662
|
my ($self, $name, $default) = @_; |
96
|
872
|
100
|
100
|
|
|
11553
|
croak "'$name' must have a positive numeric value.\n" |
97
|
|
|
|
|
|
|
if exists $self->{$name} && $self->{$name} <= 0; |
98
|
866
|
100
|
|
|
|
2101
|
return if exists $self->{$name}; |
99
|
|
|
|
|
|
|
|
100
|
835
|
100
|
|
|
|
2365
|
$self->{$name} = $default if defined $default; |
101
|
835
|
|
|
|
|
1260
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _validate_nonneg_param |
105
|
|
|
|
|
|
|
{ |
106
|
429
|
|
|
429
|
|
666
|
my ($self, $name, $default) = @_; |
107
|
429
|
100
|
100
|
|
|
1676
|
croak "'$name' must be a non-negative numeric value.\n" |
108
|
|
|
|
|
|
|
if exists $self->{$name} && $self->{$name} < 0; |
109
|
427
|
100
|
|
|
|
908
|
return if exists $self->{$name}; |
110
|
|
|
|
|
|
|
|
111
|
405
|
50
|
|
|
|
1269
|
$self->{$name} = $default if defined $default; |
112
|
405
|
|
|
|
|
622
|
return; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _validate_mark_param |
116
|
|
|
|
|
|
|
{ |
117
|
213
|
|
|
213
|
|
317
|
my ($self) = @_; |
118
|
|
|
|
|
|
|
|
119
|
213
|
100
|
|
|
|
655
|
return unless exists $self->{mark}; |
120
|
|
|
|
|
|
|
|
121
|
84
|
100
|
|
|
|
475
|
croak "'mark' parameter must be an array reference.\n" |
122
|
|
|
|
|
|
|
unless 'ARRAY' eq ref $self->{mark}; |
123
|
83
|
|
|
|
|
582
|
croak "'mark' array parameter must have an even number of elements.\n" |
124
|
83
|
100
|
|
|
|
114
|
unless 0 == (@{$self->{mark}}%2); |
125
|
|
|
|
|
|
|
|
126
|
82
|
|
|
|
|
115
|
my @marks = @{$self->{mark}}; |
|
82
|
|
|
|
|
237
|
|
127
|
82
|
|
|
|
|
217
|
while(@marks) |
128
|
|
|
|
|
|
|
{ |
129
|
84
|
|
|
|
|
223
|
my ($index, $color) = splice( @marks, 0, 2 ); |
130
|
84
|
100
|
|
|
|
655
|
croak "'$index' is not a valid mark index.\n" |
131
|
|
|
|
|
|
|
unless $index =~ /^(?:first|last|high|low|\d+)$/; |
132
|
77
|
100
|
|
|
|
190
|
croak "'$color' is not a valid mark color.\n" |
133
|
|
|
|
|
|
|
unless _is_color( $color ); |
134
|
|
|
|
|
|
|
} |
135
|
74
|
|
|
|
|
138
|
return; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub _is_color |
139
|
|
|
|
|
|
|
{ |
140
|
314
|
|
|
314
|
|
15665
|
my ($color) = @_; |
141
|
314
|
100
|
|
|
|
1684
|
return 1 if $color =~ /^#[[:xdigit:]]{3}$/; |
142
|
101
|
100
|
|
|
|
311
|
return 1 if $color =~ /^#[[:xdigit:]]{6}$/; |
143
|
99
|
100
|
|
|
|
240
|
return 1 if $color =~ /^rgb\(\d+,\d+,\d+\)$/; |
144
|
98
|
100
|
|
|
|
210
|
return 1 if $color =~ /^rgb\(\d+%,\d+%,\d+%\)$/; |
145
|
97
|
100
|
|
|
|
886
|
return 1 if $color =~ /^[[:alpha:]]+$/; |
146
|
18
|
|
|
|
|
120
|
return; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |