my $id = $self->stash('id');
my $depth = $self->stash('depth');
warn "jit_tree $id $depth";
- my $jit_tree = _fetch_node($id, $depth, sub {
- my ($node, $children) = @_;
+ my $node_tree = _fetch_node_tree($id, $depth);
+ my $jit_tree = _transform_node_tree($node_tree, sub {
+ my ($node) = @_;
+ my $children = delete $node->{children}; # XXX edits the src tree
$node->{'$area'} = $node->{self_size}+$node->{kids_size};
- $node->{child_count} = @$children if $children;
my $jit_node = {
id => $node->{id},
name => $node->{name},
if(1){
use Devel::Dwarn;
use Data::Dump qw(pp);
- local $jit_tree->{children};
+# local $jit_tree->{children};
pp($jit_tree);
}
$self->render_json($jit_tree);
};
-sub _fetch_node {
- my ($id, $depth, $transform) = @_;
- my $node = MemView->selectrow_hashref("select * from node where id = ?", undef, $id);
- my $children;
+sub _merge_child_into_node {
+ my ($node, $child) = @_;
+ my $fake_data => {
+ "\$area" => 23230,
+ "child_count" => 2,
+ "child_seqns" => "1414,1496",
+ "depth" => 17,
+ "id" => 1413,
+ "kids_node_count" => 83,
+ "kids_size" => 23078,
+ "name" => "SV(PVGV)",
+ "parent_seqn" => 1412,
+ "self_size" => 152,
+ };
+
+}
+
+sub _fetch_node_tree {
+ my ($id, $depth) = @_;
+ my $node = MemView->selectrow_hashref("select * from node where id = ?", undef, $id)
+ or die "Node '$id' not found";
if ($depth && $node->{child_seqns}) {
my @child_seqns = split /,/, $node->{child_seqns};
- $children = [ map { _fetch_node($_, $depth-1, $transform) } @child_seqns ];
+ my $children;
+ if (@child_seqns == -1) {
+ my $child = _fetch_node_tree($child_seqns[0], $depth); # same depth
+ _merge_child_into_node($node, $child);
+ }
+ else {
+ $children = [ map { _fetch_node_tree($_, $depth-1) } @child_seqns ];
+ }
+ $node->{children} = $children;
+ $node->{child_count} = @$children;
}
- $node = $transform->($node, $children) if $transform;
return $node;
}
+sub _transform_node_tree { # depth first
+ my ($node, $transform) = @_;
+ if (my $children = $node->{children}) {
+ $_ = _transform_node_tree($_, $transform) for @$children;
+ }
+ return $transform->($node);
+}
+
app->start;
__DATA__
//where to inject the visualization
injectInto: 'infovis',
//show only one tree level
- levelsToShow: 1,
+ levelsToShow: 2,
//parent box title heights
titleHeight: 0,
//enable animations
//callback method should be called.
request: function(nodeId, level, onComplete){
if (true) {
- jQuery.getJSON('jit_tree/'+nodeId+'/3', function(data) {
+ jQuery.getJSON('jit_tree/'+nodeId+'/1', function(data) {
onComplete.onComplete(nodeId, data);
});
}
});
if(true) {
- jQuery.getJSON('jit_tree/1/2', function(data) {
+ jQuery.getJSON('jit_tree/1/1', function(data) {
console.log(data);
tm.loadJSON(data);
tm.refresh();