From: Tim Bunce Date: Wed, 19 Sep 2012 08:55:47 +0000 (+0100) Subject: split transform nodes away from fetch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=875c10733686e859136cbfc901941edc60933b94;p=p5sagit%2FDevel-Size.git split transform nodes away from fetch --- diff --git a/static/MemView.pl b/static/MemView.pl index b4bb73e..e17f344 100755 --- a/static/MemView.pl +++ b/static/MemView.pl @@ -26,10 +26,11 @@ get '/jit_tree/:id/:depth' => sub { 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}, @@ -41,24 +42,57 @@ get '/jit_tree/:id/:depth' => sub { 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__ diff --git a/static/public/.tm.js.swp b/static/public/.tm.js.swp index 1974839..3705dcb 100644 Binary files a/static/public/.tm.js.swp and b/static/public/.tm.js.swp differ diff --git a/static/public/tm.js b/static/public/tm.js index 5f5b36d..db4dfd2 100644 --- a/static/public/tm.js +++ b/static/public/tm.js @@ -34,7 +34,7 @@ function init(){ //where to inject the visualization injectInto: 'infovis', //show only one tree level - levelsToShow: 1, + levelsToShow: 2, //parent box title heights titleHeight: 0, //enable animations @@ -125,7 +125,7 @@ function init(){ //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); }); } @@ -144,7 +144,7 @@ function init(){ }); 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();