| Chart-Clicker documentation | Contained in the Chart-Clicker distribution. |
Chart::Clicker::Decoration::Grid - Under-data grid
Generates a collection of Markers for use as a background.
Set/Get the background_color for this Grid.
Set/Get the border for this Grid.
Set/Get the color for this Grid.
Set/Get the brush for inking the domain markers.
Set/Get the brush for inking the range markers.
Flag to show or not show the domain lines.
Flag to show or not show the range lines.
Creates a new Chart::Clicker::Decoration::Grid object.
Called by pack, draws the lines for a given axis.
Prepare this Grid for drawing
Set/Get the Stroke for this Grid.
Cory G Watson <gphat@cpan.org>
perl(1)
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__