Gtk2-Ex-TreeMap

 view release on metacpan or  search on metacpan

examples/demo-treemap.pl  view on Meta::CPAN

use Data::Dumper;
use XML::Simple;

use Gtk2 -init;
use Glib qw /TRUE FALSE/;

use Gtk2::Ex::TreeMap;

# This is our little tooltip window.
my $tooltip_label = Gtk2::Label->new;
my $tooltip = Gtk2::Window->new('popup');
$tooltip->set_decorated(0);
$tooltip->set_position('mouse'); # We'll choose this to start with.
$tooltip->add($tooltip_label);
my $tooltip_displayed = FALSE;

my $xmlstr;
while (<DATA>) {
	$xmlstr .= $_;
}
my $tree = XMLin($xmlstr, ForceArray => 1);

my $treemap = Gtk2::Ex::TreeMap->new([600,400]);

my $current_chosen_path = [];
$treemap->signal_connect('mouse-over', \&show_popup);

$treemap->draw_map($tree);

my $window = Gtk2::Window->new;
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
$window->add($treemap->get_image);
$window->show_all;
Gtk2->main;

sub show_popup {
	my ($x, $y, $path, $node) = @_;
	my $str1 = join ':', @$current_chosen_path;
	my $str2 = join ':', @$path;
	if ($str1 ne $str2) { # Path has changed
		@$current_chosen_path = @$path;
		my $size = $node->{size} || "unknown";
		my $description = $node->{description} || "unknown";
		my $color = $node->{color} || "unknown";
		my $desc = "size = $size\ndesc = $description\ncolor = $color";
	    $tooltip_label->set_label($desc);

lib/Gtk2/Ex/TreeMap.pm  view on Meta::CPAN

to your own Gtk2 container

	my $window = Gtk2::Window->new;
	$window->add($treemap->get_image);
	$window->show_all;
	Gtk2->main;

=head1 TODO

  * Implement callback for mouse-over and clicked events
  * Implement popup box as a default option
  * Implement text in the rectangles
  * The boxes should probably be drawn with a black border
  * Build a new example using WWW::Google::News perhaps !
  * Once the module is done, may be I'll split it into a two; a pure GD module which 
    will be "used" by a Gtk2 module. That way, non-Gtk2 folks can use it, of course 
    without the popups and callbacks and all those bells and whistles.
  * More tests, more documentation.

=head1 AUTHOR

Ofey Aikon, C<< <ofey_aikon at gmail dot com> >>

=head1 ACKNOWLEDGEMENTS

To the wonderful gtk-perl list.



( run in 2.542 seconds using v1.01-cache-2.11-cpan-364913b4093 )