Chart-OFC

 view release on metacpan or  search on metacpan

lib/Chart/OFC/AxisLabel.pm  view on Meta::CPAN

    ( is      => 'ro',
      isa     => 'Chart::OFC::Type::Size',
      default => 20,
    );

sub _ofc_data_lines
{
    my $self = shift;
    my $name = shift;

    return $self->_data_line( $name . '_legend', $self->label(), $self->text_size(), $self->text_color() );
}

no Moose;

__PACKAGE__->meta()->make_immutable();

1;


# ABSTRACT: A label for an axis

t/AxisLabel.t  view on Meta::CPAN

use Test::More tests => 4;

use Chart::OFC::AxisLabel;


eval { Chart::OFC::AxisLabel->new() };
like( $@, qr/\Q(label) is required/, 'label is required for constructor' );

{
    my $axis_label = Chart::OFC::AxisLabel->new( label => 'Months' );
    is( $axis_label->_ofc_data_lines('x'), '&x_legend=Months,20,#000000&',
        'data lines with defaults' );
}

{
    my $axis_label = Chart::OFC::AxisLabel->new( label => 'Months, With Year' );
    is( $axis_label->_ofc_data_lines('x'), '&x_legend=Months#comma# With Year,20,#000000&',
        'data lines with comma in label' );
}

{
    my $axis_label = Chart::OFC::AxisLabel->new( label      => 'Months',
                                                 text_color => 'red',
                                                 text_size  => 10,
                                               );
    is( $axis_label->_ofc_data_lines('x'), '&x_legend=Months,10,#FF0000&',
        'data lines with all attributes set' );
}

t/XAxis.t  view on Meta::CPAN



eval { Chart::OFC::XAxis->new() };
like( $@, qr/\Q(axis_label) is required/, 'axis_label is required for constructor' );

{
    my $axis_label = Chart::OFC::AxisLabel->new( label => 'Months' );

    my $axis = Chart::OFC::XAxis->new( axis_label => $axis_label );

    my @lines = ( '&x_legend=Months,20,#000000&',
                  '&x_label_style=10,#784016,0,1&',
                );
    is_deeply( [ $axis->_ofc_data_lines() ], \@lines,
               'data lines with defaults and label' );
}

{
    my $axis_label = Chart::OFC::AxisLabel->new( label      => 'Months',
                                                 text_color => 'red',
                                                 text_size  => 10,
                                               );

    my $axis = Chart::OFC::XAxis->new( axis_label => $axis_label );

    my @lines = ( '&x_legend=Months,10,#FF0000&',
                  '&x_label_style=10,#784016,0,1&',
                );
    is_deeply( [ $axis->_ofc_data_lines() ], \@lines,
               'data lines with all-params axis_label' );
}

{
    my $axis = Chart::OFC::XAxis->new( axis_label => 'Months' );

    my @lines = ( '&x_legend=Months,20,#000000&',
                  '&x_label_style=10,#784016,0,1&',
                );
    is_deeply( [ $axis->_ofc_data_lines() ], \@lines,
               'string -> axis_label coercion' );
}

{
    my $axis = Chart::OFC::XAxis->new( axis_label => { label => 'Months', text_size => 15 } );

    my @lines = ( '&x_legend=Months,15,#000000&',
                  '&x_label_style=10,#784016,0,1&',
                );
    is_deeply( [ $axis->_ofc_data_lines() ], \@lines,
               'hashref -> axis_label coercion' );
}

{
    my $axis =
        Chart::OFC::XAxis->new( axis_label     => 'Months',
                                axis_color     => 'blue',
                                label_steps    => 4,
                                tick_steps     => 2,
                                text_size      => 7,
                                text_color     => 'blue',
                                grid_color     => 'orange',
                                labels         => [ qw( jan feb mar apr may jun jul aug sep oct nov dec ) ],
                                three_d_height => 5,
                                orientation    => 'diagonal',
                              );

    my @lines = ( '&x_legend=Months,20,#000000&',
                  '&x_labels=jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec&',
                  '&x_label_style=7,#0000FF,2,4,#FFA500&',
                  '&x_ticks=2&',
                  '&x_axis_3d=5&',
                  '&x_axis_colour=#0000FF&',
                  '&x_axis_steps=2&',
                );
    is_deeply( [ $axis->_ofc_data_lines() ], \@lines,
               'x axis with all attributes set' );
}

t/YAxis.t  view on Meta::CPAN

like( $@, qr/\Q(max) is required/, 'max is required for constructor' );

{
    my $axis_label = Chart::OFC::AxisLabel->new( label => 'Size' );

    my $axis = Chart::OFC::YAxis->new( axis_label  => $axis_label,
                                       max         => 20,
                                       label_steps => 5,
                                     );

    my @lines = ( '&y_legend=Size,20,#000000&',
                  '&y_label_style=10,#784016&',
                  '&y_ticks=5,10,4&',
                  '&y_min=0&',
                  '&y_max=20&',
                );
    is_deeply( [ $axis->_ofc_data_lines() ], \@lines,
               'data lines with defaults and label-only axis_label' );
}

{

t/YAxis.t  view on Meta::CPAN

                                       min             => -9.5,
                                       max             => 20.5,
                                       small_tick_size => 2,
                                       large_tick_size => 20,
                                       label_steps     => 5,
                                       text_color      => 'blue',
                                       axis_color      => 'green',
                                       grid_color      => 'red',
                                     );

    my @lines = ( '&y_legend=Size,20,#000000&',
                  '&y_label_style=10,#0000FF&',
                  '&y_ticks=2,20,6&',
                  '&y_min=-9.5&',
                  '&y_max=20.5&',
                  '&y_axis_colour=#00FF00&',
                  '&y_grid_colour=#FF0000&',
                );
    is_deeply( [ $axis->_ofc_data_lines() ], \@lines,
               'data lines with all parameters' );
}



( run in 1.136 second using v1.01-cache-2.11-cpan-49f99fa48dc )