From: Tim Bunce Date: Wed, 19 Sep 2012 09:44:28 +0000 (+0100) Subject: single-child node merging working X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f9d8678b3c36613155a92def12743761cd14e00c;p=p5sagit%2FDevel-Size.git single-child node merging working --- diff --git a/static/MemView.pl b/static/MemView.pl index e17f344..204853a 100755 --- a/static/MemView.pl +++ b/static/MemView.pl @@ -42,50 +42,39 @@ 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 _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}) { + if ($node->{child_seqns}) { my @child_seqns = split /,/, $node->{child_seqns}; my $children; - if (@child_seqns == -1) { + if (@child_seqns == 1) { my $child = _fetch_node_tree($child_seqns[0], $depth); # same depth - _merge_child_into_node($node, $child); + # merge node into child + # XXX id, depth, parent_seqn + warn "Merged $node->{name} #$node->{id} with only child $child->{name} #$child->{id}\n"; + $child->{name} = "$node->{name} + $child->{name}"; + $child->{$_} += $node->{$_} for (qw(self_size)); + $child->{$_} = $node->{$_} for (qw(parent_seqn)); + $node = $child; } - else { + elsif ($depth) { $children = [ map { _fetch_node_tree($_, $depth-1) } @child_seqns ]; + $node->{children} = $children; + $node->{child_count} = @$children; } - $node->{children} = $children; - $node->{child_count} = @$children; } return $node; } -sub _transform_node_tree { # depth first +sub _transform_node_tree { # recurse depth first my ($node, $transform) = @_; if (my $children = $node->{children}) { $_ = _transform_node_tree($_, $transform) for @$children; diff --git a/static/public/.tm.js.swp b/static/public/.tm.js.swp index 3705dcb..d77f1b1 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 db4dfd2..0bb0dd8 100644 --- a/static/public/tm.js +++ b/static/public/tm.js @@ -36,7 +36,7 @@ function init(){ //show only one tree level levelsToShow: 2, //parent box title heights - titleHeight: 0, + titleHeight: 10, //enable animations animate: animate, //box offsets @@ -114,6 +114,7 @@ function init(){ if (data.child_count) { html += sprintf("Children: %d of %d
", data.child_count, data.kids_node_count); } + html += JSON.stringify(data, undefined, 4); tip.innerHTML = html; } @@ -126,6 +127,8 @@ function init(){ request: function(nodeId, level, onComplete){ if (true) { jQuery.getJSON('jit_tree/'+nodeId+'/1', function(data) { + console.log("Node "+nodeId); + console.log(data); onComplete.onComplete(nodeId, data); }); } @@ -145,7 +148,7 @@ function init(){ if(true) { jQuery.getJSON('jit_tree/1/1', function(data) { - console.log(data); + console.log(data); tm.loadJSON(data); tm.refresh(); });