| VS-Chart documentation | Contained in the VS-Chart distribution. |
VS::Chart::Dataset - Carries data to be displayed in chart
Creates a new instance.
Returns an array reference of all data in the dataset.
Returns the maximum value in the dataset.
Returns the minimum value in the dataset.
Returns the number of items in the dataset.
Sets the contents of the row INDEX to VALUE. Rows start at 0.
Returns the value at row INDEX. Rows start at 0.
Sets attributes on the dataset such as color.
Returns the value for the requested attribute.
| VS-Chart documentation | Contained in the VS-Chart distribution. |
package VS::Chart::Dataset; use strict; use warnings; use Scalar::Util qw(refaddr); use List::Util qw(); my %Data; my %Attributes; sub new { my ($pkg) = @_; my $self = bless \do { my $v; }, $pkg; $$self = refaddr $self; $Data{$$self} = []; $Attributes{$$self} = {}; return $self; } sub set { my ($self, %attrs) = @_; my $id = refaddr $self; while (my ($key, $value) = each %attrs) { $Attributes{$id}->{$key} = $value; } } sub get { my ($self, $key) = @_; return $Attributes{refaddr $self}->{$key}; } sub max { my $self = shift; return List::Util::max grep { defined } @{$Data{$$self}}; } sub min { my $self = shift; return List::Util::min grep { defined } @{$Data{$$self}}; } sub length { my $self = shift; return scalar @{$Data{$$self}}; } sub insert { my ($self, $idx, $value) = @_; $Data{$$self}->[$idx] = $value; } sub value { my ($self, $idx) = @_; return $Data{$$self}->[$idx]; } sub data { my ($self) = @_; return $Data{$$self}; } sub DESTROY { my $self = shift; delete $Data{$$self}; } 1; __END__