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