1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
package Chart::Clicker::Renderer::Point;
$Chart::Clicker::Renderer::Point::VERSION = '2.90';
use Moose;
# ABSTRACT: Point renderer
extends 'Chart::Clicker::Renderer';
use Geometry::Primitive::Circle;
use Geometry::Primitive::Point;
use Graphics::Primitive::Operation::Fill;
use Graphics::Primitive::Paint::Solid;
has 'shape' => (
is => 'rw',
does => 'Geometry::Primitive::Shape',
default => sub {
Geometry::Primitive::Circle->new({
radius => 3,
});
}
);
has 'shape_brush' => (
is => 'rw',
isa => 'Graphics::Primitive::Brush',
);
override('finalize', sub {
my ($self) = @_;
my $clicker = $self->clicker;
my $width = $self->width;
my $height = $self->height;
my $dses = $clicker->get_datasets_for_context($self->context);
foreach my $ds (@{ $dses }) {
foreach my $series (@{ $ds->series }) {
# TODO if undef...
my $ctx = $clicker->get_context($ds->context);
my $domain = $ctx->domain_axis;
my $range = $ctx->range_axis;
my $min = $range->range->lower;
my @vals = @{ $series->values };
my @keys = @{ $series->keys };
for(0..($series->key_count - 1)) {
my $x = $domain->mark($width, $keys[$_]);
next unless defined($x);
my $ymark = $range->mark($height, $vals[$_]);
next unless defined($ymark);
my $y = $height - $ymark;
$self->move_to($x, $y);
$self->draw_point($x, $y, $series, $_);
}
my $op = Graphics::Primitive::Operation::Fill->new(
paint => Graphics::Primitive::Paint::Solid->new(
color => $clicker->color_allocator->next
)
);
if(defined($self->shape_brush)) {
$op->preserve(1);
}
$self->do($op);
if(defined($self->shape_brush)) {
my $op3 = Graphics::Primitive::Operation::Stroke->new;
$op3->brush($self->shape_brush->clone);
$self->do($op3);
}
}
}
return 1;
});
sub draw_point {
my ($self, $x, $y, $series, $count) = @_;
my $shape = $self->shape->clone;
$shape->origin(Geometry::Primitive::Point->new(x => $x, y => $y));
$self->path->add_primitive($shape);
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
__END__
=pod
=head1 NAME
Chart::Clicker::Renderer::Point - Point renderer
=head1 VERSION
version 2.90
=head1 SYNOPSIS
my $pr = Chart::Clicker::Renderer::Point->new({
shape => Geometry::Primitive::Arc->new({
angle1 => 0,
angle2 => 180,
radius => 5
})
});
=head1 DESCRIPTION
Chart::Clicker::Renderer::Point renders a dataset as points.
=for HTML <p><img src="http://gphat.github.com/chart-clicker/static/images/examples/point.png" width="500" height="250" alt="Point Chart" /></p>
=head1 ATTRIBUTES
=head2 shape
Specify the L<shape|Geometry::Primitive::Shape> to be used at each point. Defaults to 360 degree arc with
a radius of 3.
=head2 shape_brush
Optionally provide a L<brush|Graphics::Primitive::Brush> with with to stroke each point.
=head1 METHODS
=head2 draw_point
Called for each point. Implemented as a separate method so that subclasses
such as Bubble may override the drawing.
=head1 AUTHOR
Cory G Watson <gphat@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by Cory G Watson.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|