]> khamidou — GitHub mirrors - Projet_IC05.git/commitdiff
passé totalement à sigma.
authorkarim hamidou <khamidou@gmail.com>
Wed, 12 Dec 2012 19:53:10 +0000 (20:53 +0100)
committerkarim hamidou <khamidou@gmail.com>
Wed, 12 Dec 2012 19:53:10 +0000 (20:53 +0100)
js/index.html
js/js/main.js

index b19af4192e8a0809431d88f088c24b7403cc8d66..4147ea7e957f58d912fcd7eaab3caf3eee3b2a7d 100755 (executable)
         <link rel="stylesheet" href="css/normalize.min.css">
         <link rel="stylesheet" href="css/main.css">
 
-        <script src="js/vendor/modernizr-2.6.1.min.js"></script>
-        <script src="js/vendor/sigma.min.js"></script>
-        <script src="js/vendor/raphael.min.js"></script>
-        <script src="js/vendor/harry.min.js"></script>
-        <script src="js/vendor/d3.v2.min.js"></script>
-    </head>
+        </head>
     <body>
         <!--[if lt IE 7]>
             <p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
@@ -46,6 +41,9 @@
         </div>
         <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
         <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.2.min.js"><\/script>')</script>
+        <script src="js/vendor/sigma.min.js"></script>
+        <script src="js/vendor/sigma.forceatlas2.js"></script>
+
         <script src="js/plugins.js"></script>
         <script src="js/main.js"></script>
 
index da0312d85be9d662aaf69fddb7edde7e540b9119..c29020217e57a1d87165707784a8f8251d403aa3 100755 (executable)
@@ -1,5 +1,4 @@
 $(document).ready(function() {
-    $(".ppButton").click(handlePlayPause);
     $.ajax("full.json", {success :setup});
     /*
     window.setTimeout(step1, 2000);
@@ -18,118 +17,55 @@ function setup(json) {
 
     var sigRoot = $('#graphWrapper').get(0);
     var sigInst = sigma.init(sigRoot);
-    sigInst.addNode('hello',{
-          label: 'Hello',
-          color: '#ff0000'
-    }).addNode('world',{
-          label: 'World !',
-      color: '#00ff00'
-    }).addEdge('hello_world','hello','world').draw();
-    
+    sigInst.graphProperties({minNodeSize: 1, maxNodeSize: 50});
+   
+    draw(jsonData, sigInst);
     return;
-
-    var w = 760,
-        h = 500;
-
-    force = d3.layout.force()
-        .gravity(.01)
-        .distance(400)
-        .charge(-30)
-        .size([w, h]);
-
-    nodes = force.nodes(),
-    links = force.links();
-            
-    vis = d3.select("#graphCanvas").append("svg:svg")
-        .attr("width", w)
-        .attr("height", h);
-
-    force.on("tick", function() {
-      vis.selectAll("g.node")
-          .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
-
-      vis.selectAll("line.link")
-          .attr("x1", function(d) { return d.source.x; })
-          .attr("y1", function(d) { return d.source.y; })
-          .attr("x2", function(d) { return d.target.x; })
-          .attr("y2", function(d) { return d.target.y; });
-    });
-    //step2();
-    stepN();
-}
-
-function restart() {
-  var link = vis.selectAll("line.link")
-      .data(links, function(d) { return d.source.id + "-" + d.target.id; });
-/*
-  link.enter().insert("svg:line", "g.node")
-      .attr("stroke", "white")
-      .transition().duration(4000)
-      .attr("stroke", "black");
-
-  link.exit().remove();
-*/
-  var node = vis.selectAll("g.node")
-      .data(nodes, function(d) { return d.id;});
-       
-  var nodeEnter = node.enter().append("svg:g")
-      .attr("class", "node")
-      .call(force.drag);
-  
-  nodeEnter.append("svg:text")
-      .attr("dx", 12)
-      .attr("dy", ".35em")
-      .text(function(d) { return d.id })
-      .transition()
-      .attr("class", "nodetext")
-
-  nodeEnter.append("svg:title")
-      .text("pkpmlkmlkmlk http://reddit.com");
-       
-  nodeEnter.append("circle")
-      .attr("class", "circle")
-      .attr("r", "5")
-      .attr("fill", "white")
-      .attr("stroke", "none")
-      .attr("x", "-8px")
-      .attr("y", "-8px")
-      .attr("width", "16px")
-      .attr("height", "16px")
-      .transition()
-      .duration(2500)
-      .attr("class", "fully_visible")
-      .attr("r", "10")
-
-  node.exit().remove();
-               
-  force.start();
 }
 
-// Add three nodes and three links.
-function step1() {
-  var a = {id: "aaa"}, b = {id: "bbb", weight: 45}, c = {id: "ccc"};
-  nodes.push(a, b, c);
-  links.push({source: a, target: b}, {source: a, target: c}, {source: b, target: c});
-
-
-
-  restart();
-}
+function draw(data, sigInst) {
+    var created_nodes = {}
+    for(var i = 0; i < data["nodes"].length; i++) {
+        var size = data["nodes"][i]["nodeScore"]; 
+        var name =data["nodes"][i]["nodeName"]; 
+        
+        var color = "#c00"; // user
+        if(name.split(".").length > 1)
+            color = "#00c"; // site web
+ 
+        if(size > 2) {
+            sigInst.addNode(name, {x: Math.random(), y: Math.random(), size: size, color: color});
+            created_nodes[name] = 1;
+        }
+    }
+    
+    for(var i = 0; i < data["edges"].length; i++) {
+        var source = data["edges"][i]["source"]; 
+        var dest = data["edges"][i]["destination"]; 
+        if(created_nodes[source] == 1 && created_nodes[dest] == 1)
+            sigInst.addEdge(i, source, dest);
+    }
 
-function step2() {
-  var a = {id: "aa"}, b = {id: "bb", weight : 45}, c = {id: "cc"}, d = {id: "dd"};
-  nodes.push(a, b, c, d);
-  console.log(links);
-  links.push({source: a, target: b}, {source: a, target: c}, {source: b, target: c});
-  restart();
-  console.log(links[3], links[0]);
-  links.push({source: nodes[0], target: a});  
-  restart();
-}
 
-function step3() {
-   nodes.pop(); 
-   restart();
+    sigInst.startForceAtlas2();
+     
+      var isRunning = true;
+      document.getElementById('stop-layout').addEventListener('click',function(){
+        if(isRunning){
+          isRunning = false;
+          sigInst.stopForceAtlas2();
+          document.getElementById('stop-layout').childNodes[0].nodeValue = 'Start Layout';
+        }else{
+          isRunning = true;
+          sigInst.startForceAtlas2();
+          document.getElementById('stop-layout').childNodes[0].nodeValue = 'Stop Layout';
+        }
+      },true);
+      document.getElementById('rescale-graph').addEventListener('click',function(){
+        sigInst.position(0,0,1).draw();
+      },true);
+    
+      sigInst.draw();
 }
 
 var displayed = [];
@@ -201,17 +137,3 @@ function stepN() {
     restart();
     count += NUMELEMENTS;
 }
-
-var mode = "PAUSED";
-
-function handlePlayPause() {
-    if(mode == "PAUSED") {
-        mode = "PLAYING";
-        $(".ppButton").attr("src", "imgs/pause_24.png"); 
-    } else {
-        mode = "PAUSED";
-        $(".ppButton").attr("src", "imgs/play_24.png"); 
-    }
-
-    stepN();
-}