| 1 | |||||||||||
| 2 | package LaTeX::PGF::Diagram2D::Polyline; | ||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use 5.000000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our @ISA = qw(); | |||||||||
| 11 | |||||||||||
| 12 | 1 | our $VERSION = '1.00'; | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | # Arguments: | ||||||||||
| 16 | # - diagram | ||||||||||
| 17 | # - polyline points | ||||||||||
| 18 | |||||||||||
| 19 | sub new | ||||||||||
| 20 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 21 | 0 | my $self = undef; | |||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | if($#_ < 4) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | croak "Usage: LaTeX::PGF::Diagram2D::Polyline->new(diagram, xaxis, yaxis, pointsarrayref)"; | |||||||||
| 25 | } else { | ||||||||||
| 26 | 0 | my $class = shift; | |||||||||
| 27 | 0 | my $diagram = shift; | |||||||||
| 28 | 0 | my $ax = shift; | |||||||||
| 29 | 0 | my $ay = shift; | |||||||||
| 30 | 0 | my $points = shift; | |||||||||
| 31 | 0 | $self = { | |||||||||
| 32 | 'p' => $points, # Point coordinates | ||||||||||
| 33 | 'c' => 'black', # Color | ||||||||||
| 34 | 's' => 0, # Line style | ||||||||||
| 35 | 'w' => 0.5, # Linewidth factor | ||||||||||
| 36 | 'd' => $diagram, # Parent diagram | ||||||||||
| 37 | 'ax' => $ax, # X axis | ||||||||||
| 38 | 'ay' => $ay, # Y axis | ||||||||||
| 39 | }; | ||||||||||
| 40 | 0 | bless($self, $class); | |||||||||
| 41 | } | ||||||||||
| 42 | 0 | return $self; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | sub set_color | ||||||||||
| 48 | 0 | ▶ | { | ||||||||
|
Subroutine
set_color: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 49 | 0 | my $self = undef; | |||||||||
| 50 | 0 | ▶ | if($#_ < 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | croak "Usage: \$polyline->set_color(color)"; | |||||||||
| 52 | } else { | ||||||||||
| 53 | 0 | $self = shift; $self->{'c'} = shift; | |||||||||
| 54 | } | ||||||||||
| 55 | 0 | return $self; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | sub set_width | ||||||||||
| 61 | 0 | ▶ | { | ||||||||
|
Subroutine
set_width: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 62 | 0 | my $self = undef; | |||||||||
| 63 | 0 | ▶ | if($#_ < 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | croak "Usage: \$polyline->set_width(widthfactor)"; | |||||||||
| 65 | } else { | ||||||||||
| 66 | 0 | $self = shift; $self->{'w'} = shift; | |||||||||
| 67 | } | ||||||||||
| 68 | 0 | return $self; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | sub plot | ||||||||||
| 74 | 0 | ▶ | { | ||||||||
|
Subroutine
plot: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 75 | 0 | my $self = shift; | |||||||||
| 76 | 0 | my $d = $self->{'d'}; | |||||||||
| 77 | 0 | my $fh = $d->{'f1'}; | |||||||||
| 78 | 0 | my $ax = $self->{'ax'}; my $ay = $self->{'ay'}; | |||||||||
| 79 | 0 | my @p; | |||||||||
| 80 | 0 | my $ar = $self->{'p'}; | |||||||||
| 81 | 0 | my $i = 0; | |||||||||
| 82 | 0 | ▶ | for($i = 0; $i <= $#$ar; $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | $p[$i] = $d->value_to_coord($ax, $ay, $ar->[$i], $i); | |||||||||
| 84 | } | ||||||||||
| 85 | 0 | $d->set_color($self->{'c'}); | |||||||||
| 86 | 0 | $d->setlinewidth_mm( 0.2 * $self->{'w'} ); | |||||||||
| 87 | 0 | $i = 0; | |||||||||
| 88 | 0 | ▶ | while($i < $#p) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | ▶ | if($i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | print $fh "\\pgfpathlineto{"; | |||||||||
| 91 | 0 | $d->write_point($p[$i], $p[$i+1]); | |||||||||
| 92 | 0 | print $fh "}\n"; | |||||||||
| 93 | } else { | ||||||||||
| 94 | 0 | print $fh "\\pgfpathmoveto{"; | |||||||||
| 95 | 0 | $d->write_point($p[$i], $p[$i+1]); | |||||||||
| 96 | 0 | print $fh "}\n"; | |||||||||
| 97 | } | ||||||||||
| 98 | 0 | $i++; $i++; | |||||||||
| 99 | } | ||||||||||
| 100 | 0 | print $fh "\\pgfusepath{stroke}\n"; | |||||||||
| 101 | 0 | return $self; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | |||||||||||
| 106 | |||||||||||
| 107 | 1 | 1; | |||||||||
| 108 | __END__ | ||||||||||