line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Chart::Clicker::Data::Series; |
2
|
|
|
|
|
|
|
$Chart::Clicker::Data::Series::VERSION = '2.90'; |
3
|
11
|
|
|
11
|
|
412870
|
use Moose; |
|
11
|
|
|
|
|
2697764
|
|
|
11
|
|
|
|
|
83
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: A series of key, value pairs representing chart data |
6
|
|
|
|
|
|
|
|
7
|
11
|
|
|
11
|
|
72643
|
use List::Util qw(max min); |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
1134
|
|
8
|
11
|
|
|
11
|
|
5621
|
use Chart::Clicker::Data::Range; |
|
11
|
|
|
|
|
35
|
|
|
11
|
|
|
|
|
7071
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'keys' => ( |
12
|
|
|
|
|
|
|
traits => [ 'Array' ], |
13
|
|
|
|
|
|
|
is => 'rw', |
14
|
|
|
|
|
|
|
isa => 'ArrayRef[Num]', |
15
|
|
|
|
|
|
|
default => sub { [] }, |
16
|
|
|
|
|
|
|
handles => { |
17
|
|
|
|
|
|
|
'add_to_keys' => 'push', |
18
|
|
|
|
|
|
|
'key_count' => 'count' |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'name' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => 'Str', |
26
|
|
|
|
|
|
|
predicate => 'has_name' |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has 'range' => ( |
31
|
|
|
|
|
|
|
is => 'rw', |
32
|
|
|
|
|
|
|
isa => 'Chart::Clicker::Data::Range', |
33
|
|
|
|
|
|
|
lazy_build => 1 |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has 'values' => ( |
38
|
|
|
|
|
|
|
traits => [ 'Array' ], |
39
|
|
|
|
|
|
|
is => 'rw', |
40
|
|
|
|
|
|
|
isa => 'ArrayRef[Num|Undef]', |
41
|
|
|
|
|
|
|
default => sub { [] }, |
42
|
|
|
|
|
|
|
handles => { |
43
|
|
|
|
|
|
|
'add_to_values' => 'push', |
44
|
|
|
|
|
|
|
'value_count' => 'count' |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _build_range { |
49
|
5
|
|
|
5
|
|
7
|
my ($self) = @_; |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
195
|
my $values = $self->values; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
confess('A series must have values before it can be charted') |
54
|
5
|
100
|
|
|
|
7
|
unless scalar(@{ $values }); |
|
5
|
|
|
|
|
198
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return Chart::Clicker::Data::Range->new( |
57
|
13
|
|
|
|
|
53
|
lower => min(grep { defined } @{ $values }), |
|
4
|
|
|
|
|
11
|
|
58
|
4
|
|
|
|
|
9
|
upper => max(grep { defined } @{ $values }) |
|
13
|
|
|
|
|
198
|
|
|
4
|
|
|
|
|
10
|
|
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub BUILDARGS { |
63
|
21
|
|
|
21
|
1
|
55
|
my ($class, @args) = @_; |
64
|
|
|
|
|
|
|
|
65
|
21
|
100
|
66
|
|
|
173
|
if(@args == 1 && (ref($args[0]) eq 'HASH') && !exists($args[0]->{keys})) { |
|
|
100
|
100
|
|
|
|
|
66
|
1
|
|
|
|
|
3
|
my @keys = sort { $a <=> $b } keys %{ $args[0] }; |
|
4
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
6
|
|
67
|
1
|
|
|
|
|
2
|
my @values = (); |
68
|
1
|
|
|
|
|
3
|
foreach my $k (@keys) { |
69
|
4
|
|
|
|
|
6
|
push(@values, $args[0]->{$k}) |
70
|
|
|
|
|
|
|
} |
71
|
1
|
|
|
|
|
32
|
return { keys => \@keys, values => \@values } |
72
|
|
|
|
|
|
|
} elsif(@args % 2 == 0) { |
73
|
17
|
|
|
|
|
618
|
return { @args }; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
3
|
|
|
|
|
90
|
return $args[0]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub add_pair { |
81
|
0
|
|
|
0
|
1
|
0
|
my ($self, $key, $value) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
$self->add_to_keys($key); |
84
|
0
|
|
|
|
|
0
|
$self->add_to_values($value); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get_value_for_key { |
89
|
5
|
|
|
5
|
1
|
11
|
my ($self, $key) = @_; |
90
|
|
|
|
|
|
|
|
91
|
5
|
|
|
|
|
180
|
for(0..$self->key_count) { |
92
|
11
|
|
|
|
|
299
|
my $ikey = $self->keys->[$_]; |
93
|
11
|
100
|
100
|
|
|
158
|
return $self->values->[$_] if defined($ikey) && $ikey == $key; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# We found nothing, return undef |
97
|
1
|
|
|
|
|
6
|
return undef; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub prepare { |
101
|
6
|
|
|
6
|
0
|
3322
|
my ($self) = @_; |
102
|
|
|
|
|
|
|
|
103
|
6
|
100
|
|
|
|
313
|
if($self->key_count != $self->value_count) { |
104
|
1
|
|
|
|
|
36
|
die('Series key/value counts dont match: '.$self->key_count.' != '.$self->value_count.'.'); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
5
|
|
|
|
|
14
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
111
|
|
|
|
|
|
|
|
112
|
11
|
|
|
11
|
|
132
|
no Moose; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
86
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=pod |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 NAME |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Chart::Clicker::Data::Series - A series of key, value pairs representing chart data |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 VERSION |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
version 2.90 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SYNOPSIS |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
use Chart::Clicker::Data::Series; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my @keys = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); |
133
|
|
|
|
|
|
|
my @values = (42, 25, 86, 23, 2, 19, 103, 12, 54, 9); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $series = Chart::Clicker::Data::Series->new({ |
136
|
|
|
|
|
|
|
keys => \@keys, |
137
|
|
|
|
|
|
|
value => \@values |
138
|
|
|
|
|
|
|
}); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Alternately, if you prefer |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $series2 = Chart::Clicker::Data::Series->new({ |
143
|
|
|
|
|
|
|
1 => 42, |
144
|
|
|
|
|
|
|
2 => 25, |
145
|
|
|
|
|
|
|
3 => 85, |
146
|
|
|
|
|
|
|
4 => 23, |
147
|
|
|
|
|
|
|
5 => 2, |
148
|
|
|
|
|
|
|
6 => 19, |
149
|
|
|
|
|
|
|
7 => 102, |
150
|
|
|
|
|
|
|
8 => 12, |
151
|
|
|
|
|
|
|
9 => 54, |
152
|
|
|
|
|
|
|
10 => 9 |
153
|
|
|
|
|
|
|
}); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 DESCRIPTION |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Chart::Clicker::Data::Series represents a series of values to be charted. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Despite the name (keys and values) it is expected that all keys and values |
160
|
|
|
|
|
|
|
will be numeric. Values is pretty obvious, but it is important that keys |
161
|
|
|
|
|
|
|
also be numeric, as otherwise we'd have no idea how to order the data. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
If you want to use text labels for your domain's see L<Chart::Clicker::Axis>'s |
164
|
|
|
|
|
|
|
L<tick_labels> method. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 keys |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Set/Get the keys for this series. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 add_to_keys |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Adds a key to this series. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 name |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Set/Get the name for this Series |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 range |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Returns the L<range|Chart::Clicker::Data::Range> for this series. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 values |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Set/Get the values for this series. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 METHODS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 key_count |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Get the count of keys in this series. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 add_to_values |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Add a value to this series. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 value_count |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Get the count of values in this series. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 add_pair ($key, $value) |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Convenience method to add a single key and a single value to the series. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 get_value_for_key ($key) |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Returns the value associated with the specified key. This is necessary |
209
|
|
|
|
|
|
|
because not all series will have values for every key. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 AUTHOR |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Cory G Watson <gphat@cpan.org> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Cory G Watson. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
220
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=cut |