1. Gregory Petukhov
  2. jspr

Commits

Gregory Petukhov  committed 086cfa5

Implement load scheme via URL

  • Participants
  • Parent commits eac6f64
  • Branches default

Comments (0)

Files changed (2)

File index.html

View file
 <script src="static/bootstrap/js/bootstrap.min.js"></script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
 <script type="text/javascript" src="static/jsplumb-1.3.16/js/jquery.jsPlumb-1.3.16-all.js"></script>
-<script type="text/javascript" src="static/js/util.js?4"></script>
+<script type="text/javascript">
+    var num = Math.random();
+    document.write('<script type="text/javascript" src="static/js/util.js?' + num + '"></sc' + 'ript>');
+</script>
 <!--<script type="text/javascript" src="static/js/jquery.the-modal.js"></script>-->
 </head>
 <body>
                 </div>
                 <div class="modal-body">
                     <form class="form-horizontal">
+                        <label>Get shema as code</label>
                         <textarea name="dump-area" class="span5" rows="5"></textarea>
+                        <br/><br/>
+                        <label>or as URL</label>
+                        <input name="dump-url" class="span5" rows="5"/>
                     </form>
                 </div>
                 <div class="modal-footer">
         </div>
         <div class="span2">
             <h3>Statistics</h3>
-            <div id="missed-rank">Missed rank: <span class="label label-success value">0</span></div>
+            <div id="total-rank">Total rank: <span class="label label-info value">0</span></div>
+            <div id="system-rank">System rank: <span class="label label-success value">0</span></div>
+            <div id="missed-rank">Missed rank: <span class="label label-warning value">0</span></div>
             <h3>Credits</h3>
             <ul class="unstyled">
                 <li><a href="http://twitter.github.com/bootstrap/index.html">Twitter Bootstrap</a></li>

File static/js/util.js

View file
 var connections = {};
 var initialOffset = [0, 0];
 var missedRank = 0;
+var totalRank = 1;
+var systemRank = 1;
 
 function getRandomInt(min, max) {
   return Math.floor(Math.random() * (max - min + 1)) + min;
 }
 
+function roundFloat(val, prec) {
+    var mult = Math.pow(10, prec);
+    return Math.round(val * mult) / mult
+}
+
 function filter_array(array, value) {
     new_values = []
     $.each(array, function(idx, new_value) {
     //}
     $.each(pageRegistry, function(pid, page) {
         //page.rank = ranks[pid];
-        page.rank = 1/N;
+        page.rank = totalRank/N;
         page.rank_new = 0;
     });
 
     }
 
     var D = 0.15;
-    missedRank = 0;
 
     for(var x=0; x<iterationCount; x++) {
         $.each(pageRegistry, function(pid, page) {
                     dst.rank_new += rank_share;
                 });
             } else {
-                missedRank += (1 - D) * page.rank;
+                /*missedRank += (1 - D) * page.rank;*/
             }
         });
         $.each(pageRegistry, function(pid, page) {
         });
     }
 
-    missedRank = Math.round(missedRank * 1000) / 1000;
+    //missedRank = Math.round(missedRank * 1000) / 1000;
+
+
+    systemRank = 0;
     $.each(pageRegistry, function(pid, page) {
-        page.rank = Math.round(page.rank * 1000) / 1000;
+        systemRank += page.rank;
+        page.rank = roundFloat(page.rank, 3);
     });
+    missedRank = totalRank - systemRank;
+
+    missedRank = roundFloat(missedRank, 3);
+    systemRank = roundFloat(systemRank, 3);
+    totalRank = roundFloat(totalRank, 3);
+
     refreshPageInfo();
 }
 
         node.find('.pr').text(page.rank);
     });
     $('#missed-rank .value').text(missedRank);
+    $('#system-rank .value').text(systemRank);
+    $('#total-rank .value').text(totalRank);
 }
 
 function resetAll() {
 function openDumpWindow() {
     var dump = dumpScheme();
     $('textarea[name="dump-area"]').text(dump);
+    var url = location.protocol + '//' + location.host + location.pathname +
+        '#scheme=' + $.trim(dump);
+    $('input[name="dump-url"]').val(url);
     $('#dumpWindow').modal('show');
 }
 
     });
     $.each(pages, function(page_num, page) {
         src_id = 'page' + page_num;
-        $.each(page.l, function(idx, ext_num) {
-            var ext_id = 'page' + ext_num;
-            makeConnection({'sourceId': src_id, 'targetId': ext_id});
-        });
+        if (page.l) {
+            ext_numbers = page.l.split(',');
+            $.each(ext_numbers, function(idx, ext_num) {
+                var ext_id = 'page' + ext_num;
+                makeConnection({'sourceId': src_id, 'targetId': ext_id});
+            });
+        }
     });
 }
 
+function getHashArgument(key) {
+    var hash = location.hash;
+    var rex = new RegExp(key + '=([^&]+)');
+    var match = hash.match(rex);
+    if (match === null) {
+        return null;
+    } else {
+        return match[1];
+    }
+}
+
 $(function() {
     jsPlumb.bind('jsPlumbConnectionDetached', function(res) {
         var cid = res.sourceId + res.targetId;
             breakConnection(res);
         }
     });
-    p1 = createNewPage(1, [0, 0]);
-    p2 = createNewPage(2, [300, 0]);
-    p3 = createNewPage(3, [0, 100]);
-    p4 = createNewPage(4, [300, 100]);
-    p5 = createNewPage(5, [0, 200]);
-    makeConnection({'sourceId': p1.id, 'targetId': p2.id})
-    makeConnection({'sourceId': p1.id, 'targetId': p3.id})
-    makeConnection({'sourceId': p3.id, 'targetId': p5.id})
-    makeConnection({'sourceId': p3.id, 'targetId': p4.id})
-    makeConnection({'sourceId': p2.id, 'targetId': p4.id})
+    
+    //loadFromDump("{ '1':{ 'x':'0','y':'0','l':'2,3'},'2':{ 'x':'300','y':'0','l':'4,1'},'3':{ 'x':'0','y':'100','l':'5,4,1'},'4':{ 'x':'300','y':'100','l':'1'},'5':{ 'x':'0','y':'200','l':''}}");
+    //
+     
+    var scheme = getHashArgument('scheme')
+    if (scheme) {
+        loadFromDump(scheme);
+    } else {
+        p1 = createNewPage(1, [0, 0]);
+        p2 = createNewPage(2, [300, 0]);
+        p3 = createNewPage(3, [0, 100]);
+        p4 = createNewPage(4, [300, 100]);
+        p5 = createNewPage(5, [0, 200]);
+        makeConnection({'sourceId': p1.id, 'targetId': p2.id})
+        makeConnection({'sourceId': p1.id, 'targetId': p3.id})
+        makeConnection({'sourceId': p3.id, 'targetId': p5.id})
+        makeConnection({'sourceId': p3.id, 'targetId': p4.id})
+        makeConnection({'sourceId': p2.id, 'targetId': p4.id})
 
-    makeConnection({'sourceId': p2.id, 'targetId': p1.id})
-    makeConnection({'sourceId': p3.id, 'targetId': p1.id})
-    makeConnection({'sourceId': p4.id, 'targetId': p1.id})
+        makeConnection({'sourceId': p2.id, 'targetId': p1.id})
+        makeConnection({'sourceId': p3.id, 'targetId': p1.id})
+        makeConnection({'sourceId': p4.id, 'targetId': p1.id})
+    }
+
     calculatePageRank();
 });