Apache-Wyrd
view release on metacpan or search on metacpan
Wyrd/Chart.pm view on Meta::CPAN
$self->{'text_clr'} && $graph->set_text_clr($self->{'text_clr'});
$self->{'title_font'} && $self->_ok_font($self->{'title_font'}) && $graph->set_title_font(token_parse($self->{'title_font'}));
$self->_add_chart_attributes($self->{'_valid_attributes'}->{'all'});
#then those for axis types
if ($type =~ /^(lines|hbars|bars|points|linespoints|area)$/) {
$self->_add_chart_attributes($self->{'_valid_attributes'}->{'axes'});
if ($type =~ /bars/) {
$self->_add_chart_attributes($self->{'_valid_attributes'}->{'bars'});
}
if ($type =~ /points/) {
$self->_add_chart_attributes($self->{'_valid_attributes'}->{'points'});
}
if ($type =~ /lines/) {
$self->_add_chart_attributes($self->{'_valid_attributes'}->{'lines'});
}
#or those for pie types
} elsif ($type eq 'pie') {
$self->_add_chart_attributes($self->{'_valid_attributes'}->{'pie'});
}
#then parse function-based settings, such as fonts
foreach my $attrib (@font_attribs) {
next unless defined ($self->{$attrib});
my ($font, $size) = token_parse($self->{$attrib});
my $approved_font = $self->_ok_font($font);
if ($approved_font) {
eval "\$graph->set_$attrib('$approved_font', $size)";
$self->_error("Could not use font $font in attribute $attrib: $@") if ($@);
} else {
$self->_error("Could not use font $font in attribute $attrib");
}
}
$graph->set_legend(token_parse($self->{'legend'})) if $self->{'legend'};
my %settings = ();
foreach my $attribute (@{$self->{'_chart_attributes'}}) {
$settings{$attribute} = $self->{$attribute} if defined($self->{$attribute});
}
#warn Dumper(\%settings);
$graph->set(%settings);
return $graph;
}
sub _plot {
my ($self) = @_;
my $graph = $self->_get_graph;
$self->_process_chart($graph);
my $gd = $graph->plot($self->{'_graph_data'});
$self->_error($graph->error) if ($graph->error);
$self->_alter_graphic($gd);
$self->_error($graph->error) if ($graph->error);
#256 Color limit due to bugs in GD library
eval {$gd->trueColor(0)};
my $file = $self->{'_graphic_file'};
my $format = $self->{'_file_format'};
local $| = 1;
open OUT, "> $file" || $self->_raise_exception("Could not write file $file: $!");
binmode(OUT);
eval {
if ($format eq 'gif') {
print OUT $gd->gif();
} else {
print OUT $gd->png();
}
$self->_error($graph->error) if ($graph->error);
};
close OUT;
select OUT;
if ($@) {
$self->_error($@);
}
}
sub _add_chart_attributes {
my ($self, $arrayref) = @_;
my %uniq = ();
#combine existing attributes, new attributes, and uniquify them before assigning them to
#the _chart_attributes attribute
$self->{'_chart_attributes'} = [grep {$uniq{$_}++ == 0} (@{$self->{'_chart_attributes'}}, @$arrayref)];
}
=pod
=item (void) C<_alter_graphic> (GD Object)
"Hook" method for putting final changes on the plotted GD graphic. Accepts
the graphic as a GD object. Does nothing by default.
=cut
sub _alter_graphic {
my ($self, $dg) = @_;
return;
}
=pod
=item (undef) C<_process_chart> (GD::Graph Object)
"Hook" method for putting final changes on the GD::Graph object. Accepts
the chart as a GD::Graph object. Does nothing by default.
=cut
sub _process_chart {
my ($self, $graph) = @_;
return;
}
=pod
=item (void) C<_set_default_attribs> (void)
"Hook" method for setting default attributes. Does nothing by default.
=cut
sub _set_default_attributes {
( run in 1.927 second using v1.01-cache-2.11-cpan-d8267643d1d )