Commits

Frederic De Groef  committed 62aacc3

new data

  • Participants
  • Parent commits cab2d5f

Comments (0)

Files changed (1)

File test_sigma_gexf.js

-function makeListFromAttrs(attr) {
-  var attrWhiteList = ['author', 'title', 'url', 'date'];
 
-  return '<ul>' +
-    attr.map(function(o){
-      if(attrWhiteList.indexOf(o.attr) != -1){
-        return '<li>' + o.attr + ' : ' + o.val + '</li>';
-      } else {
-        return '';
-      }
-    }).join('') +
-    '</ul>';
+
+function getAttrValue(attributes, attrName) {
+  return attributes.map(function(o){
+    if(o.attr == attrName){
+      return o.val;
+    } else {
+      return '';
+    }
+  }).join('');
 };
 
 
+function makePrettyListFromAttr(attr) {
+  var ul = '<ul>';
+
+
+  ul +=  '<li> Title: ' + getAttrValue(attr, 'title') + '</li>';
+  ul +=  '<li> Author: ' + getAttrValue(attr, 'author') + '</li>';
+  var url = getAttrValue(attr, 'url');
+  ul +=  '<li> URL: ' + '<a href="'+ url + '"  target="_blank">'+ url + '</a></li>';
+  ul +=  '<li> Date: ' + getAttrValue(attr, 'date') + '</li>';
+
+  return ul + '</ul>';
+};
+
+
+
+
 
 
 function init() {
+
   // Instanciate sigma.js and customize rendering :
-  var sigInst = sigma.init(document.getElementById('sigma-example')).drawingProperties({
+  var sigma_canvas = document.getElementById('sigma-example');
+
+  var sigInst = sigma.init(sigma_canvas).drawingProperties({
     defaultLabelColor: '#fff',
     defaultLabelSize: 10,
     defaultLabelBGColor: '#fff',
     minEdgeSize: 1,
     maxEdgeSize: 2
   }).mouseProperties({
-    maxRatio: 32
+    maxRatio: 4,
+    minRatio: 0.6
   });
 
   // Parse a GEXF encoded file to fill the graph
   },[event.content[0]]);
 
   var infos_div = document.getElementById("node_infos");
-  var attributes = makeListFromAttrs(node['attr']['attributes']);
+  var attributes = makePrettyListFromAttr(node['attr']['attributes']);
   infos_div.innerHTML = '<div>'
-          + '<h4> Node: '+ event.content[0] +'</h4>'
+          + '<h4> Details: </h4>'
           + attributes
           + '</div>';
 
   sigInst.bind('overnodes',showNodeInfo);
 
 
+  console.log(sigma_canvas.getElementsByTagName('canvas')[0].getAttribute('width'));
+  var w, h;
+  w = parseInt(sigma_canvas.getElementsByTagName('canvas')[0].getAttribute('width'));
+  h = parseInt(sigma_canvas.getElementsByTagName('canvas')[0].getAttribute('height'));
   // Draw the graph :
-  sigInst.draw();
+  sigInst.zoomTo(w/2, h/2, 0.9).draw();
+
+
+
+
+  var enabled_years = [];
+  function makeYearCheckboxes(start, stop){
+    var html = '';
+
+    for (year=start; year <= stop; year=year+1)
+    {
+      html += '<input type="checkbox" name="year" checked="true" value="'+ year +'">'+ year +'<br>';
+      enabled_years.push(''+year);
+    }
+
+    html += '<input type="checkbox" name="year" checked="true" value="'+ 'nd' +'">'+ 'No Date' +'<br>';
+    enabled_years.push('nd');
+
+
+    return html;
+  };
+
+
+  var year_selection_form = document.getElementById('select_year_form');
+  year_selection_form.innerHTML = makeYearCheckboxes(1997, 2012);
+
+  $(':checkbox').live('change', function(){
+    if(this.checked){
+      enabled_years.push(this.value);
+    } else {
+      var idx = enabled_years.indexOf(this.value);
+      enabled_years.splice(idx, 1);
+    }
+    console.log(enabled_years);
+
+    sigInst.iterNodes(function (n){
+        var node_attrs = n['attr']['attributes'];
+        var node_year = getAttrValue(node_attrs, 'year');
+
+        //console.log(''+  getAttrValue(node_attrs, 'year'))
+        if (enabled_years.indexOf(node_year) == -1){
+          // console.log('hiding: '+getAttrValue(node_attrs, 'title') + '   ' + node_year);
+          n.hidden = 1;
+        } else {
+          // console.log('showing: '+getAttrValue(node_attrs, 'title') + '   ' + node_year );
+          n.hidden = 0;
+        }
+
+      }).draw();
+
+
+  });
+
+
 }
 
 if (document.addEventListener) {