From: eli173 Date: Tue, 29 Sep 2015 03:37:26 +0000 (-0500) Subject: Adds dot output X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=2d58ff0c8d75e273fc3c2e3b1cf469e9e13d0f4b;p=graphbyhand Adds dot output --- diff --git a/.gitignore b/.gitignore index cb882f0..3e08567 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /index.html~ /style.css~ /README~ +/js_generated.dot diff --git a/graph.js b/graph.js index a87ac4d..bc982c5 100644 --- 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) { diff --git a/index.html b/index.html index fef7293..2e67a6c 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,8 @@ id="idlbllbl">

+
+
note: in order to get proper results when using user-provided labels, it's essential that you label each vertex uniquely.