]> git.eli173.com Git - graphbyhand/commitdiff
Adds dot output
authoreli173 <eli@eli173.com>
Tue, 29 Sep 2015 03:37:26 +0000 (22:37 -0500)
committereli173 <eli@eli173.com>
Tue, 29 Sep 2015 03:37:26 +0000 (22:37 -0500)
.gitignore
graph.js
index.html

index cb882f0837fe3de4eb570f5712042b805da8cc99..3e0856750bed90ee4cc917083fb49f9fa3f410d1 100644 (file)
@@ -2,3 +2,4 @@
 /index.html~
 /style.css~
 /README~
+/js_generated.dot
index a87ac4d94ed0ba34feeec7eaf39d78c3e6724087..bc982c554218075f6104f3b0aa673633ed2ca92a 100644 (file)
--- a/graph.js
+++ b/graph.js
@@ -24,6 +24,12 @@ var main = function() {
     document.getElementById("fmt").onclick = function(e) {
        ezformatter(canvas);
     }
+    document.getElementById("dot").onclick = function(e) {
+       dot_format(canvas);
+    }
+    document.getElementById("ddl").onclick = function(e) {
+       dot_file(canvas);
+    }
     document.getElementById("label").onkeypress = function(e) {
        if(e.key="Enter") {
            submit()
@@ -196,6 +202,38 @@ var ezformatter = function(canvas) {
 }
 
 
+var dot_format = function(canvas) {
+    dot_str = dot_format_str(canvas);
+    document.getElementById("results").value = dot_str;
+    document.getElementById("results").style.display = "block";
+
+}
+
+var dot_file = function(canvas) {
+    var dot_str = dot_format_str(canvas);
+    var a = window.document.createElement('a');
+    a.href = window.URL.createObjectURL(new Blob([dot_str],{type: 'text/plain'}));
+    a.download = 'js_generated.dot';
+    a.style.display = "block";
+    document.body.appendChild(a);
+    a.click();
+    document.body.removeChild(a);
+    
+}
+
+var dot_format_str = function(canvas) {
+    var retstr = "graph output {\n"
+    var useids = document.getElementById("idlblid").checked;
+    canvas.forEachObject(function(o) {
+       if(o.type=='Edge') {
+           retstr = retstr.concat("\t"+o.vertices[0].id+" -- "
+                                  +o.vertices[1].id+";\n");
+       }
+    });
+    retstr = retstr.concat("}");
+    return retstr;
+}
+
 var Vertex = fabric.util.createClass(fabric.Circle, {
     type: 'Vertex',
     initialize: function(options) {
index fef7293f491b605247f3d683e744d7f35d6e51de..2e67a6c2665a54460c33c8e886b1e0411ab6acc5 100644 (file)
@@ -36,6 +36,8 @@
             id="idlbllbl">
       <label for="idlbllbl">Use user-given labels</label><br/>
       <button id="fmt">Get representation</button><br/>
+      <button id="dot">Get dot format</button><br/>
+      <button id="ddl">Download dot file</button><br/>
       <textarea name="results" id="results" rows="10" cols="50" style="display:none"></textarea>
       note: in order to get proper results when using user-provided labels, it's essential that you label each vertex uniquely.
     </div>