use Imager::Graph::SubClass;
my $chart = Imager::Graph::SubClass->new;
- my $img = $chart->draw(data=>..., ...)
+ my $img = $chart->draw(data=> \@data, ...)
or die $chart->error;
=head1 DESCRIPTION
=cut
use strict;
+use warnings;
use vars qw($VERSION);
use Imager qw(:handy);
use Imager::Fountain;
The C<style> parameter will selects a basic color set, and possibly
sets other related parameters. See L</"STYLES">.
- my $img = $graph->draw(data=>\@data,
- title=>{ text=>"Hello, World!",
- size=>36,
- color=>'FF0000' });
+ my $font = Imager::Font->new(file => 'ImUgly.ttf');
+ my $img = $chart->draw(
+ data => \@data,
+ font => $font,
+ title => {
+ text => "Hello, World!",
+ size => 36,
+ color => 'FF0000'
+ }
+ );
When referring to a single sub-value this documentation will refer to
'title.color' rather than 'the color element of title'.
a light grey background with no outlines. Uses primary colors for the
data fills.
-This is the default style.
-
=item primary_red
a light red background with no outlines. Uses primary colors for the
You can override the value used for text and outlines by setting the
C<fg> parameter.
+This is the default style.
+
=item fount_rad
also designed as a "pretty" style this uses radial fountain fills for
\%style_defs;
}
-my $def_style = 'primary';
+# Let's make the default something that looks really good, so folks will be interested enough to customize the style.
+my $def_style = 'fount_lin';
my %styles =
(
sub _make_img {
my ($self) = @_;
-
- my ($width, $height) = (256, 256);
- $width = $self->_get_number('width');
- $height = $self->_get_number('height');
+ my $width = $self->_get_number('width') || 256;
+ my $height = $self->_get_number('height') || 256;
my $channels = $self->{_style}{channels};
$channels ||= 3;
my %text_info = $self->_text_style($name);
+ if (!defined $text_info{font}) {
+ die "No font or invalid font specified, and we're trying to draw text.\n";
+ }
my @bbox = $text_info{font}->bounding_box(%text_info, string=>$text,
canon=>1);
my $chart = Imager::Graph::Pie->new;
# see Imager::Graph for options
- my $img = $chart->draw(labels=>['first segment', 'second segment'],
- data=>[ $first_amount, $second_amount ],
- size=>[$width, $height])
+ my $img = $chart->draw(
+ data => [ $first_amount, $second_amount ],
+ size => 350);
=head1 DESCRIPTION
Draws a pie graph onto a new image and returns the image.
-You must at least supply a C<data> parameter and should probably supply a C<labels> parameter.
+You must at least supply a C<data> parameter and should probably supply a C<labels> parameter. If you supply a C<labels> parameter, you must supply a C<font> parameter.
The C<data> parameter should be a reference to an array containing the
data the pie graph should present.