Make levelsToShow more variable
[p5sagit/Devel-Size.git] / static / public / tm.js
index 6576b3a..6119410 100644 (file)
@@ -45,15 +45,20 @@ function bySortedValue(obj, comparitor, callback, context) {
 
 
 
+function request_jit_tree(nodeId, level, depth, onComplete){
+    var params = { logarea: 1 };
+    jQuery.getJSON('jit_tree/'+nodeId+'/'+depth, params, onComplete);
+}
+
+
 function init(){
-  //init data
-  //end
+  var levelsToShow = 2;
   //init TreeMap
   var tm = new $jit.TM.Squarified({
     //where to inject the visualization
     injectInto: 'infovis',
     //show only one tree level
-    levelsToShow: 1,
+    levelsToShow: levelsToShow,
     //parent box title heights
     titleHeight: 11,
     //enable animations
@@ -115,9 +120,11 @@ function init(){
       //add content to the tooltip when a node
       //is hovered
       onShow: function(tip, node, isLeaf, domElement) {
-        var html = "<div class=\"tip-title\">" + node.name 
-          + "</div><div class=\"tip-text\">";
         var data = node.data;
+        var html = "<div class=\"tip-title\">"
+          + (data.title ? data.title : "")
+          + " " + data.name
+          + "</div><div class=\"tip-text\">";
 
         html += "<br />";
         html += sprintf("Size: %d (%d + %d)<br />", data.self_size+data.kids_size, data.self_size, data.kids_size);
@@ -131,6 +138,7 @@ function init(){
             html += "<br />";
         }
 
+
         html += sprintf("Attributes:<br />");
         bySortedValue(data.attr,
             function(a, b) { return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0 },
@@ -145,6 +153,9 @@ function init(){
         html += sprintf("Depth: %d<br />", data.depth);
         html += sprintf("Parent: %d<br />", data.parent_id);
 
+        html += JSON.stringify(data.attr, undefined, 4);
+        //html += JSON.stringify(data, undefined, 4);
+
         tip.innerHTML =  html; 
       }  
     },
@@ -154,19 +165,11 @@ function init(){
     //call for the requested subtree. When completed, the onComplete   
     //callback method should be called.  
     request: function(nodeId, level, onComplete){  
-        if (true) {
-            jQuery.getJSON('jit_tree/'+nodeId+'/1', function(data) {
-                console.log("Node "+nodeId);
+            request_jit_tree(nodeId, level, levelsToShow, function(data) {
+                console.log("Fetched node "+nodeId);
                 console.log(data);
                 onComplete.onComplete(nodeId, data);  
             });
-        }
-        else {
-            var tree = memnodes[0];
-            var subtree = $jit.json.getSubtree(tree, nodeId);  
-            $jit.json.prune(subtree, 2);  
-            onComplete.onComplete(nodeId, subtree);  
-        }
     },
     //Add the name of the node in the corresponding label
     //This method is called once, on label creation and only for DOM labels.
@@ -174,26 +177,17 @@ function init(){
         domElement.innerHTML = node.name;
     }
   });
-  
-if(true) {
-    jQuery.getJSON('jit_tree/1/1', function(data) {
+
+  request_jit_tree(1, 0, levelsToShow, function(data) {
         console.log(data);
         tm.loadJSON(data);
         tm.refresh();
     });
-}
-else {
-  //var pjson = eval('(' + json + ')');  
-  var pjson = memnodes[0];
-  $jit.json.prune(pjson, 2);
-  console.log(pjson);
-  tm.loadJSON(pjson);
-  tm.refresh();
-}
 
-  //add event to the back button
-  var back = $jit.id('back');
-  $jit.util.addEvent(back, 'click', function() {
-    tm.out();
-  });
+    //add event to buttons
+    $jit.util.addEvent($jit.id('back'), 'click', function() { tm.out() });
+    $jit.util.addEvent($jit.id('logarea'), 'onchange', function() { tm.refresh() });
+
 }
+
+