diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-05-18 10:50:10 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-05-18 10:50:10 +0100 |
| commit | 7c83f334c6abda21d945945ba8f0da5ff388b833 (patch) | |
| tree | a36cfdb265ff54720cafef65d4719a2821489527 /challenge-165/james-smith/perl | |
| parent | 5957f3d0dd509e68787beaa1b16b5d1b95deea90 (diff) | |
| download | perlweeklychallenge-club-7c83f334c6abda21d945945ba8f0da5ff388b833.tar.gz perlweeklychallenge-club-7c83f334c6abda21d945945ba8f0da5ff388b833.tar.bz2 perlweeklychallenge-club-7c83f334c6abda21d945945ba8f0da5ff388b833.zip | |
tidied up
Diffstat (limited to 'challenge-165/james-smith/perl')
| -rw-r--r-- | challenge-165/james-smith/perl/SVG.pm | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/challenge-165/james-smith/perl/SVG.pm b/challenge-165/james-smith/perl/SVG.pm index d2d8323c17..9a9ca6b77b 100644 --- a/challenge-165/james-smith/perl/SVG.pm +++ b/challenge-165/james-smith/perl/SVG.pm @@ -95,7 +95,8 @@ sub best_fit { sub add_line_of_best_fit { my $self = shift; my ($a,$b) = $self->best_fit; - my ($min_x, $max_x, $min_y, $max_y, $extn) = ( $self->{'min_x'}, $self->{'max_x'}, $self->{'min_y'}, $self->{'max_y'}, $self->{'config'}{'margin'} ); + my ( $min_x, $max_x, $min_y, $max_y, $extn ) = + ( $self->{'min_x'}, $self->{'max_x'}, $self->{'min_y'}, $self->{'max_y'}, $self->{'config'}{'margin'} ); ## special case of a vertical line $self->add_lines( [ $a, $min_y - $extn, $a, $max_y + $extn] ), return $self unless defined $b; @@ -114,7 +115,8 @@ sub calculate_image_size { my $margin = $self->{'config'}{'margin'}; ## Adjust height and width so it fits the size from the self->{'config'}ig. - my($W,$H,$width,$height) = ($self->{'config'}{'max_w'},$self->{'config'}{'max_h'},$self->{'max_x'}-$self->{'min_x'}+2*$margin,$self->{'max_y'}-$self->{'min_y'}+2*$margin); + my($W,$H,$width,$height) = ($self->{'config'}{'max_w'},$self->{'config'}{'max_h'}, + $self->{'max_x'}-$self->{'min_x'}+2*$margin,$self->{'max_y'}-$self->{'min_y'}+2*$margin); ( $width/$height > $W/$H ) ? ( $H = $height/$width*$W ) : ( $W = $width/$height*$H ); ## Calculate the scale factor so that we keep spots/lines the same size irrespective of the ranges. ( $self->{'width'}, $self->{'height'}, $self->{'scale'} ) = ( $W, $H, $width/$W ); @@ -133,8 +135,8 @@ sub render { sub _render { my $self = shift; - $self->calculate_image_size(); - my $margin = $self->{'config'}{'margin'}; + $self->calculate_image_size(); ## Given max height/width work out the dimensions of image and the scale factor. + my $margin = $self->{'config'}{'margin'}; ## Get margin... sprintf $SVG_TEMPLATE, $self->{'height'}, $self->{'width'}, $self->{'min_x'} - $margin, $self->{'min_y'} - $margin, $self->{'max_x'} - $self->{'min_x'} + 2 * $margin, @@ -142,8 +144,10 @@ sub _render { $self->{'config'}{'border'}, $self->{'scale'}, $self->{'config'}{'bg'}, $self->{'min_x'} - $margin, $self->{'min_y'} - $margin, $self->{'max_x'} - $self->{'min_x'} + 2 * $margin, $self->{'max_y'} - $self->{'min_y'} + 2 * $margin, - $self->{'config'}{'color'}, $self->{'config'}{'stroke'} * $self->{'scale'}, join( qq(\n ), map { sprintf $LINE_TEMPLATE, @{$_} } @{$self->{'lines'}} ), ## lines - $self->{'config'}{'fill'}, join( qq(\n ), map { sprintf $POINT_TEMPLATE, @{$_}, $self->{'config'}{'radius'}*$self->{'scale'} } @{$self->{'points'}} ) ## points + $self->{'config'}{'color'}, $self->{'config'}{'stroke'} * $self->{'scale'}, + join( qq(\n ), map { sprintf $LINE_TEMPLATE, @{$_} } @{$self->{'lines'}} ), ## lines + $self->{'config'}{'fill'}, join( qq(\n ), + map { sprintf $POINT_TEMPLATE, @{$_}, $self->{'config'}{'radius'}*$self->{'scale'} } @{$self->{'points'}} ) ## points } |
