From: Benjamin Auder Date: Wed, 7 Feb 2018 01:16:06 +0000 (+0100) Subject: Option to show dot input without running graphviz X-Git-Url: https://git.auder.net/doc/current/%7B%7B%20asset%28%27mixstore/images/js/%7B%7B%20pkg.url%20%7D%7D?a=commitdiff_plain;h=55eb65a256cca97da913831fe50263910ab93f30;p=erdiag.git Option to show dot input without running graphviz --- diff --git a/TODO b/TODO deleted file mode 100644 index eda158d..0000000 --- a/TODO +++ /dev/null @@ -1 +0,0 @@ -Fix bug 1,1 -- 1,n --> attribute type when creating foreign key diff --git a/parser.js b/parser.js index 5ef2b3f..eeafa08 100644 --- a/parser.js +++ b/parser.js @@ -1,7 +1,7 @@ // ER diagram description parser class ErDiags { - constructor(description) + constructor(description, callDot) { this.entities = { }; this.inheritances = [ ]; @@ -9,9 +9,13 @@ class ErDiags this.tables = { }; this.mcdParsing(description); this.mldParsing(); - // Cache SVG graphs returned by server (in addition to server cache = good perfs) - this.mcdGraph = ""; - this.mldGraph = ""; + this.callDot = !!callDot; + if (this.callDot) + { + // Cache SVG graphs returned by server (in addition to server cache = good perfs) + this.mcdGraph = ""; + this.mldGraph = ""; + } this.sqlText = ""; } @@ -302,7 +306,7 @@ class ErDiags { let element = document.getElementById(id); mcdStyle = mcdStyle || "compact"; - if (this.mcdGraph.length > 0) + if (!!this.mcdGraph) { element.innerHTML = this.mcdGraph; return; @@ -420,19 +424,23 @@ class ErDiags }); }); mcdDot += '}'; - //console.log(mcdDot); - ErDiags.AjaxGet(mcdDot, graphSvg => { - this.mcdGraph = graphSvg; - element.innerHTML = graphSvg; - }); + if (this.callDot) + { + // Draw graph in element + ErDiags.AjaxGet(mcdDot, graphSvg => { + this.mcdGraph = graphSvg; + element.innerHTML = graphSvg; + }); + } + else //just show dot input + element.innerHTML = mcdDot.replace(//g,">"); } // "Modèle logique des données", from MCD without anomalies - // TODO: this one should draw links from foreign keys to keys (port=... in ) drawMld(id) { let element = document.getElementById(id); - if (this.mldGraph.length > 0) + if (!!this.mldGraph) { element.innerHTML = this.mcdGraph; return; @@ -461,18 +469,22 @@ class ErDiags mldDot += '>];\n'; }); mldDot += links + '\n'; - mldDot += '}\n'; - //console.log(mldDot); - ErDiags.AjaxGet(mldDot, graphSvg => { - this.mldGraph = graphSvg; - element.innerHTML = graphSvg; - }); + mldDot += '}'; + if (this.callDot) + { + ErDiags.AjaxGet(mldDot, graphSvg => { + this.mldGraph = graphSvg; + element.innerHTML = graphSvg; + }); + } + else + element.innerHTML = mldDot.replace(//g,">"); } fillSql(id) { let element = document.getElementById(id); - if (this.sqlText.length > 0) + if (!!this.sqlText) { element.innerHTML = this.sqlText; return; @@ -499,7 +511,6 @@ class ErDiags }); sqlText += "\n);\n"; }); - //console.log(sqlText); this.sqlText = sqlText; element.innerHTML = "
" + sqlText + "
"; }