Add switch to turn automatic layout on/off
authorHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Tue, 23 Jun 2015 13:10:26 +0000 (15:10 +0200)
committerHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Tue, 23 Jun 2015 13:10:26 +0000 (15:10 +0200)
files/netjson_viewer/netjson_view.html
files/netjson_viewer/netjson_view.js

index 01c5639..04be291 100644 (file)
@@ -34,7 +34,8 @@
 <body>
     <p>Visualization of olsrd2 netjson graph</p>
 
-    Auto Update: <input type="checkbox" id="autoupdate" onclick="checkbox_clicked();" checked="checked"/>
+    Auto Update: <input type="checkbox" id="autoupdate" onclick="autoupdate_clicked();" checked="checked"/>
+    Dynamic Layout: <input type="checkbox" id="dynamiclayout" onclick="dynamiclayout_clicked();" checked="checked"/>
 
     <div id="section">
         <div id="networkgraph"></div>
index 3246a30..df8e60c 100644 (file)
@@ -28,7 +28,7 @@ String.prototype.endsWith = function (pattern) {
     if (this.length < pattern.length) {
         return false;
     }
-    return pattern == this.substring(-pattern.length);
+    return pattern == this.substring(this.length - pattern.length);
 };
 
 function init_network() {
@@ -168,14 +168,14 @@ function layout_edges(element) {
         var edge = undirectedEdges[newIds[ei]];
         var label = "";
         
-        var flen = edge.fromLabel.length - common_edge_postfix.length;
-        var tlen = edge.toLabel.length - common_edge_postfix.length;
-        
         if (edge.fromLabel == edge.toLabel) {
             label = edge.fromLabel;
         }
         else if (edge.fromLabel.endsWith(common_edge_postfix)
                 && edge.fromLabel.endsWith(common_edge_postfix)) {
+            var flen = edge.fromLabel.length - common_edge_postfix.length;
+            var tlen = edge.toLabel.length - common_edge_postfix.length;
+        
             label = edge.fromLabel.substring(0, flen).trim() + "/"
                 + edge.toLabel.substring(0, tlen).trim()
                 + " " + common_edge_postfix;             
@@ -251,7 +251,7 @@ function xmlhttp_changed()
     }
 }
 
-function checkbox_clicked() {
+function autoupdate_clicked() {
     var checkbox = document.getElementById("autoupdate");
     if (checkbox.checked === false) {
         window.clearTimeout(autoupdate_timeout);
@@ -261,6 +261,12 @@ function checkbox_clicked() {
     }    
 }
 
+function dynamiclayout_clicked() {
+    var checkbox = document.getElementById("dynamiclayout");
+    
+    visNetwork.setOptions({physics:checkbox.checked})
+}
+
 function send_request() {
     xmlhttp.open("GET",netjsonurl,true);
     xmlhttp.send();