Tree::Visualize - A module for visualizing Tree structures
use Tree::Visualize; use Tree::Binary; my $tree = Tree::Binary->new("*") ->setLeft( Tree::Binary->new("+") ->setLeft(Tree::Binary->new("2")) ->setRight(Tree::Binary->new("2")) ) ->setRight( Tree::Binary->new("+") ->setLeft(Tree::Binary->new("4")) ->setRight(Tree::Binary->new("5")) ); my $visualize = Tree::Visualize->new($tree, 'ASCII', 'TopDown'); print $visualize->draw(); # +---+ # +--------| * |-------+ # | +---+ | # +---+ +---+ # +--| + |--+ +--| + |--+ # | +---+ | | +---+ | # +---+ +---+ +---+ +---+ # | 2 | | 2 | | 4 | | 5 | # +---+ +---+ +---+ +---+ my $tree = Tree::Binary::Search->new(); foreach my $value (7, 3, 1, 0, 2, 5, 4, 6, 11, 9, 10, 8, 13, 12, 14) { $tree->insert($value => $value); } my $visualize = Tree::Visualize->new($tree, 'ASCII', 'Diagonal'); print $visualize->draw(); # (7)-------------(11)-----(13)-(14) # | | | # | | (12) # | | # | (9)-(10) # | | # | (8) # | # (3)-----(5)-(6) # | | # | (4) # | # (1)-(2) # | # (0) my $tree = Tree::Simple->new("test") ->addChildren( Tree::Simple->new("test-1") ->addChildren( Tree::Simple->new("test-1-1") ), Tree::Simple->new("test-2"), Tree::Simple->new("test-3") ); my $visualize = Tree::Visualize->new($tree, 'ASCII', 'TopDown'); print $visualize->draw(); # | # +------+ # | test | # +------+ # ____________|_____________ # | | | # +--------+ +--------+ +--------+ # | test-1 | | test-2 | | test-3 | # +--------+ +--------+ +--------+ # | # | # +----------+ # | test-1-1 | # +----------+
NOTE: This is very early release alpha software
The goal of this module is to provide a means of easily visualizing trees in a number of output formats and layouts. Currently only ASCII output and a limited number of formats are supported. There is some support for output as GraphViz dot files, but that is buggy at best right now.
As I said, this is alpha software, and so please don't expect it to do all that much. Many of the classes inside are not even implemented, and few if any are documented. I am releasing this to CPAN largely as a means of self-motivation, although I can make no promises about the speed of my progress. If you find this module interesting at all and would either like to know more (or even to help in it's development) please don't hesitate contact me at the email address listed below in the AUTHOR section.
This module really only draws Tree::Simple, Tree::Binary and Tree::Binary::Search objects currently. However through the use of some of the conversion Visitors in the Tree::Simple::VisitorFactory module, a number of other tree styles can be first converted, then visualized.
The algorithms for drawing binary and n-ary trees in a top-down layout (as illustrated above in the SYNOPSIS section) have been severely tested with randomly generated trees and have proven to be quite accurate and stable. The algorithm for the diagonal binary tree has not be tested as thoroughly, but so far has proven to be equally as stable as well. I have a few other layouts planned (left-side, right-side and bottom-up) but none of them has been implemented yet.
At this point, none of the drawing algorithms are space efficient, they are concerned more with accurate drawing then with space efficiency. Future work includes trying to develop some space optimizing algorithms.
Given a $tree_to_visualize with a specified $output_format and $layout_stype, this will return a Tree::Visualize instance ready to be drawn into a string.
$tree_to_visualize
$output_format
$layout_stype
This will call draw on the underlying Tree::Visualize::Layout::ILayout instance and then return a string.
draw
The list is to large for the moment, as this is early release alpha software here. Lets put it this way, most of the classes are not even implemented yet.
None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it.
I use Devel::Cover to test the code coverage of my tests, this section will have the Devel::Cover report on this module test suite once this module is more developed.
stevan little, <stevan@iinteractive.com>
Copyright 2004 by Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Tree::Visualize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Visualize
CPAN shell
perl -MCPAN -e shell install Tree::Visualize
For more information on module installation, please visit the detailed CPAN module installation guide.