| Chart-OFC2 documentation | Contained in the Chart-OFC2 distribution. |
Chart::OFC2::Extremes - OFC2 axis or chart extremes
use Chart::OFC2::Extremes;
has 'extremes' => (
is => 'rw',
isa => 'Chart::OFC2::Extremes',
default => sub { Chart::OFC2::Extremes->new() },
lazy => 1,
);
$self->extremes->reset();
has 'x_axis_max' => (is => 'rw', isa => 'Num|Undef', );
has 'x_axis_min' => (is => 'rw', isa => 'Num|Undef', );
has 'y_axis_max' => (is => 'rw', isa => 'Num|Undef', );
has 'y_axis_min' => (is => 'rw', isa => 'Num|Undef', );
has 'other' => (is => 'rw', isa => 'Num|Undef', );
Object constructor.
Calculate x or y minimal and maximal values and set (x|y)_axis_(min|max) according.
Returns HashRef that is possible to give to encode_json() function.
Jozef Kutej
| Chart-OFC2 documentation | Contained in the Chart-OFC2 distribution. |
package Chart::OFC2::Extremes;
use Moose; use Moose::Util::TypeConstraints; use MooseX::StrictConstructor; use Carp::Clan 'croak'; our $VERSION = '0.07'; coerce 'Chart::OFC2::Extremes' => from 'HashRef' => via { Chart::OFC2::Extremes->new($_) };
has 'x_axis_max' => (is => 'rw', isa => 'Num|Undef', ); has 'x_axis_min' => (is => 'rw', isa => 'Num|Undef', ); has 'y_axis_max' => (is => 'rw', isa => 'Num|Undef', ); has 'y_axis_min' => (is => 'rw', isa => 'Num|Undef', ); has 'other' => (is => 'rw', isa => 'Num|Undef', );
sub reset { my $self = shift; my $axis_type = shift; my $values = shift; croak 'pass axis type (x|y) argument' if (($axis_type ne 'y') and ($axis_type ne 'x')); croak 'pass values argument as array ref' if (ref $values ne 'ARRAY'); my $axis_min = $axis_type.'_axis_min'; my $axis_max = $axis_type.'_axis_max'; my $max; my $min; my @values_to_check = @{$values}; while (scalar @values_to_check) { my $value = shift @values_to_check; next if not defined $value; push @values_to_check, @{$value} if ref $value eq 'ARRAY'; next if ref $value ne ''; $max = $value if ((not defined $max) or ($value > $max)); $min = $value if ((not defined $min) or ($value < $min)); } $self->$axis_min($min) if defined $min; $self->$axis_max($max) if defined $max; }
sub TO_JSON { my $self = shift; return { 'x_axis_max' => $self->x_axis_max, 'x_axis_min' => $self->x_axis_min, 'y_axis_max' => $self->y_axis_max, 'y_axis_min' => $self->y_axis_min, 'other' => $self->other, }; } 1; __END__