]> git.eli173.com Git - graphbyhand/commitdiff
some formatting stuff
authoreli173 <eli@eli173.com>
Sun, 30 Aug 2015 03:55:32 +0000 (22:55 -0500)
committereli173 <eli@eli173.com>
Sun, 30 Aug 2015 03:55:32 +0000 (22:55 -0500)
graph.js
index.html

index 00232efd444023b081cdf7e05d85a753d5f60286..276d28b626e6af4a180a72839507fd6e16b1c8ec 100644 (file)
--- a/graph.js
+++ b/graph.js
@@ -21,6 +21,14 @@ var main = function() {
 
     canvas.on('mouse:down',function(o){mousedown(o,canvas)});
     canvas.on('object:moving',function(o){movement(o,canvas)});
+    document.getElementById("fmt").onclick = function(e) {
+       ezformatter(canvas);
+    }
+    document.getElementById("label").onkeypress = function(e) {
+       if(e.key="Enter") {
+           submit()
+       }
+    };
 }
 
 
@@ -150,6 +158,53 @@ var getNeighbors = function(vert,canvas) {
     return neighbors;
 }
 
+var ezformatter = function(canvas) {
+    var retstr = "";
+    var useedges = document.getElementById("radioedge").checked;
+    var useids = document.getElementById("idlblid").checked;
+    canvas.forEachObject(function(o) {
+       if(useedges && o.type == 'Edge') {
+           console.log("a");
+           if(!useids) {
+               retstr = retstr.concat("("+o.vertices[0].label+
+                                      ", "+o.vertices[1].label+") ");
+           }
+           else {
+               retstr = retstr.concat("("+o.vertices[0].id+
+                                      ", "+o.vertices[1].id+") ");
+           }
+       }
+       else if(o.type == 'Vertex') {
+           
+           
+       }
+    });
+    document.getElementById("results").value = retstr;
+    document.getElementById("results").style.display = "block";
+}
+
+var runformatter = function(canvas) {
+    retstr = "";
+    fstr = document.getElementById("formatstr").value;
+    var in_escape = false;
+    for(i=0;i<fstr.length;i++) {
+       if(in_escape) {
+           if(fstr[i]=='\\') {
+               retstr.push('\\')
+           }
+           else if(fstr[i]=='{') {
+               retstr.push('a');
+           }
+
+           in_escape = false;
+       }
+       
+
+    }
+    
+    console.log(retstr);
+}
+
 var Vertex = fabric.util.createClass(fabric.Circle, {
     type: 'Vertex',
     initialize: function(options) {
index 4414c46fd71ea7ea88c5f00ad8062f4743191bad..f8887a5f3026c001dbe947c9bd25aba9ba7f4383 100644 (file)
       <button onclick="setMode('d')">Remove</button>
     </div>
     <div id="editor" style="display: none">
-      Label: <input id="label" type="text" value=""/>
+      Label:
+      <input id="label" type="text" value=""/>
+      <input id="submitlabel" type="button" value="OK"
+            onclick="submit()" style="display:inline-block"/><br/>
       ID: <div style="display:inline-block" id="elementid"></div><br/>
       Neighbors: <div id="neighbors"></div><br/>
-      <input id="submitlabel" type="button" value="OK" onclick="submit()"/>
+
+    </div>
+    <div id="formatter">
+      Formatter<br/>
+      <input type="radio" name="eorv"
+            id="radiovert">
+      <label for="radiovert">Run on vertices</label>
+      <input type="radio" name="eorv"
+            id="radioedge">
+      <label for="radioedge">Run on edges</label><br/>
+      <input type="radio" name="idolbl"
+            id="idlblid">
+      <label for="idlblid">Use automatically generated IDs</label>
+      <input type="radio" name="idolbl"
+            id="idlbllbl">
+      <label for="idlbllbl">Use user-given labels</label><br/>
+      <textarea name="formatstr" id="formatstr"></textarea><br/>
+      <button id="fmt">Format</button><br/>
+      <textarea name="results" id="results" style="display:none"></textarea>
     </div>
   </body>
 </html>
+
+