| 1 | package Chart::Clicker::Data::DataSet; | ||||||||||||||||||||||||||||
| 2 | 8 | $Chart::Clicker::Data::DataSet::VERSION = '2.89'; | |||||||||||||||||||||||||||
| 3 | 8 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: A collection of series | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Chart::Clicker::Data::Range; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 8 | has 'context' => ( | |||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||
| 12 | isa => 'Str', | ||||||||||||||||||||||||||||
| 13 | default => 'default' | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | has 'domain' => ( | ||||||||||||||||||||||||||||
| 18 | is => 'rw', | ||||||||||||||||||||||||||||
| 19 | isa => 'Chart::Clicker::Data::Range', | ||||||||||||||||||||||||||||
| 20 | 9 | ▶ | default => sub { Chart::Clicker::Data::Range->new } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 8 | ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 8 | has 'max_key_count' => ( is => 'rw', isa => 'Int', default => 0 ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | has 'range' => ( | ||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||
| 29 | isa => 'Chart::Clicker::Data::Range', | ||||||||||||||||||||||||||||
| 30 | 9 | ▶ | default => sub { Chart::Clicker::Data::Range->new } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 8 | ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | has 'series' => ( | ||||||||||||||||||||||||||||
| 35 | traits => [ 'Array' ], | ||||||||||||||||||||||||||||
| 36 | is => 'rw', | ||||||||||||||||||||||||||||
| 37 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 38 | 2 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 8 | handles => { | |||||||||||||||||||||||||||
| 40 | 'count' => 'count', | ||||||||||||||||||||||||||||
| 41 | 'add_to_series' => 'push', | ||||||||||||||||||||||||||||
| 42 | 'get_series' => 'get' | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub get_all_series_keys { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_all_series_keys: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my %keys; | |||||||||||||||||||||||||||
| 51 | 0 | for my $series (@{$self->series}) { | |||||||||||||||||||||||||||
| 52 | 0 | foreach (@{$series->keys}) { $keys{$_} = 1}; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | return keys %keys; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub get_series_keys { | ||||||||||||||||||||||||||||
| 59 | 1 | ▶ | my ($self, $position) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_series_keys: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | return map({ $_->keys->[$position] } @{ $self->series }); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub get_series_values { | ||||||||||||||||||||||||||||
| 66 | 5 | ▶ | my ($self, $position) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_series_values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | return [ map({ $_->values->[$position] } @{ $self->series }) ]; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub get_series_values_for_key { | ||||||||||||||||||||||||||||
| 73 | 2 | ▶ | my ($self, $key) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_series_values_for_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | return [ map({ $_->get_value_for_key($key) } @{ $self->series }) ]; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub largest_value_slice { | ||||||||||||||||||||||||||||
| 80 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
largest_value_slice: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # Prime out big variable with the value of the first slice | ||||||||||||||||||||||||||||
| 83 | 1 | my $big; | |||||||||||||||||||||||||||
| 84 | 1 | foreach (@{ $self->get_series_values(0) }) { $big += $_; } | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # Check that value against all the remaining slices | ||||||||||||||||||||||||||||
| 87 | 1 | for my $i (0 .. $self->max_key_count - 1) { | |||||||||||||||||||||||||||
| 88 | 3 | my $t; | |||||||||||||||||||||||||||
| 89 | 3 | ▶ | foreach (@{ $self->get_series_values($i) }) { $t += $_ if defined($_); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 3 | ▶ | $big = $t if(($t > $big) || !defined($big)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t > $big or not defined $big
MC/DC50%1/2
$t > $big or not defined $big
$t > $big
not defined $big
Truth table66%2/3
A or not(B)
A= $t > $bigB= not defined $big
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 1 | return $big; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub prepare { | ||||||||||||||||||||||||||||
| 96 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | unless($self->count && $self->count > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->count and $self->count > 0
MC/DC50%1/2
$self->count and $self->count > 0
$self->count
$self->count > 0
Truth table66%2/3
A and B
A= $self->countB= $self->count > 0
| |||||||||||||||||||||||||||||
| 99 | 1 | die('Dataset has no series.'); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | foreach my $series (@{ $self->series }) { | |||||||||||||||||||||||||||
| 103 | 2 | $series->prepare; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | $self->range->combine($series->range); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | my @keys = @{ $series->keys }; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | $self->domain->combine( | |||||||||||||||||||||||||||
| 110 | Chart::Clicker::Data::Range->new({ | ||||||||||||||||||||||||||||
| 111 | lower => $keys[0], upper => $keys[ $#keys ] | ||||||||||||||||||||||||||||
| 112 | }) | ||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 2 | ▶ | if($series->key_count > $self->max_key_count) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | $self->max_key_count($series->key_count); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | return 1; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 8 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 8 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 8 | 1; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =pod | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head1 NAME | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | Chart::Clicker::Data::DataSet - A collection of series | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =head1 VERSION | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | version 2.89 | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | use Chart::Clicker::Data::DataSet; | ||||||||||||||||||||||||||||
| 144 | use Chart::Clicker::Data::Series; | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | my @vals = (12, 19, 90, 4, 44, 3, 78, 87, 19, 5); | ||||||||||||||||||||||||||||
| 147 | my @keys = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||||||||||||||||||||||||||||
| 148 | my $series = Chart::Clicker::Data::Series->new({ | ||||||||||||||||||||||||||||
| 149 | keys => \@keys, | ||||||||||||||||||||||||||||
| 150 | values => \@vals | ||||||||||||||||||||||||||||
| 151 | }); | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | my $ds = Chart::Clicker::Data::DataSet->new({ | ||||||||||||||||||||||||||||
| 154 | series => [ $series ] | ||||||||||||||||||||||||||||
| 155 | }); | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | Chart::Clicker::Data::DataSet is a set of Series that are grouped for some | ||||||||||||||||||||||||||||
| 160 | logical reason or another. DatasSets can be associated with Renderers in the | ||||||||||||||||||||||||||||
| 161 | Chart. Unless you are doing something fancy like that you have no reason to | ||||||||||||||||||||||||||||
| 162 | use more than one in your chart. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head2 max_key_count | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | Get the number of keys in the longest series. This will be set automatically. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =head2 context | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Set/Get the context this DataSet will be charted under. | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head2 domain | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | Get the L<Range|Chart::Clicker::Data::Range> for the domain values | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =head2 range | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | Get the L<Range|Chart::Clicker::Data::Range> for the... range values... | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =head2 series | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | Set/Get the series for this DataSet | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head1 METHODS | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =head2 add_to_series | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | Add a series to this dataset. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =head2 count | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | Get the number of series in this dataset. | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =head2 get_series ($index) | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | Get the series at the specified index. | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =head2 get_all_series_keys | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | Returns an array of keys representing the union of all keys from all DataSets. | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =head2 get_series_keys | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | Returns the key at the specified position for every series in this DataSet. | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =head2 get_series_values | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | Returns the value at the specified position for every series in this DataSet | ||||||||||||||||||||||||||||
| 211 | as an ArrayRef. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =head2 get_series_values_for_key | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | Returns the value for the specified key for every series in this DataSet as an | ||||||||||||||||||||||||||||
| 216 | ArrayRef. | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =head2 largest_value_slice | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | Finds the largest cumulative 'slice' in this dataset. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | Cory G Watson <gphat@cpan.org> | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | This software is copyright (c) 2016 by Cory G Watson. | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 231 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||||||||||