Gtk2-Ex-TreeMap

 view release on metacpan or  search on metacpan

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

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

=head2 Gtk2::Ex::TreeMap->draw_map_simple($values);

Use this API to quickly build a treemap from a flat list of values. The colors of the 
rectangles are chosen internally. If you want to do anything serious, like specify colors, 
description etc, then use the C<draw_map($tree)> api.

	my $values = [6,6,4,3,2,2,1];
	$treemap->draw_map_simple($values);

=head2 Gtk2::Ex::TreeMap->draw_map($tree);

This is the api that you will use most of the time. This one accepts a hierarchical tree 
structure as its input. I have chosen the tree format that is used by the XML::Simple module.
This approach so that the tree can be easily constructed from an xml document.

Here is an example definition of the XML

	<Node>
		<Node>
			<Node size="9" color="0,0,80" description="0 0"/>
			<Node size="7" color="0,120,80" description="0 1"/>
			<Node>
				<Node size="9" color="0,0,100" description="0 2 0"/>
				<Node size="9" color="0,0,110" description="0 2 1"/>
				<Node>
					<Node size="8" color="0,0,100" description="0 2 2 0"/>
					<Node size="2" color="0,0,110" description="0 2 2 1"/>
				</Node>
			</Node>
		</Node>
		<Node>
			<Node size="7" color="0,170,200" description="1 0"/>
			<Node size="5" color="0,170,210" description="1 1"/>
			<Node size="9" color="0,170,220" description="1 2"/>
		</Node>
	</Node>	

Now read this string using XML::Simple to derive the tree.

	my $tree = XMLin($xmlstr, ForceArray => 1);
	$treemap->draw_map($tree);

B<Note: It is very important to use the C<ForceArray> option. Else you will end up with
a variety of errors.>

=head2 Gtk2::Ex::TreeMap->get_image

Returns the TreeMap image as a C<Gtk2::Image> wrapped in a C<Gtk2::EventBox>. You can add this
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.

=head1 COPYRIGHT & LICENSE

Copyright 2005 Ofey Aikon, All Rights Reserved.

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; either version 2.1 of the License, or (at your option) any
later version.

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.

=cut

__END__



( run in 1.041 second using v1.01-cache-2.11-cpan-364913b4093 )