From 553a632aa4556740090cc3278f021f41100ba646 Mon Sep 17 00:00:00 2001
From: eli173 <eli@eli173.com>
Date: Sat, 29 Aug 2015 22:55:32 -0500
Subject: [PATCH] some formatting stuff

---
 graph.js   | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 index.html | 27 +++++++++++++++++++++++++--
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/graph.js b/graph.js
index 00232ef..276d28b 100644
--- 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) {
diff --git a/index.html b/index.html
index 4414c46..f8887a5 100644
--- a/index.html
+++ b/index.html
@@ -19,10 +19,33 @@
       <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>
+
+
-- 
2.39.5