| Chart-Clicker documentation | Contained in the Chart-Clicker distribution. |
Chart::Clicker::Data::DataSet - A collection of series
Chart::Clicker::Data::DataSet is a set of Series that are grouped for some logical reason or another. DatasSets can be associated with Renderers in the Chart. Unless you are doing something fancy like that you have no reason to use more than one in your chart.
use Chart::Clicker::Data::DataSet;
use Chart::Clicker::Data::Series;
my @vals = (12, 19, 90, 4, 44, 3, 78, 87, 19, 5);
my @keys = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
my $series = Chart::Clicker::Data::Series->new({
keys => \@keys,
values => \@values
});
my $ds = Chart::Clicker::Data::DataSet->new({
series => [ $series ]
});
Set/Get the context this DataSet will be charted under.
Get the Range for the domain values
Get the number of keys in the longest series.
Get the Range for the... range values...
Set/Get the series for this DataSet
Creates a new, empty DataSet
Add a series to this dataset.
Get the number of series in this dataset.
Returns an array of keys representing the union of all keys from all DataSets.
Returns the key at the specified position for every series in this DataSet.
Returns the value at the specified position for every series in this DataSet.
Finds the largest cumulative 'slice' in this dataset.
Prepare this DataSet.
Cory G Watson <gphat@cpan.org>
You can redistribute and/or modify this code under the same terms as Perl itself.
| Chart-Clicker documentation | Contained in the Chart-Clicker distribution. |
package Chart::Clicker::Data::DataSet; use Moose; use Chart::Clicker::Data::Range; has 'context' => ( is => 'rw', isa => 'Str', default => sub { 'default'} ); has 'domain' => ( is => 'rw', isa => 'Chart::Clicker::Data::Range', default => sub { Chart::Clicker::Data::Range->new } ); has 'max_key_count' => ( is => 'rw', isa => 'Int', default => 0 ); has 'range' => ( is => 'rw', isa => 'Chart::Clicker::Data::Range', default => sub { Chart::Clicker::Data::Range->new } ); has 'series' => ( traits => [ 'Array' ], is => 'rw', isa => 'ArrayRef', default => sub { [] }, handles => { 'count' => 'count', 'add_to_series' => 'push', 'get_series' => 'get' } ); sub get_all_series_keys { my ($self) = @_; my %keys; for my $series (@{$self->series}) { foreach (@{$series->keys}) { $keys{$_} = 1}; } return keys %keys; } sub get_series_keys { my ($self, $position) = @_; return map({ $_->keys->[$position] } @{ $self->series }); } sub get_series_values { my ($self, $position) = @_; return map({ $_->values->[$position] } @{ $self->series }); } sub largest_value_slice { my ($self) = @_; # Prime out big variable with the value of the first slice my $big; foreach ($self->get_series_values(0)) { $big += $_; } # Check that value against all the remaining slices for my $i (0 .. $self->max_key_count - 1) { my $t; foreach ($self->get_series_values($i)) { $t += $_ if defined($_); } $big = $t if(($t > $big) || !defined($big)); } return $big; } sub prepare { my ($self) = @_; unless($self->count && $self->count > 0) { die('Dataset has no series.'); } my $stotal; foreach my $series (@{ $self->series }) { $series->prepare; $self->range->combine($series->range); my @keys = @{ $series->keys }; $self->domain->combine( Chart::Clicker::Data::Range->new({ lower => $keys[0], upper => $keys[ $#keys ] }) ); if($series->key_count > $self->max_key_count) { $self->max_key_count($series->key_count); } } return 1; } __PACKAGE__->meta->make_immutable; no Moose; 1; __END__