From 2d58ff0c8d75e273fc3c2e3b1cf469e9e13d0f4b Mon Sep 17 00:00:00 2001 From: eli173 Date: Mon, 28 Sep 2015 22:37:26 -0500 Subject: [PATCH] Adds dot output --- .gitignore | 1 + graph.js | 38 ++++++++++++++++++++++++++++++++++++++ index.html | 2 ++ 3 files changed, 41 insertions(+) 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. -- 2.39.2