Chart::Clicker::Decoration::Grid - Under-data grid


Chart-Clicker documentation Contained in the Chart-Clicker distribution.

Index


Code Index:

NAME

Top

Chart::Clicker::Decoration::Grid - Under-data grid

DESCRIPTION

Top

Generates a collection of Markers for use as a background.

SYNOPSIS

Top

ATTRIBUTES

Top

background_color

Set/Get the background_color for this Grid.

border

Set/Get the border for this Grid.

color

Set/Get the color for this Grid.

domain_brush

Set/Get the brush for inking the domain markers.

range_brush

Set/Get the brush for inking the range markers.

show_domain

Flag to show or not show the domain lines.

show_range

Flag to show or not show the range lines.

METHODS

Top

new

Creates a new Chart::Clicker::Decoration::Grid object.

draw_lines

Called by pack, draws the lines for a given axis.

pack

Prepare this Grid for drawing

stroke

Set/Get the Stroke for this Grid.

AUTHOR

Top

Cory G Watson <gphat@cpan.org>

SEE ALSO

Top

perl(1)

LICENSE

Top

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::Decoration::Grid;
use Moose;

extends 'Graphics::Primitive::Canvas';

with 'Graphics::Primitive::Oriented';

use Graphics::Color::RGB;

has '+background_color' => (
    default => sub {
        Graphics::Color::RGB->new(
            red => 0.9, green => 0.9, blue => 0.9, alpha => 1
        )
    }
);
has 'clicker' => ( is => 'rw', isa => 'Chart::Clicker' );
has 'domain_brush' => (
    is => 'rw',
    isa => 'Graphics::Primitive::Brush',
    default => sub {
        Graphics::Primitive::Brush->new(
            color => Graphics::Color::RGB->new(
                red => .75, green => .75, blue => .75, alpha => 1
            ),
            width => 1
        )
    }
);
has 'range_brush' => (
    is => 'rw',
    isa => 'Graphics::Primitive::Brush',
    default => sub {
        Graphics::Primitive::Brush->new(
            color => Graphics::Color::RGB->new(
                red => .75, green => .75, blue => .75, alpha => 1
            ),
            width => 1
        )
    }
);
has 'show_domain' => (
    is => 'rw',
    isa => 'Bool',
    default => 1
);
has 'show_range' => (
    is => 'rw',
    isa => 'Bool',
    default => 1
);

override('finalize', sub {
    my $self = shift();

    return unless ($self->show_domain || $self->show_range);

    my $clicker = $self->clicker;

    my $dflt = $clicker->get_context('default');
    my $daxis = $dflt->domain_axis;
    my $raxis = $dflt->range_axis;

    if($self->show_domain) {
        $self->draw_lines($daxis);
        my $dop = Graphics::Primitive::Operation::Stroke->new;
        $dop->brush($self->domain_brush);
        $self->do($dop);
    }

    if($self->show_range) {
        $self->draw_lines($raxis);
        my $rop = Graphics::Primitive::Operation::Stroke->new;
        $rop->brush($self->range_brush);
        $self->do($rop);
    }
});

sub draw_lines {
    my ($self, $axis) = @_;

    my $height = $self->height;
    my $width = $self->width;

    if($axis->is_horizontal) {

        foreach my $val (@{ $axis->tick_values }) {
            my $mark = $axis->mark($width, $val);
            # Don't try and draw a mark if the Axis wouldn't give us a value,
            # it might be skipping...
            next unless defined($mark);
            $self->move_to($mark, 0);
            $self->rel_line_to(0, $height);
        }
    } else {

        foreach my $val (@{ $axis->tick_values }) {
            my $mark = $axis->mark($height, $val);
            # Don't try and draw a mark if the Axis wouldn't give us a value,
            # it might be skipping...
            next unless defined($mark);
            $self->move_to(0, $height - $mark);
            $self->rel_line_to($width, 0);
        }
    }
}

__PACKAGE__->meta->make_immutable;

no Moose;

1;
__END__