| 1 | package SVG::Graph::Data; | ||||||||||
| 2 | |||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 7 | ▶ | use Statistics::Descriptive; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =head2 new | ||||||||||
| 8 | |||||||||||
| 9 | Title : new | ||||||||||
| 10 | Usage : my $data = SVG::Graph::Data->new | ||||||||||
| 11 | Function: creates a new SVG::Graph::Data object | ||||||||||
| 12 | Returns : a SVG::Graph::Data object | ||||||||||
| 13 | Args : (optional) array of SVG::Graph::Data::Datum objects | ||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 9 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 19 | 9 | my($class, %args) = @_; | |||||||||
| 20 | 9 | my $self = bless {}, $class; | |||||||||
| 21 | 9 | $self->init(%args); | |||||||||
| 22 | 9 | return $self; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | =head2 init | ||||||||||
| 26 | |||||||||||
| 27 | Title : init | ||||||||||
| 28 | Usage : | ||||||||||
| 29 | Function: | ||||||||||
| 30 | Example : | ||||||||||
| 31 | Returns : | ||||||||||
| 32 | Args : | ||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | =cut | ||||||||||
| 36 | |||||||||||
| 37 | 9 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 38 | 9 | my($self, %args) = @_; | |||||||||
| 39 | 9 | foreach my $arg (keys %args){ | |||||||||
| 40 | 9 | my $meth = 'add_'.$arg; | |||||||||
| 41 | 9 | $self->$meth($args{$arg}); | |||||||||
| 42 | } | ||||||||||
| 43 | 9 | $self->is_changed(1); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | =head2 data | ||||||||||
| 47 | |||||||||||
| 48 | Title : data | ||||||||||
| 49 | Usage : | ||||||||||
| 50 | Function: | ||||||||||
| 51 | Example : | ||||||||||
| 52 | Returns : | ||||||||||
| 53 | Args : | ||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 34 | ▶ | sub data { | ||||||||
|
Subroutine
data: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 59 | 34 | my $self = shift; | |||||||||
| 60 | |||||||||||
| 61 | 34 | ▶ | return $self->{data} ? @{$self->{data}} : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | =head2 add_data | ||||||||||
| 65 | |||||||||||
| 66 | Title : add_data | ||||||||||
| 67 | Usage : $data->add_data($datum) | ||||||||||
| 68 | Function: adds a Datum object to the current Data object | ||||||||||
| 69 | Returns : none | ||||||||||
| 70 | Args : SVG::Graph::Data::Datum object | ||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||
| 74 | |||||||||||
| 75 | 9 | ▶ | sub add_data { | ||||||||
|
Subroutine
add_data: called CC=6 SCAR=20.9
Pod
documented
| |||||||||||
| 76 | 9 | my($self,@data) = @_; | |||||||||
| 77 | |||||||||||
| 78 | 9 | my $epitaph = "only SVG::Graph::Data::Datum objects accepted"; | |||||||||
| 79 | |||||||||||
| 80 | 9 | foreach my $data (@data){ | |||||||||
| 81 | 9 | ▶ | if(ref $data eq 'ARRAY'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 9 | foreach my $d (@$data){ | |||||||||
| 83 | 180 | ▶ | die $epitaph unless ref $d eq 'SVG::Graph::Data::Datum'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 180 | push @{$self->{data}}, $d; | |||||||||
| 85 | } | ||||||||||
| 86 | } else { | ||||||||||
| 87 | 0 | ▶ | die $epitaph unless ref $data eq 'SVG::Graph::Data::Datum'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 0 | push @{$self->{data}}, $data; | |||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 9 | $self->is_changed(1); | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | =head2 _recalculate_stats | ||||||||||
| 96 | |||||||||||
| 97 | Title : _recalculate_stats | ||||||||||
| 98 | Usage : | ||||||||||
| 99 | Function: | ||||||||||
| 100 | Example : | ||||||||||
| 101 | Returns : | ||||||||||
| 102 | Args : | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | sub _recalculate_stats{ | ||||||||
|
Subroutine
_recalculate_stats: not called CC=2 SCAR=17.9
| |||||||||||
| 108 | 0 | my ($self,@args) = @_; | |||||||||
| 109 | 0 | ▶ | return undef unless $self->is_changed; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | |||||||||||
| 111 | #x | ||||||||||
| 112 | 0 | my $xstat = Statistics::Descriptive::Full->new(); | |||||||||
| 113 | 0 | $xstat->add_data(map {$_->x} $self->data); | |||||||||
| 114 | 0 | $self->xstat($xstat); | |||||||||
| 115 | |||||||||||
| 116 | #y | ||||||||||
| 117 | 0 | my $ystat = Statistics::Descriptive::Full->new(); | |||||||||
| 118 | 0 | $ystat->add_data(map {$_->y} $self->data); | |||||||||
| 119 | 0 | $self->ystat($ystat); | |||||||||
| 120 | |||||||||||
| 121 | #z | ||||||||||
| 122 | 0 | my $zstat = Statistics::Descriptive::Full->new(); | |||||||||
| 123 | 0 | $zstat->add_data(map {$_->z} $self->data); | |||||||||
| 124 | 0 | $self->zstat($zstat); | |||||||||
| 125 | |||||||||||
| 126 | 0 | $self->is_changed(0); | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | =head2 xstat | ||||||||||
| 130 | |||||||||||
| 131 | Title : xstat | ||||||||||
| 132 | Usage : $obj->xstat($newval) | ||||||||||
| 133 | Function: | ||||||||||
| 134 | Example : | ||||||||||
| 135 | Returns : value of xstat (a scalar) | ||||||||||
| 136 | Args : on set, new value (a scalar or undef, optional) | ||||||||||
| 137 | |||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | 249 | ▶ | sub xstat{ | ||||||||
|
Subroutine
xstat: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 142 | 249 | my $self = shift; | |||||||||
| 143 | |||||||||||
| 144 | 249 | ▶ | return $self->{'xstat'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | 241 | return $self->{'xstat'}; | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | =head2 ystat | ||||||||||
| 149 | |||||||||||
| 150 | Title : ystat | ||||||||||
| 151 | Usage : $obj->ystat($newval) | ||||||||||
| 152 | Function: | ||||||||||
| 153 | Example : | ||||||||||
| 154 | Returns : value of ystat (a scalar) | ||||||||||
| 155 | Args : on set, new value (a scalar or undef, optional) | ||||||||||
| 156 | |||||||||||
| 157 | |||||||||||
| 158 | =cut | ||||||||||
| 159 | |||||||||||
| 160 | 249 | ▶ | sub ystat{ | ||||||||
|
Subroutine
ystat: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 161 | 249 | my $self = shift; | |||||||||
| 162 | |||||||||||
| 163 | 249 | ▶ | return $self->{'ystat'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 164 | 241 | return $self->{'ystat'}; | |||||||||
| 165 | } | ||||||||||
| 166 | |||||||||||
| 167 | =head2 zstat | ||||||||||
| 168 | |||||||||||
| 169 | Title : zstat | ||||||||||
| 170 | Usage : $obj->zstat($newval) | ||||||||||
| 171 | Function: | ||||||||||
| 172 | Example : | ||||||||||
| 173 | Returns : value of zstat (a scalar) | ||||||||||
| 174 | Args : on set, new value (a scalar or undef, optional) | ||||||||||
| 175 | |||||||||||
| 176 | |||||||||||
| 177 | =cut | ||||||||||
| 178 | |||||||||||
| 179 | 13 | ▶ | sub zstat{ | ||||||||
|
Subroutine
zstat: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 180 | 13 | my $self = shift; | |||||||||
| 181 | |||||||||||
| 182 | 13 | ▶ | return $self->{'zstat'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 183 | 5 | return $self->{'zstat'}; | |||||||||
| 184 | } | ||||||||||
| 185 | |||||||||||
| 186 | |||||||||||
| 187 | 0 | ▶ | sub xmean {$_[0]->_recalculate_stats; return $_[0]->xstat->mean} | ||||||||
|
Subroutine
xmean: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 188 | 0 | ▶ | sub xmode {$_[0]->_recalculate_stats; return $_[0]->xstat->mode} | ||||||||
|
Subroutine
xmode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 189 | 0 | ▶ | sub xmedian {$_[0]->_recalculate_stats; return $_[0]->xstat->median} | ||||||||
|
Subroutine
xmedian: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 190 | 0 | ▶ | sub xmin {$_[0]->_recalculate_stats; return $_[0]->xstat->min} | ||||||||
|
Subroutine
xmin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 191 | 0 | ▶ | sub xmax {$_[0]->_recalculate_stats; return $_[0]->xstat->max} | ||||||||
|
Subroutine
xmax: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 192 | 0 | ▶ | sub xrange {$_[0]->_recalculate_stats; return $_[0]->xstat->sample_range} | ||||||||
|
Subroutine
xrange: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 193 | 0 | ▶ | sub xstdv {$_[0]->_recalculate_stats; return $_[0]->xstat->standard_deviation} | ||||||||
|
Subroutine
xstdv: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 194 | 0 | ▶ | sub xpercentile {$_[0]->_recalculate_stats; return $_[0]->xstat->percentile($_[1])} | ||||||||
|
Subroutine
xpercentile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 195 | |||||||||||
| 196 | 0 | ▶ | sub ymean {$_[0]->_recalculate_stats; return $_[0]->ystat->mean} | ||||||||
|
Subroutine
ymean: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 197 | 0 | ▶ | sub ymode {$_[0]->_recalculate_stats; return $_[0]->ystat->mode} | ||||||||
|
Subroutine
ymode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 198 | 0 | ▶ | sub ymedian {$_[0]->_recalculate_stats; return $_[0]->ystat->median} | ||||||||
|
Subroutine
ymedian: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 199 | 0 | ▶ | sub ymin {$_[0]->_recalculate_stats; return $_[0]->ystat->min} | ||||||||
|
Subroutine
ymin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 200 | 0 | ▶ | sub ymax {$_[0]->_recalculate_stats; return $_[0]->ystat->max} | ||||||||
|
Subroutine
ymax: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 201 | 0 | ▶ | sub yrange {$_[0]->_recalculate_stats; return $_[0]->ystat->sample_range} | ||||||||
|
Subroutine
yrange: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 202 | 0 | ▶ | sub ystdv {$_[0]->_recalculate_stats; return $_[0]->ystat->standard_deviation} | ||||||||
|
Subroutine
ystdv: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 203 | 0 | ▶ | sub ypercentile {$_[0]->_recalculate_stats; return $_[0]->ystat->percentile($_[1])} | ||||||||
|
Subroutine
ypercentile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 204 | |||||||||||
| 205 | 0 | ▶ | sub zmean {$_[0]->_recalculate_stats; return $_[0]->zstat->mean} | ||||||||
|
Subroutine
zmean: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 206 | 0 | ▶ | sub zmode {$_[0]->_recalculate_stats; return $_[0]->zstat->mode} | ||||||||
|
Subroutine
zmode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 207 | 0 | ▶ | sub zmedian {$_[0]->_recalculate_stats; return $_[0]->zstat->median} | ||||||||
|
Subroutine
zmedian: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 208 | 0 | ▶ | sub zmin {$_[0]->_recalculate_stats; return $_[0]->zstat->min} | ||||||||
|
Subroutine
zmin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 209 | 0 | ▶ | sub zmax {$_[0]->_recalculate_stats; return $_[0]->zstat->max} | ||||||||
|
Subroutine
zmax: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 210 | 5 | ▶ | sub zrange {$_[0]->_recalculate_stats; return $_[0]->zstat->sample_range} | ||||||||
|
Subroutine
zrange: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 211 | 0 | ▶ | sub zstdv {$_[0]->_recalculate_stats; return $_[0]->zstat->standard_deviation} | ||||||||
|
Subroutine
zstdv: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 212 | 0 | ▶ | sub zpercentile {$_[0]->_recalculate_stats; return $_[0]->zstat->percentile($_[1])} | ||||||||
|
Subroutine
zpercentile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 213 | |||||||||||
| 214 | =head2 is_changed | ||||||||||
| 215 | |||||||||||
| 216 | Title : is_changed | ||||||||||
| 217 | Usage : $obj->is_changed($newval) | ||||||||||
| 218 | Function: | ||||||||||
| 219 | Example : | ||||||||||
| 220 | Returns : value of is_changed (a scalar) | ||||||||||
| 221 | Args : on set, new value (a scalar or undef, optional) | ||||||||||
| 222 | |||||||||||
| 223 | |||||||||||
| 224 | =cut | ||||||||||
| 225 | |||||||||||
| 226 | 533 | ▶ | sub is_changed{ | ||||||||
|
Subroutine
is_changed: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 227 | 533 | my $self = shift; | |||||||||
| 228 | |||||||||||
| 229 | 533 | ▶ | return $self->{'is_changed'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 230 | 487 | return $self->{'is_changed'}; | |||||||||
| 231 | } | ||||||||||
| 232 | |||||||||||
| 233 | =head2 svg | ||||||||||
| 234 | |||||||||||
| 235 | Title : svg | ||||||||||
| 236 | Usage : $obj->svg($newval) | ||||||||||
| 237 | Function: | ||||||||||
| 238 | Example : | ||||||||||
| 239 | Returns : value of svg (a scalar) | ||||||||||
| 240 | Args : on set, new value (a scalar or undef, optional) | ||||||||||
| 241 | |||||||||||
| 242 | |||||||||||
| 243 | =cut | ||||||||||
| 244 | |||||||||||
| 245 | 10 | ▶ | sub add_svg {return shift->svg(@_)}; | ||||||||
|
Subroutine
add_svg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 246 | 0 | ▶ | sub svg{ | ||||||||
|
Subroutine
svg: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 247 | 0 | my $self = shift; | |||||||||
| 248 | |||||||||||
| 249 | 0 | ▶ | return $self->{'svg'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 250 | 0 | return $self->{'svg'}; | |||||||||
| 251 | } | ||||||||||
| 252 | |||||||||||
| 253 | |||||||||||
| 254 | 7 | 1; | |||||||||