| 1 | package Chart::Clicker::Renderer::Area; | ||||||||||||||
| 2 | 1 | $Chart::Clicker::Renderer::Area::VERSION = '2.90'; | |||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 1 | extends 'Chart::Clicker::Renderer'; | |||||||||||||
| 6 | |||||||||||||||
| 7 | # ABSTRACT: Area renderer | ||||||||||||||
| 8 | |||||||||||||||
| 9 | 1 | ▶ | use Graphics::Primitive::Brush; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use Graphics::Primitive::Path; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Graphics::Primitive::Operation::Fill; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use Graphics::Primitive::Operation::Stroke; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | ▶ | use Graphics::Primitive::Paint::Gradient::Linear; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 1 | ▶ | use Graphics::Primitive::Paint::Solid; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | |||||||||||||||
| 17 | has 'brush' => ( | ||||||||||||||
| 18 | is => 'rw', | ||||||||||||||
| 19 | isa => 'Graphics::Primitive::Brush', | ||||||||||||||
| 20 | 1 | ▶ | default => sub { Graphics::Primitive::Brush->new } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | 1 | ); | |||||||||||||
| 22 | |||||||||||||||
| 23 | |||||||||||||||
| 24 | 1 | has 'fade' => ( | |||||||||||||
| 25 | is => 'rw', | ||||||||||||||
| 26 | isa => 'Bool', | ||||||||||||||
| 27 | default => 0 | ||||||||||||||
| 28 | ); | ||||||||||||||
| 29 | |||||||||||||||
| 30 | |||||||||||||||
| 31 | 1 | has 'opacity' => ( | |||||||||||||
| 32 | is => 'rw', | ||||||||||||||
| 33 | isa => 'Num', | ||||||||||||||
| 34 | default => 0 | ||||||||||||||
| 35 | ); | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 0 | ▶ | override('finalize', sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||
| 38 | 0 | my ($self) = @_; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | my $height = $self->height; | |||||||||||||
| 41 | 0 | my $width = $self->width; | |||||||||||||
| 42 | 0 | my $clicker = $self->clicker; | |||||||||||||
| 43 | |||||||||||||||
| 44 | 0 | my $dses = $clicker->get_datasets_for_context($self->context); | |||||||||||||
| 45 | 0 | foreach my $ds (@{ $dses }) { | |||||||||||||
| 46 | 0 | foreach my $series (@{ $ds->series }) { | |||||||||||||
| 47 | |||||||||||||||
| 48 | # TODO if undef... | ||||||||||||||
| 49 | 0 | my $ctx = $clicker->get_context($ds->context); | |||||||||||||
| 50 | 0 | my $domain = $ctx->domain_axis; | |||||||||||||
| 51 | 0 | my $range = $ctx->range_axis; | |||||||||||||
| 52 | |||||||||||||||
| 53 | 0 | my $lastx; # used for completing the path | |||||||||||||
| 54 | 0 | my @vals = @{ $series->values }; | |||||||||||||
| 55 | 0 | my @keys = @{ $series->keys }; | |||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | my $startx; | |||||||||||||
| 58 | |||||||||||||||
| 59 | my $biggest; | ||||||||||||||
| 60 | 0 | for(0..($series->key_count - 1)) { | |||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | my $x = $domain->mark($width, $keys[$_]); | |||||||||||||
| 63 | 0 | ▶ | next unless defined($x); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | |||||||||||||||
| 65 | 0 | my $ymark = $range->mark($height, $vals[$_]); | |||||||||||||
| 66 | 0 | ▶ | next unless defined($ymark); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 0 | my $y = $height - $ymark; | |||||||||||||
| 68 | |||||||||||||||
| 69 | 0 | ▶ | if(defined($biggest)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | 0 | ▶ | $biggest = $y if $y > $biggest; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | } else { | ||||||||||||||
| 72 | 0 | $biggest = $y; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 0 | ▶ | if($_ == 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 0 | $startx = $x; | |||||||||||||
| 77 | 0 | $self->move_to($x, $y); | |||||||||||||
| 78 | } else { | ||||||||||||||
| 79 | 0 | $self->line_to($x, $y); | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | 0 | $lastx = $x; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | 0 | my $color = $self->clicker->color_allocator->next; | |||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | my $op = Graphics::Primitive::Operation::Stroke->new; | |||||||||||||
| 86 | 0 | $op->preserve(1); | |||||||||||||
| 87 | 0 | $op->brush($self->brush->clone); | |||||||||||||
| 88 | 0 | $op->brush->color($color); | |||||||||||||
| 89 | |||||||||||||||
| 90 | 0 | $self->do($op); | |||||||||||||
| 91 | |||||||||||||||
| 92 | 0 | $self->line_to($lastx, $height); | |||||||||||||
| 93 | 0 | $self->line_to($startx, $height); | |||||||||||||
| 94 | 0 | $self->close_path; | |||||||||||||
| 95 | |||||||||||||||
| 96 | 0 | my $paint; | |||||||||||||
| 97 | 0 | ▶ | if($self->opacity) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 98 | |||||||||||||||
| 99 | 0 | my $clone = $color->clone; | |||||||||||||
| 100 | 0 | $clone->alpha($self->opacity); | |||||||||||||
| 101 | 0 | $paint = Graphics::Primitive::Paint::Solid->new( | |||||||||||||
| 102 | color => $clone | ||||||||||||||
| 103 | ); | ||||||||||||||
| 104 | } elsif($self->fade) { | ||||||||||||||
| 105 | |||||||||||||||
| 106 | 0 | my $clone = $color->clone; | |||||||||||||
| 107 | 0 | $clone->alpha($self->opacity); | |||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | $paint = Graphics::Primitive::Paint::Gradient::Linear->new( | |||||||||||||
| 110 | line => Geometry::Primitive::Line->new( | ||||||||||||||
| 111 | start => Geometry::Primitive::Point->new(x => 0, y => 0), | ||||||||||||||
| 112 | end => Geometry::Primitive::Point->new(x => 1, y => $biggest), | ||||||||||||||
| 113 | ), | ||||||||||||||
| 114 | style => 'linear' | ||||||||||||||
| 115 | ); | ||||||||||||||
| 116 | 0 | $paint->add_stop(1.0, $color); | |||||||||||||
| 117 | 0 | $paint->add_stop(0, $clone); | |||||||||||||
| 118 | } else { | ||||||||||||||
| 119 | |||||||||||||||
| 120 | 0 | $paint = Graphics::Primitive::Paint::Solid->new( | |||||||||||||
| 121 | color => $color->clone | ||||||||||||||
| 122 | ); | ||||||||||||||
| 123 | } | ||||||||||||||
| 124 | 0 | my $fillop = Graphics::Primitive::Operation::Fill->new( | |||||||||||||
| 125 | paint => $paint | ||||||||||||||
| 126 | ); | ||||||||||||||
| 127 | |||||||||||||||
| 128 | 0 | $self->do($fillop); | |||||||||||||
| 129 | } | ||||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | 0 | return 1; | |||||||||||||
| 133 | 1 | }); | |||||||||||||
| 134 | |||||||||||||||
| 135 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 136 | |||||||||||||||
| 137 | 1 | ▶ | no Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 138 | |||||||||||||||
| 139 | 1 | 1; | |||||||||||||
| 140 | |||||||||||||||
| 141 | __END__ | ||||||||||||||