Graph/Plot/points/string.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 71 CC 4 SCAR 20.1
CC
4
Cov
0%
valuesInRange
12.0
count
6.0
new
2.0
CRAP 7.4
1 package CGI::Graph::Plot::points::string;
2  
3 use CGI::Graph::Plot::points;
4  
5 @ISA = ("CGI::Graph::Plot::points");
6  
7 #
8 # makes call to parent class where all real work is done
9 #
10  
11 sub new {
12 my ($pkg, $vars) = @_;
13 my $class = ref($pkg) || $pkg;
14 my $self = $class->SUPER::new($vars);
15 return bless $self, $class;
16 }
17  
18 #
19 # creates an array used for the X values of a graph. The numbers run
20 # sequentially from 1 upward, and identical non-numerical values in the input
21 # array are given the same number in the return array.
22 #
23  
24 sub count {
25 my $self = shift;
26 my @X = @_;
27
28 my @return;
29 my $count = 1;
30  
31 # assign numerical x value for each identical non-numerical x
32 for (0..$#X) {
33 push (@return,$count);
34 $count++ unless ($X[$_] eq $X[$_+1]);
35 }
36  
37 push (@return,$count); # add extra value for space at end
38  
39 return (@return);
40 }
41  
42 #
43 # returns a reference to X, Y, and select arrays that will be used to create
44 # graph images. The X and Y values must fall between the min and max values,
45 # the select value is just a flag to indicate if the point must be highlighted.
46 #
47  
48 sub valuesInRange{
49 my $self = shift;
50  
51 my @selected = split("",$self->{selected});
52  
53 my @row = $self->{table}->col('_row');
54 my @X = $self->{table}->col($self->{X});
55 my @Y = $self->{table}->col($self->{Y});
56  
57 @X = $self->count(@X);
58  
59 my (@returnX,@returnY,@selectDraw);
60 my $yFlag;
61  
62 # determine if elements are selected and/or in range
63 for (0..$#X) {
64 push (@selectDraw, $selected[$row[$_]-1]);
65 # determines if element is in range
66 if (($X[$_] >= $self->{x_min} && $X[$_] <= $self->{x_max} &&
67 $Y[$_] >= $self->{y_min} && $Y[$_] <= $self->{y_max})
68 || ($self->{grid})) {
69 push (@returnY,$Y[$_]);
70 $yFlag++;
71 }
72 # if element not in range, use undef
73 else {
74 push (@returnY,undef);
75 }
76 }
77  
78 # make sure that returnY has at least one non-undef value
79 unless ($yFlag) {
80 $returnY[0]=$self->{y_min}-$self->{y_max};
81 }
82  
83 return (\@X,\@returnY,\@selectDraw);
84 }
85  
86 1;