NAME
Gtk2::Ex::Graph::GD is a thin wrapper around the good-looking GD::Graph module. Wrapping using Gtk2 allows the GD::Graph object to respond to events such as mouse movements.
This allows functionalities such as mouse-over-tooltip and right-click menus on the Graph.
SYNOPSIS
my $graph = Gtk2::Ex::Graph::GD->new(500, 300, 'bars');
my $data = GD::Graph::Data->new([
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
[ 1.4, 4, 15, 6, 13, 1.5, 11, 3, 4],
]) or die GD::Graph::Data->error;
my $image = $graph->get_image($data);
my $window = Gtk2::Window->new;
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
$window->set_default_size(700, 500);
$window->add($image);
$window->show_all;
Gtk2->main;
FUNCTIONS
$graph = Gtk2::Ex::Graph::GD->new($width, $height, $type)
Creates a new Gtk2::Ex::Graph::GD object with the specified dimensions and type. The type can be 'bars', 'lines', 'pie'.
$graph = Gtk2::Ex::Graph::GD->new(500, 300, 'bars');
$graph->set($attr1 => $value1, $attr2 => $value2,...)
This is just a thin wrapper on the GD::Graph-
set> method. All the properties set here go straight into the GD::Graph::* object created inside. Therefore, any property acceptable to the GD::Graph::* object can be passed through here
$graph->set (
x_label => 'X Label',
y_label => 'Y label',
title => 'A Simple Bar Chart',
bar_spacing => 1,
shadowclr => 'dred',
transparent => 0,
);
$graph->set_legend(@legend_keys)
This is just a thin wrapper on the GD::Graph-
set_legend> method. However, this method extracts the @legend_keys
and uses them in the mouse-over tooltip text.
my @legend_keys = ('First', 'Second');
$graph->set_legend(@legend_keys);
$graph->get_image($data)
The $data
object used here is a GD::Graph::Data
object. This method internally calls the GD::Graph-
plot($data)> and then exports the output into a png. The png is then wrapped into a Gtk2::Image and then into a Gtk2::EventBox and returned here. You can go on and pack this $image
into the window.
my $image = $graph->get_image($data);
signal_connect($signal, $callback)
Two signals are supported
'mouse-over'
'clicked'
You can bind to these signals just like how you would bind to any normal Gtk2 widget signal.
$graph->signal_connect ('clicked' =>
sub {
print Dumper @_;
}
);
If the graph is of type bars
then the return values are
my ($measure, $xvalue, $yvalue) = @_
If the graph is of type lines
then the return values are
my ($measure, $xvalue0, $yvalue0, $xvalue1, $yvalue1) = @_
These callbacks are not currently supported for other graph types. I may add them later on. =head1 COPYRIGHT AND LICENSE
Copyright (C) 2005 by Ofey Aikon
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation;
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA.
ACKNOWLEDGEMENTS
To the wonderful gtk-perl-list.
SEE ALSO
GD::Graph