html export : not ready
[iramuteq] / webexport / graphe.html
diff --git a/webexport/graphe.html b/webexport/graphe.html
new file mode 100644 (file)
index 0000000..348c8a3
--- /dev/null
@@ -0,0 +1,194 @@
+<html class="no-js" lang="en">
+<head>
+<meta charset="utf-8" />
+  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+  <title>%(titre)s</title>
+<script src="js/jquery.min.js"></script>
+<script src="js/sigma.min.js"></script>
+<script src="js/sigma.fisheye.js"></script>
+<script src="js/sigma.parseGexf.js"></script>
+</head>
+<body>
+<div class="container">
+    <div class="row">
+  <h2 class="span12" id="post-title">Load and display a GEXF encoded graph</h2>
+  
+  <div class="span12 sigma-parent" id="sigma-example-parent">
+    <div class="sigma-expand" id="sigma-example"></div>
+  </div>
+</div>
+
+<script type="text/javascript">
+function init() {
+  // Instanciate sigma.js and customize rendering :
+  //var sigInst = sigma.init(document.getElementById('sigma-example')).drawingProperties({
+  var sigInst = sigma.init($('#sigma-example')[0]).drawingProperties({
+    defaultLabelColor: '#fff',
+    labelSize: 'proportional',
+    labelSizeRatio: 1,
+    //defaultLabelSize: 10,
+
+    defaultLabelBGColor: '#fff',
+    defaultLabelHoverColor: '#000',
+    labelThreshold: 4,
+    defaultEdgeType: 'curve'
+  }).graphProperties({
+    minNodeSize: 0.01,
+    maxNodeSize: 20,
+    minEdgeSize: 0.01,
+    maxEdgeSize: 1
+  }).mouseProperties({
+    maxRatio: 32
+  });
+
+  // Parse a GEXF encoded file to fill the graph
+  // (requires "sigma.parseGexf.js" to be included)
+  //sigInst.parseGexf('USA_2008_1.gexf');
+    sigInst.parseGexf('%(gexffile)s');
+//rttotgephi.gexf
+
+//attributs
+(function(){
+var popUp;
+// This function is used to generate the attributes list from the node attributes.
+// Since the graph comes from GEXF, the attibutes look like:
+// [
+// { attr: 'Lorem', val: '42' },
+// { attr: 'Ipsum', val: 'dolores' },
+// ...
+// { attr: 'Sit', val: 'amet' }
+// ]
+function attributesToString(attr) {
+    return '<ul>' +
+attr.map(function(o){
+return '<li>' + o.attr + ' : ' + o.val + '</li>';
+}).join('') +
+'</ul>';
+}
+function showNodeInfo(event) {
+    popUp && popUp.remove();
+     
+    var node;
+    sigInst.iterNodes(function(n){
+    node = n;
+    },[event.content[0]]);
+     
+    popUp = $(
+    '<div class="node-info-popup"></div>'
+    ).append(
+    // The GEXF parser stores all the attributes in an array named
+    // 'attributes'. And since sigma.js does not recognize the key
+    // 'attributes' (unlike the keys 'label', 'color', 'size' etc),
+    // it stores it in the node 'attr' object :
+    attributesToString( node['attr']['attributes'] )
+    ).attr(
+    'id',
+    'node-info'+sigInst.getID()
+    ).css({
+    'display': 'inline-block',
+    'border-radius': 3,
+    'padding': 5,
+    'background': 'rgba(200,120,0,0.6)',
+    'color': '#000',
+    'box-shadow': '0 0 4px #666',
+    'position': 'absolute',
+    'left': node.displayX,
+    'top': node.displayY+15
+    });
+    $('ul',popUp).css('margin','0 0 0 20px');
+    $('#sigma-example').append(popUp);
+}
+function hideNodeInfo(event) {
+    popUp && popUp.remove();
+    popUp = false;
+}
+var greyColor = 'rgba(255,255,255,0)';
+sigInst.bind('overnodes',function(event){
+    var node;
+    sigInst.iterNodes(function(n){
+    node = n;
+    },[event.content[0]]);
+    var nodes = [node.id]
+    var neighbors = {};
+    sigInst.iterEdges(function(e){
+        if(nodes.indexOf(e.source)<0 && nodes.indexOf(e.target)<0){
+            if(!e.attr['grey']){
+                e.attr['true_color'] = e.color;
+                e.color = greyColor;
+                e.attr['grey'] = 1;
+            }
+        }else{
+            e.color = e.attr['grey'] ? e.attr['true_color'] : e.color;
+            e.attr['grey'] = 0;
+            neighbors[e.source] = 1;
+            neighbors[e.target] = 1;
+        }
+    }).iterNodes(function(n){
+        if(!neighbors[n.id]){
+        //if(n.color != node.color) {
+            if(!n.attr['grey']){
+                n.attr['true_color'] = n.color;
+                n.color = greyColor;
+                n.attr['grey'] = 1;
+            }
+        }else{
+            n.color = n.attr['grey'] ? n.attr['true_color'] : n.color;
+            n.attr['grey'] = 0;
+        }
+    }).draw(2,2,2);
+}).bind('outnodes',function(){
+
+    sigInst.iterEdges(function(e){
+        e.color = e.attr['grey'] ? e.attr['true_color'] : e.color;
+        e.attr['grey'] = 0;
+    }).iterNodes(function(n){
+        n.color = n.attr['grey'] ? n.attr['true_color'] : n.color;
+        n.attr['grey'] = 0;
+    }).draw(2,2,2);
+});
+
+
+sigInst.bind('overnodes',showNodeInfo).bind('outnodes',hideNodeInfo).draw();
+})();
+sigInst.activateFishEye().draw();
+}
+  // Draw the graph :
+//  sigInst.draw();
+//}
+if (document.addEventListener) {
+  document.addEventListener("DOMContentLoaded", init, false);
+} else {
+  window.onload = init;
+}
+</script>
+<style type="text/css">
+  /* sigma.js context : */
+  .sigma-parent {
+    position: relative;
+    border-radius: 4px;
+    -moz-border-radius: 4px;
+    -webkit-border-radius: 4px;
+    background: #222;
+    height: 800px;
+  }
+  .sigma-expand {
+    position: absolute;
+    width: 100%%;
+    height: 100%%;
+    top: 0;
+    left: 0;
+  }
+  .buttons-container{
+    padding-bottom: 8px;
+    padding-top: 12px;
+  }
+</style>
+
+</body>
+</html>