blib/lib/Chart/Plot/Tagged.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1  
2 package Chart::Plot::Tagged;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 our $VERSION = '0.02';
8  
9 0 ▶use GD;
Subroutine BEGIN: called CC=1 SCAR=2.6
10 use base qw(Chart::Plot);
11  
12 sub setTag {
13 my $self = shift;
14 my ($arrayref) = @_;
15  
16 # record the dataset
17 my $label = $self->{_numDataSets};
18 $self->{_tag}->{$label} = $arrayref;
19 return $label;
20 }
21  
22 sub _drawData {
23 my $self = shift;
24 $self->SUPER::_drawData();
25 $self->_drawTag();
26 }
27  
28 sub _drawTag {
29 my $self = shift;
30  
31 foreach my $dataSetLabel (keys %{$self->{_data}}) {
32 next unless (exists $self->{_tag}->{$dataSetLabel});
33  
34 # get color
35 my $color = '_black';
36 if ( $self->{'_dataStyle'}->{$dataSetLabel} =~ /((red)|(blue)|(green))/i ) {
37 $color = "_$1";
38 $color =~ tr/A-Z/a-z/;
39 }
40  
41 # get direction
42 my $dir = '';
43 $dir = 'up' if $self->{'_dataStyle'}->{$dataSetLabel} =~ /up/i;
44  
45 my $num = @{ $self->{'_data'}->{$dataSetLabel} };
46 my $prevpx = 0;
47 for (my $i = 0; $i < $num/2; $i ++) {
48  
49 # get next point
50 my ($px, $py) = $self->_data2pxl (
51 $self->{_data}->{$dataSetLabel}[2*$i],
52 $self->{_data}->{$dataSetLabel}[2*$i+1]
53 );
54  
55 my $lbl = $self->{_tag}->{$dataSetLabel}[$i] || '';
56 if ($lbl ne '' && $px != $prevpx) {
57 if ($dir eq 'up') {
58 $self->{'_im'}->stringUp(gdTinyFont, $px-8, $py-5,
59 $lbl, $self->{$color});
60 }
61 else {
62 $self->{'_im'}->string(gdTinyFont, $px+5, $py-4,
63 $lbl, $self->{$color});
64 }
65 $prevpx = $px;
66 }
67 }
68 }
69 }
70  
71 1;
72 __END__
↑ Summary