Chart-Plot-Canvas
view release on metacpan or search on metacpan
lib/Chart/Plot/Canvas.pm view on Meta::CPAN
$self->{'_imy'} = $_[1];
}
else {
$self->{'_imx'} = 400;
$self->{'_imy'} = 300;
}
# set graph offset; graph will be centered this many pixels within image
$self->{'_horGraphOffset'} = 50;
$self->{'_vertGraphOffset'} = 50;
# create an empty hash for the datsets
# data sets and their styles are hashes whose keys are 1 ... _numDataSets
# and values are refs to flat data arrays or style strings, respectively
$self->{'_data'} = {};
$self->{'_dataStyle'} = {};
$self->{'_numDataSets'} = 0;
# calculated by _getMinMax and used in translating _data2pxl()
$self->{'_xmin'} = 0; $self->{'_xmax'} = 0; # among all datasets
$self->{'_ymin'} = 0; $self->{'_ymax'} = 0;
$self->{'_xslope'} = 0; $self->{'_yslope'} = 0; # for _data2pxl()
$self->{'_ax'} = 0; $self->{'_ay'} = 0;
$self->{'_omx'} = 0; $self->{'_omy'} = 0; # for axis ticks
$self->{'_validMinMax'} = 0; # last calculated min and max still valid
# initialize text
($self->{'_horAxisLabel'}, $self->{'_vertAxisLabel'}) = (q{},q{});
$self->{'_title'} = q{};
$self->{'_errorMessage'} = q{};
# initialize custom tick labels
($self->{'_xTickLabels'}, $self->{'_yTickLabels'}) = (0,0);
# undocumented: in script, use as $plotObject->{'_debugging'} = 1;
$self->{'_debugging'} = 0;
}
sub _init_gd {
my $self = shift;
use GD;
# create an image object
$self->{'_im'} = new GD::Image($self->{'_imx'}, $self->{'_imy'});
# find format(s) supported by GD
unless (@_image_types) {
for ( qw(png gif jpeg) ) {
push @_image_types, $_ if $self->{'_im'}->can($_);
}
}
# allocate some colors
$self->{'_white'} = $self->{'_im'}->colorAllocate(255,255,255);
$self->{'_black'} = $self->{'_im'}->colorAllocate(0,0,0);
$self->{'_red'} = $self->{'_im'}->colorAllocate(255,0,0);
$self->{'_blue'} = $self->{'_im'}->colorAllocate(0,0,255);
$self->{'_green'} = $self->{'_im'}->colorAllocate(0,255,0);
# make the background transparent and interlaced
$self->{'_im'}->transparent($self->{'_white'});
$self->{'_im'}->interlaced('true');
# Put a black frame around the picture
$self->{'_im'}->rectangle( 0, 0,
$self->{'_imx'}-1, $self->{'_imy'}-1,
$self->{'_black'});
}
sub _init_cv {
my $self = shift;
use Tk;
my($widget) = @_;
# create an canvas object
$self->{'_cv'} = $widget->Canvas(
-width => $self->{'_imx'},
-height => $self->{'_imy'},
);
# make the background white
$self->{'_cv'}->configure(
-background => 'white',
);
# some fonts
if ($^O eq 'MSWin32') {
$self->{'_MediumBoldFont'} = "{MS Sans serif} 8 bold";
$self->{'_SmallFont'} = "Tahoma 8";
$self->{'_TinyFont'} = "{Small Fonts} 6";
}
else {
$self->{'_MediumBoldFont'} = '7x13bold';
$self->{'_SmallFont'} = '6x12';
$self->{'_TinyFont'} = '5x8';
}
}
# draws all the datasets in $self->{'_data'}
# usage: $self->_createData()
sub _createData {
my $self = shift;
my ($i, $num, $px, $py, $prevpx, $prevpy, $dataSetLabel, $color);
foreach $dataSetLabel (keys %{$self->{'_data'}}) {
# get color
if ( $self->{'_dataStyle'}->{$dataSetLabel} =~ /((red)|(blue)|(green))/i ) {
$color = $1;
$color =~ tr/A-Z/a-z/;
}
else {
$color = 'black';
}
# draw the first point
($px, $py) = $self->_data2pxl (
$self->{'_data'}->{$dataSetLabel} [0],
$self->{'_data'}->{$dataSetLabel} [1]
);
( run in 1.158 second using v1.01-cache-2.11-cpan-39bf76dae61 )