-
-
13 Oct 2005 22:03:56 UTC
- Distribution: Gtk2-Ex-Graph-GD
- Module version: 0.04
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues
- Testers (109 / 39 / 0)
- Kwalitee
Bus factor: 0- 87.50% Coverage
- License: unknown
- Activity
24 month- Tools
- Download (6.25KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- GD::Graph::area
- GD::Graph::bars
- GD::Graph::lines
- GD::Graph::linespoints
- GD::Graph::pie
- Glib
- Gtk2
- Test::More
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
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 aGD::Graph::Data
object. This method internally calls theGD::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 aremy ($measure, $xvalue, $yvalue) = @_
If the graph is of type
lines
then the return values aremy ($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
Module Install Instructions
To install Gtk2::Ex::Graph::GD, copy and paste the appropriate command in to your terminal.
cpanm Gtk2::Ex::Graph::GD
perl -MCPAN -e shell install Gtk2::Ex::Graph::GD
For more information on module installation, please visit the detailed CPAN module installation guide.