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