| 1 | package Chart::Clicker::Renderer::Line; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | $Chart::Clicker::Renderer::Line::VERSION = '2.90'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Line renderer | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | extends 'Chart::Clicker::Renderer'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use Geometry::Primitive::Point; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Graphics::Primitive::Brush; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Graphics::Primitive::Operation::Stroke; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Geometry::Primitive::Circle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | #number of defined points we must have around another point | ||||||||||||||||||||||||||||||||||||||||||
| 15 | #to render a line instead of a scatter | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use constant MIN_DEFINED_SURROUNDING_POINTS => 5; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | has 'brush' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | isa => 'Graphics::Primitive::Brush', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | ▶ | default => sub { Graphics::Primitive::Brush->new(width => 2) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | has 'shape' => ( | |||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | isa => 'Geometry::Primitive::Shape', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | has 'shape_brush' => ( | |||||||||||||||||||||||||||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | isa => 'Graphics::Primitive::Brush', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # TODO Readd shapes | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub finalize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finalize: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $width = $self->width; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $height = $self->height; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $clicker = $self->clicker; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $dses = $clicker->get_datasets_for_context($self->context); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my %accum; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | foreach my $ds (@{ $dses }) { | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | foreach my $series (@{ $ds->series }) { | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # TODO if undef... | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $ctx = $clicker->get_context($ds->context); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $domain = $ctx->domain_axis; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $range = $ctx->range_axis; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $color = $clicker->color_allocator->next; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my @vals = @{ $series->values }; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my @keys = @{ $series->keys }; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $kcount = $series->key_count - 1; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $skip = 0; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $previous_x = -1; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $previous_y = -1; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $min_y_delta_on_same_x = $height / 100; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | for(0..$kcount) { | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $key = $keys[$_]; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $x = $domain->mark($width, $key); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | next unless defined($x); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $skip = 1 unless defined $vals[$_]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $ymark = $range->mark($height, $vals[$_]); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | next unless defined($ymark); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if($self->additive) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if(exists($accum{$key})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $accum{$key} += $ymark; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $ymark = $accum{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $accum{$key} = $ymark; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $y = $height - $ymark; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if( $_ == 0 || $skip ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ == 0 or $skip
MC/DC0%0/2
$_ == 0 or $skip
$_ == 0
$skip
Truth table0%0/3
A or B
A= $_ == 0B= $skip
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $lineop = Graphics::Primitive::Operation::Stroke->new( | |||||||||||||||||||||||||||||||||||||||||
| 91 | brush => $self->brush->clone | ||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $lineop->brush->color($color); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->do($lineop); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->move_to($x, $y); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $start_new_line = 1; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | foreach my $i ($_..($_ + MIN_DEFINED_SURROUNDING_POINTS)) { | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($i > 0 && $i < @vals && !defined($vals[$i])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$i > 0 and $i < @vals and not defined $vals[$i]
$i > 0 and $i < @vals
MC/DC0%0/3
$i > 0 and $i < @vals and not defined $vals[$i]
$i > 0
$i < @vals
not defined $vals[$i]
Truth table0%0/4
A and B and not(C)
A= $i > 0B= $i < @valsC= not defined $vals[$i]
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $start_new_line = 0; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($start_new_line){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $skip = 0; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $shape = Geometry::Primitive::Circle->new(radius => 3); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $shape->origin(Geometry::Primitive::Point->new(x => $x, y => $y)); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->path->add_primitive($shape); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $fill = Graphics::Primitive::Operation::Fill->new( | |||||||||||||||||||||||||||||||||||||||||
| 110 | paint => Graphics::Primitive::Paint::Solid->new( | ||||||||||||||||||||||||||||||||||||||||||
| 111 | color => $color | ||||||||||||||||||||||||||||||||||||||||||
| 112 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $self->do($fill); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # when in fast mode, we plot only if we moved by more than | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # 1 of a pixel on the X axis or we moved by more than 1% | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # of the size of the Y axis. | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if( $clicker->plot_mode ne 'fast' || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$clicker->plot_mode ne "fast" or $x - $previous_x > 1 or abs $y - $previous_y > $min_y_delta_on_same_x
$clicker->plot_mode ne "fast" or $x - $previous_x > 1
MC/DC0%0/3
$clicker->plot_mode ne "fast" or $x - $previous_x > 1 or abs $y - $previous_y > $min_y_delta_on_same_x
$clicker->plot_mode ne "fast"
$x - $previous_x > 1
abs $y - $previous_y > $min_y_delta_on_same_x
Truth table0%0/4
A or B or C
A= $clicker->plot_mode ne "fast"B= $x - $previous_x > 1C= abs $y - $previous_y > $min_y_delta_on_same_x
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | $x - $previous_x > 1 || | ||||||||||||||||||||||||||||||||||||||||||
| 123 | abs($y - $previous_y) > $min_y_delta_on_same_x | ||||||||||||||||||||||||||||||||||||||||||
| 124 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->line_to($x, $y); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $previous_x = $x; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $previous_y = $y; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $op = Graphics::Primitive::Operation::Stroke->new; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $op->brush($self->brush->clone); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $op->brush->color($color); | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $self->do($op); | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if(defined($self->shape)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | for(0..$kcount) { | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $key = $keys[$_]; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $x = $domain->mark($width, $key); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | next unless defined($x); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $ymark = $range->mark($height, $vals[$_]); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | next unless defined($ymark); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if($self->additive) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if(exists($accum{$key})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $ymark = $accum{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $accum{$key} = $ymark; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $y = $height - $ymark; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $self->move_to($x, $y); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $self->draw_point($x, $y, $series, $vals[$_]); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | # Fill the shape | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $op2 = Graphics::Primitive::Operation::Fill->new( | |||||||||||||||||||||||||||||||||||||||||
| 162 | paint => Graphics::Primitive::Paint::Solid->new( | ||||||||||||||||||||||||||||||||||||||||||
| 163 | color => $color | ||||||||||||||||||||||||||||||||||||||||||
| 164 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 165 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if(defined($self->shape_brush)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $op2->preserve(1); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $self->do($op2); | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | # Optionally stroke the shape | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if(defined($self->shape_brush)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $op3 = Graphics::Primitive::Operation::Stroke->new; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $op3->brush($self->shape_brush->clone); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $self->do($op3); | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub draw_point { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
draw_point: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my ($self, $x, $y, $series, $count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $shape = $self->shape->clone; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $shape->origin(Geometry::Primitive::Point->new(x => $x, y => $y)); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->path->add_primitive($shape); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 9 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | __END__ | ||||||||||||||||||||||||||||||||||||||||||