Tree::Visualize is a Perl module for visualizing Tree structures.
SYNOPSIS
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.
Product's homepage
Requirements:
· Perl