From: Benjamin Auder <benjamin.auder@somewhere> Date: Fri, 2 Feb 2018 18:43:38 +0000 (+0100) Subject: Fix bugs, MLD graphs now seem well generated X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/images/doc/html/scripts/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=b8af38fdc3c2f56ffbf4f0be715742152a3f37c8;p=erdiag.git Fix bugs, MLD graphs now seem well generated --- diff --git a/README.md b/README.md index b39f8a7..2f543b9 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ To indicate an inheritance relation, proceed as follow Animal Cat Fish Planet Mars Venus -Finally, blocks must be separated by new lines. For a usage example, see example.html (it should render as seen in example.svg) +Finally, blocks must be separated by new lines. For a usage example, see example.html (it should render as seen in example\_\*.svg) Note that the "drawMcd" method can take a second argument, which indicates the type of graph. * "bubble" draws the standard graph, as seen [here](https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#/media/File:ER_Diagram_MMORPG.png) for example diff --git a/example.html b/example.html index d5a27ac..24d8953 100644 --- a/example.html +++ b/example.html @@ -1,6 +1,12 @@ +<h2>MCD graph:</h3> <div id="mcd"></div> + +<h2>MLD graph:</h2> <div id="mld"></div> +<h2>SQL instructions:</h2> +<div id="sql"></div> + <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> <script src="parser.js"></script> <script> @@ -33,4 +39,5 @@ `); er.drawMcd("mcd"); //,"bubble" er.drawMld("mld"); + er.fillSql("sql"); </script> diff --git a/example.svg b/example.svg deleted file mode 100644 index bf81b87..0000000 --- a/example.svg +++ /dev/null @@ -1,96 +0,0 @@ -<!--?xml version="1.0" encoding="UTF-8" standalone="no"?--> - -<!-- Generated by graphviz version 2.40.1 (20161225.0304) - --> -<!-- Title: %3 Pages: 1 --> -<svg width="316pt" height="327pt" viewBox="0.00 0.00 316.05 327.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> -<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 323)"> -<title>%3</title> -<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-323 312.0467,-323 312.0467,4 -4,4"></polygon> -<!-- Musician --> -<g id="node1" class="node"> -<title>Musician</title> -<polygon fill="#ae7d4e" stroke="transparent" points="9,-191.5 9,-216.5 81,-216.5 81,-191.5 9,-191.5"></polygon> -<text text-anchor="start" x="14" y="-200.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Musician</text> -<polygon fill="#ffffff" stroke="transparent" points="9,-166.5 9,-191.5 81,-191.5 81,-166.5 9,-166.5"></polygon> -<text text-anchor="start" x="14" y="-176.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">id</text> -<polygon fill="#ffffff" stroke="transparent" points="9,-141.5 9,-166.5 81,-166.5 81,-141.5 9,-141.5"></polygon> -<text text-anchor="start" x="14" y="-150.3" font-family="Roboto" font-size="14.00" fill="#000000">name</text> -<polygon fill="#ffffff" stroke="transparent" points="9,-116.5 9,-141.5 81,-141.5 81,-116.5 9,-116.5"></polygon> -<text text-anchor="start" x="14" y="-125.3" font-family="Roboto" font-size="14.00" fill="#000000">band</text> -<polygon fill="#ffffff" stroke="transparent" points="9,-91.5 9,-116.5 81,-116.5 81,-91.5 9,-91.5"></polygon> -<text text-anchor="start" x="14" y="-100.3" font-family="Roboto" font-size="14.00" fill="#000000">role</text> -<polygon fill="none" stroke="#000000" points="8,-91 8,-218 82,-218 82,-91 8,-91"></polygon> -</g> -<!-- Play --> -<g id="node5" class="node"> -<title>Play</title> -<polygon fill="#d3d3d3" stroke="#d3d3d3" points="162,-36 119.9364,-18 162,0 204.0636,-18 162,-36"></polygon> -<text text-anchor="middle" x="162" y="-14.3" font-family="Roboto" font-size="14.00" fill="#000000">Play</text> -</g> -<!-- Musician--Play --> -<g id="edge3" class="edge"> -<title>Musician:name--Play</title> -<path fill="none" stroke="#000000" d="M82.084,-107.3354C87.6808,-100.4547 93.4413,-93.5019 99,-87 116.0765,-67.0262 136.769,-44.7006 149.6627,-30.9982"></path> -<text text-anchor="middle" x="139.5" y="-57.8" font-family="Roboto" font-size="14.00" fill="#000000">1,n</text> -</g> -<!-- Instrument --> -<g id="node2" class="node"> -<title>Instrument</title> -<polygon fill="#ae7d4e" stroke="transparent" points="118,-166.5 118,-191.5 207,-191.5 207,-166.5 118,-166.5"></polygon> -<text text-anchor="start" x="123" y="-175.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Instrument</text> -<polygon fill="#ffffff" stroke="transparent" points="118,-141.5 118,-166.5 207,-166.5 207,-141.5 118,-141.5"></polygon> -<text text-anchor="start" x="123" y="-151.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">name</text> -<polygon fill="#ffffff" stroke="transparent" points="118,-116.5 118,-141.5 207,-141.5 207,-116.5 118,-116.5"></polygon> -<text text-anchor="start" x="123" y="-125.3" font-family="Roboto" font-size="14.00" fill="#000000">family</text> -<polygon fill="none" stroke="#000000" points="116.5,-116 116.5,-193 207.5,-193 207.5,-116 116.5,-116"></polygon> -</g> -<!-- Instrument--Play --> -<g id="edge4" class="edge"> -<title>Instrument:name--Play</title> -<path fill="none" stroke="#000000" d="M162,-115.7497C162,-89.5818 162,-56.2494 162,-36.0469"></path> -<text text-anchor="middle" x="173.5" y="-57.8" font-family="Roboto" font-size="14.00" fill="#000000">0,n</text> -</g> -<!-- Piano --> -<g id="node3" class="node"> -<title>Piano</title> -<polygon fill="#ae7d4e" stroke="transparent" points="92,-289 92,-314 142,-314 142,-289 92,-289"></polygon> -<text text-anchor="start" x="97" y="-297.8" font-family="Roboto" font-size="14.00" fill="#ffffff">Piano</text> -<polygon fill="#ffffff" stroke="transparent" points="92,-264 92,-289 142,-289 142,-264 92,-264"></polygon> -<text text-anchor="start" x="97" y="-272.8" font-family="Roboto" font-size="14.00" fill="#000000">type</text> -<polygon fill="none" stroke="#000000" points="91,-263 91,-315 143,-315 143,-263 91,-263"></polygon> -</g> -<!-- Piano--Instrument --> -<g id="edge1" class="edge"> -<title>Piano:name--Instrument:name</title> -<path fill="none" stroke="#000000" stroke-dasharray="5,2" d="M125.7833,-262.7478C131.4763,-245.7319 139.064,-223.0533 145.823,-202.8511"></path> -<polygon fill="#000000" stroke="#000000" points="149.0627,-193.1683 150.1572,-204.0794 147.4762,-197.9099 145.8897,-202.6516 145.8897,-202.6516 145.8897,-202.6516 147.4762,-197.9099 141.6222,-201.2238 149.0627,-193.1683 149.0627,-193.1683"></polygon> -</g> -<!-- Guitar --> -<g id="node4" class="node"> -<title>Guitar</title> -<polygon fill="#ae7d4e" stroke="transparent" points="179,-289 179,-314 234,-314 234,-289 179,-289"></polygon> -<text text-anchor="start" x="184" y="-297.8" font-family="Roboto" font-size="14.00" fill="#ffffff">Guitar</text> -<polygon fill="#ffffff" stroke="transparent" points="179,-264 179,-289 234,-289 234,-264 179,-264"></polygon> -<text text-anchor="start" x="184" y="-272.8" font-family="Roboto" font-size="14.00" fill="#000000">type</text> -<polygon fill="none" stroke="#000000" points="177.5,-263 177.5,-315 234.5,-315 234.5,-263 177.5,-263"></polygon> -</g> -<!-- Guitar--Instrument --> -<g id="edge2" class="edge"> -<title>Guitar:name--Instrument:name</title> -<path fill="none" stroke="#000000" stroke-dasharray="5,2" d="M197.4119,-262.7478C191.8454,-245.7319 184.4263,-223.0533 177.8175,-202.8511"></path> -<polygon fill="#000000" stroke="#000000" points="174.6499,-193.1683 182.0361,-201.2735 176.2045,-197.9205 177.7591,-202.6726 177.7591,-202.6726 177.7591,-202.6726 176.2045,-197.9205 173.4822,-204.0718 174.6499,-193.1683 174.6499,-193.1683"></polygon> -</g> -<!-- Play_event --> -<g id="node6" class="node"> -<title>Play_event</title> -<ellipse fill="none" stroke="#000000" cx="271" cy="-154.5" rx="37.0935" ry="18"></ellipse> -<text text-anchor="middle" x="271" y="-150.8" font-family="Roboto" font-size="14.00" fill="#000000">event</text> -</g> -<!-- Play_event--Play --> -<g id="edge5" class="edge"> -<title>Play_event--Play</title> -<path fill="none" stroke="#000000" d="M259.7846,-137.157C250.5992,-123.2662 237.0373,-103.4517 224,-87 207.7962,-66.5524 187.2723,-44.3526 174.3848,-30.8066"></path> -</g> -</g> -</svg> diff --git a/example_MCD.svg b/example_MCD.svg new file mode 100644 index 0000000..4d6c1a1 --- /dev/null +++ b/example_MCD.svg @@ -0,0 +1,86 @@ +<!--?xml version="1.0" encoding="UTF-8" standalone="no"?--> + +<!-- Generated by graphviz version 2.40.1 (20161225.0304) + --> +<!-- Title: %3 Pages: 1 --> +<svg width="352pt" height="246pt" viewBox="0.00 0.00 352.00 246.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> +<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 242)"> +<title>%3</title> +<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-242 348,-242 348,4 -4,4"></polygon> +<!-- Musician --> +<g id="node1" class="node"> +<title>Musician</title> +<polygon fill="#ae7d4e" stroke="transparent" points="122.5,-207.5 122.5,-232.5 194.5,-232.5 194.5,-207.5 122.5,-207.5"></polygon> +<text text-anchor="start" x="127.5" y="-216.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Musician</text> +<polygon fill="#ffffff" stroke="transparent" points="122.5,-182.5 122.5,-207.5 194.5,-207.5 194.5,-182.5 122.5,-182.5"></polygon> +<text text-anchor="start" x="127.5" y="-192.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">id</text> +<polygon fill="#ffffff" stroke="transparent" points="122.5,-157.5 122.5,-182.5 194.5,-182.5 194.5,-157.5 122.5,-157.5"></polygon> +<text text-anchor="start" x="127.5" y="-166.3" font-family="Roboto" font-size="14.00" fill="#000000">name</text> +<polygon fill="#ffffff" stroke="transparent" points="122.5,-132.5 122.5,-157.5 194.5,-157.5 194.5,-132.5 122.5,-132.5"></polygon> +<text text-anchor="start" x="127.5" y="-141.3" font-family="Roboto" font-size="14.00" fill="#000000">band</text> +<polygon fill="#ffffff" stroke="transparent" points="122.5,-107.5 122.5,-132.5 194.5,-132.5 194.5,-107.5 122.5,-107.5"></polygon> +<text text-anchor="start" x="127.5" y="-116.3" font-family="Roboto" font-size="14.00" fill="#000000">role</text> +<polygon fill="none" stroke="#000000" points="121.5,-107 121.5,-234 195.5,-234 195.5,-107 121.5,-107"></polygon> +</g> +<!-- Play --> +<g id="node5" class="node"> +<title>Play</title> +<path fill="none" stroke="#d3d3d3" d="M330.5,-149.5C330.5,-149.5 284.5,-149.5 284.5,-149.5 278.5,-149.5 272.5,-143.5 272.5,-137.5 272.5,-137.5 272.5,-123.5 272.5,-123.5 272.5,-117.5 278.5,-111.5 284.5,-111.5 284.5,-111.5 330.5,-111.5 330.5,-111.5 336.5,-111.5 342.5,-117.5 342.5,-123.5 342.5,-123.5 342.5,-137.5 342.5,-137.5 342.5,-143.5 336.5,-149.5 330.5,-149.5"></path> +<text text-anchor="middle" x="307.5" y="-134.3" font-family="Roboto" font-size="14.00" fill="#000000"><Play></text> +<text text-anchor="middle" x="307.5" y="-119.3" font-family="Roboto" font-size="14.00" fill="#000000">event</text> +</g> +<!-- Musician--Play --> +<g id="edge4" class="edge"> +<title>Musician:name--Play</title> +<path fill="none" stroke="#000000" d="M195.7146,-160.5095C219.1602,-154.2154 249.2436,-146.1393 272.2952,-139.9509"></path> +<text text-anchor="middle" x="241.5" y="-154.3" font-family="Roboto" font-size="14.00" fill="#000000">1,n</text> +</g> +<!-- Instrument --> +<g id="node2" class="node"> +<title>Instrument</title> +<polygon fill="#ae7d4e" stroke="transparent" points="114.5,-54.5 114.5,-79.5 203.5,-79.5 203.5,-54.5 114.5,-54.5"></polygon> +<text text-anchor="start" x="119.5" y="-63.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Instrument</text> +<polygon fill="#ffffff" stroke="transparent" points="114.5,-29.5 114.5,-54.5 203.5,-54.5 203.5,-29.5 114.5,-29.5"></polygon> +<text text-anchor="start" x="119.5" y="-39.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">name</text> +<polygon fill="#ffffff" stroke="transparent" points="114.5,-4.5 114.5,-29.5 203.5,-29.5 203.5,-4.5 114.5,-4.5"></polygon> +<text text-anchor="start" x="119.5" y="-13.3" font-family="Roboto" font-size="14.00" fill="#000000">family</text> +<polygon fill="none" stroke="#000000" points="113,-4 113,-81 204,-81 204,-4 113,-4"></polygon> +</g> +<!-- Guitar --> +<g id="node4" class="node"> +<title>Guitar</title> +<polygon fill="#ae7d4e" stroke="transparent" points="280.5,-42.5 280.5,-67.5 335.5,-67.5 335.5,-42.5 280.5,-42.5"></polygon> +<text text-anchor="start" x="285.5" y="-51.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Guitar</text> +<polygon fill="#ffffff" stroke="transparent" points="280.5,-17.5 280.5,-42.5 335.5,-42.5 335.5,-17.5 280.5,-17.5"></polygon> +<text text-anchor="start" x="285.5" y="-26.3" font-family="Roboto" font-size="14.00" fill="#000000">type</text> +<polygon fill="none" stroke="#000000" points="279,-16.5 279,-68.5 336,-68.5 336,-16.5 279,-16.5"></polygon> +</g> +<!-- Instrument--Guitar --> +<g id="edge2" class="edge"> +<title>Instrument:name--Guitar:name</title> +<path fill="none" stroke="#000000" stroke-dasharray="5,2" d="M214.2241,-42.5C236.1496,-42.5 260.3961,-42.5 278.672,-42.5"></path> +<polygon fill="#000000" stroke="#000000" points="204.0145,-42.5 214.0146,-38.0001 209.0145,-42.5 214.0145,-42.5001 214.0145,-42.5001 214.0145,-42.5001 209.0145,-42.5 214.0145,-47.0001 204.0145,-42.5 204.0145,-42.5"></polygon> +</g> +<!-- Instrument--Play --> +<g id="edge3" class="edge"> +<title>Instrument:name--Play</title> +<path fill="none" stroke="#000000" d="M204.0145,-69.3811C226.9506,-82.9272 254.2291,-99.038 275.0199,-111.3171"></path> +<text text-anchor="middle" x="241.5" y="-100.3" font-family="Roboto" font-size="14.00" fill="#000000">0,n</text> +</g> +<!-- Piano --> +<g id="node3" class="node"> +<title>Piano</title> +<polygon fill="#ae7d4e" stroke="transparent" points="9,-42.5 9,-67.5 59,-67.5 59,-42.5 9,-42.5"></polygon> +<text text-anchor="start" x="14" y="-51.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Piano</text> +<polygon fill="#ffffff" stroke="transparent" points="9,-17.5 9,-42.5 59,-42.5 59,-17.5 9,-17.5"></polygon> +<text text-anchor="start" x="14" y="-26.3" font-family="Roboto" font-size="14.00" fill="#000000">type</text> +<polygon fill="none" stroke="#000000" points="8,-16.5 8,-68.5 60,-68.5 60,-16.5 8,-16.5"></polygon> +</g> +<!-- Piano--Instrument --> +<g id="edge1" class="edge"> +<title>Piano:name--Instrument:name</title> +<path fill="none" stroke="#000000" stroke-dasharray="5,2" d="M60.0993,-42.5C72.4972,-42.5 87.8228,-42.5 102.6578,-42.5"></path> +<polygon fill="#000000" stroke="#000000" points="112.8078,-42.5 102.8078,-47.0001 107.8078,-42.5 102.8078,-42.5001 102.8078,-42.5001 102.8078,-42.5001 107.8078,-42.5 102.8077,-38.0001 112.8078,-42.5 112.8078,-42.5"></polygon> +</g> +</g> +</svg> diff --git a/example_MLD.svg b/example_MLD.svg new file mode 100644 index 0000000..4f03c96 --- /dev/null +++ b/example_MLD.svg @@ -0,0 +1,96 @@ +<!--?xml version="1.0" encoding="UTF-8" standalone="no"?--> + +<!-- Generated by graphviz version 2.40.1 (20161225.0304) + --> +<!-- Title: %3 Pages: 1 --> +<svg width="495pt" height="272pt" viewBox="0.00 0.00 495.00 272.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> +<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 268)"> +<title>%3</title> +<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-268 491,-268 491,4 -4,4"></polygon> +<!-- Instrument --> +<g id="node1" class="node"> +<title>Instrument</title> +<polygon fill="#ae7d4e" stroke="transparent" points="213.5,-80.5 213.5,-105.5 302.5,-105.5 302.5,-80.5 213.5,-80.5"></polygon> +<text text-anchor="start" x="218.5" y="-89.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Instrument</text> +<polygon fill="#ffffff" stroke="transparent" points="213.5,-55.5 213.5,-80.5 302.5,-80.5 302.5,-55.5 213.5,-55.5"></polygon> +<text text-anchor="start" x="218.5" y="-65.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">name</text> +<polygon fill="#ffffff" stroke="transparent" points="213.5,-30.5 213.5,-55.5 302.5,-55.5 302.5,-30.5 213.5,-30.5"></polygon> +<text text-anchor="start" x="218.5" y="-39.3" font-family="Roboto" font-size="14.00" fill="#000000">family</text> +<polygon fill="none" stroke="#000000" points="212,-30 212,-107 303,-107 303,-30 212,-30"></polygon> +</g> +<!-- Guitar --> +<g id="node2" class="node"> +<title>Guitar</title> +<polygon fill="#ae7d4e" stroke="transparent" points="356,-157.5 356,-182.5 478,-182.5 478,-157.5 356,-157.5"></polygon> +<text text-anchor="start" x="394.5" y="-166.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Guitar</text> +<polygon fill="#ffffff" stroke="transparent" points="356,-132.5 356,-157.5 478,-157.5 478,-132.5 356,-132.5"></polygon> +<text text-anchor="start" x="361" y="-141.3" font-family="Roboto" font-size="14.00" fill="#000000">type</text> +<polygon fill="#ffffff" stroke="transparent" points="356,-107.5 356,-132.5 478,-132.5 478,-107.5 356,-107.5"></polygon> +<text text-anchor="start" x="361" y="-117.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">#Instrument_id</text> +<polygon fill="none" stroke="#000000" points="355,-107 355,-184 479,-184 479,-107 355,-107"></polygon> +</g> +<!-- Instrument--Guitar --> +<g id="edge1" class="edge"> +<title>Instrument:name--Guitar:Instrument_id</title> +<path fill="none" stroke="#000000" d="M302.5,-67.5C332.5502,-67.5 324.8404,-110.207 347.8106,-118.2146"></path> +<ellipse fill="#000000" stroke="#000000" cx="352.0484" cy="-118.8797" rx="4" ry="4"></ellipse> +</g> +<!-- Piano --> +<g id="node3" class="node"> +<title>Piano</title> +<polygon fill="#ae7d4e" stroke="transparent" points="356,-54.5 356,-79.5 478,-79.5 478,-54.5 356,-54.5"></polygon> +<text text-anchor="start" x="397" y="-63.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Piano</text> +<polygon fill="#ffffff" stroke="transparent" points="356,-29.5 356,-54.5 478,-54.5 478,-29.5 356,-29.5"></polygon> +<text text-anchor="start" x="361" y="-38.3" font-family="Roboto" font-size="14.00" fill="#000000">type</text> +<polygon fill="#ffffff" stroke="transparent" points="356,-4.5 356,-29.5 478,-29.5 478,-4.5 356,-4.5"></polygon> +<text text-anchor="start" x="361" y="-14.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">#Instrument_id</text> +<polygon fill="none" stroke="#000000" points="355,-4 355,-81 479,-81 479,-4 355,-4"></polygon> +</g> +<!-- Instrument--Piano --> +<g id="edge2" class="edge"> +<title>Instrument:name--Piano:Instrument_id</title> +<path fill="none" stroke="#000000" d="M302.5,-67.5C332.2708,-67.5 325.0412,-25.6143 347.8744,-17.7607"></path> +<ellipse fill="#000000" stroke="#000000" cx="352.0473" cy="-17.1133" rx="4" ry="4"></ellipse> +</g> +<!-- Musician --> +<g id="node4" class="node"> +<title>Musician</title> +<polygon fill="#ae7d4e" stroke="transparent" points="221.5,-233.5 221.5,-258.5 293.5,-258.5 293.5,-233.5 221.5,-233.5"></polygon> +<text text-anchor="start" x="226.5" y="-242.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Musician</text> +<polygon fill="#ffffff" stroke="transparent" points="221.5,-208.5 221.5,-233.5 293.5,-233.5 293.5,-208.5 221.5,-208.5"></polygon> +<text text-anchor="start" x="226.5" y="-218.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">id</text> +<polygon fill="#ffffff" stroke="transparent" points="221.5,-183.5 221.5,-208.5 293.5,-208.5 293.5,-183.5 221.5,-183.5"></polygon> +<text text-anchor="start" x="226.5" y="-192.3" font-family="Roboto" font-size="14.00" fill="#000000">name</text> +<polygon fill="#ffffff" stroke="transparent" points="221.5,-158.5 221.5,-183.5 293.5,-183.5 293.5,-158.5 221.5,-158.5"></polygon> +<text text-anchor="start" x="226.5" y="-167.3" font-family="Roboto" font-size="14.00" fill="#000000">band</text> +<polygon fill="#ffffff" stroke="transparent" points="221.5,-133.5 221.5,-158.5 293.5,-158.5 293.5,-133.5 221.5,-133.5"></polygon> +<text text-anchor="start" x="226.5" y="-142.3" font-family="Roboto" font-size="14.00" fill="#000000">role</text> +<polygon fill="none" stroke="#000000" points="220.5,-133 220.5,-260 294.5,-260 294.5,-133 220.5,-133"></polygon> +</g> +<!-- Play --> +<g id="node5" class="node"> +<title>Play</title> +<polygon fill="#ae7d4e" stroke="transparent" points="9,-169.5 9,-194.5 159,-194.5 159,-169.5 9,-169.5"></polygon> +<text text-anchor="start" x="69" y="-178.3" font-family="Roboto" font-size="14.00" fill="#ffffff">Play</text> +<polygon fill="#ffffff" stroke="transparent" points="9,-144.5 9,-169.5 159,-169.5 159,-144.5 9,-144.5"></polygon> +<text text-anchor="start" x="14" y="-154.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">#Musician_id</text> +<polygon fill="#ffffff" stroke="transparent" points="9,-119.5 9,-144.5 159,-144.5 159,-119.5 9,-119.5"></polygon> +<text text-anchor="start" x="14" y="-129.3" font-family="Roboto" text-decoration="underline" font-size="14.00" fill="#000000">#Instrument_name</text> +<polygon fill="#ffffff" stroke="transparent" points="9,-94.5 9,-119.5 159,-119.5 159,-94.5 9,-94.5"></polygon> +<text text-anchor="start" x="14" y="-103.3" font-family="Roboto" font-size="14.00" fill="#000000">event</text> +<polygon fill="none" stroke="#000000" points="8,-93.5 8,-195.5 160,-195.5 160,-93.5 8,-93.5"></polygon> +</g> +<!-- Play--Instrument --> +<g id="edge4" class="edge"> +<title>Play:Instrument_name--Instrument:name</title> +<path fill="none" stroke="#000000" d="M167.0953,-130.2787C193.4304,-121.4307 179.2043,-67.5 213.5,-67.5"></path> +<ellipse fill="#000000" stroke="#000000" cx="162.9552" cy="-130.9032" rx="4" ry="4"></ellipse> +</g> +<!-- Play--Musician --> +<g id="edge3" class="edge"> +<title>Play:Musician_id--Musician:id</title> +<path fill="none" stroke="#000000" d="M166.9606,-158.5053C196.5449,-166.6475 184.6929,-221.5 221.5,-221.5"></path> +<ellipse fill="#000000" stroke="#000000" cx="162.9685" cy="-158.0012" rx="4" ry="4"></ellipse> +</g> +</g> +</svg> diff --git a/parser.js b/parser.js index db70f7f..41eff93 100644 --- a/parser.js +++ b/parser.js @@ -9,9 +9,6 @@ class ErDiags this.tables = { }; this.mcdParsing(description); this.mldParsing(); - - console.log(this.tables); - // Cache SVG graphs returned by server (in addition to server cache = good perfs) this.mcdGraph = ""; this.mldGraph = ""; @@ -178,6 +175,20 @@ class ErDiags }); this.tables[name] = newTable; }); + // Add foreign keys information for children (inheritance). TODO: allow several levels + // NOTE: modelisation assume each child has its own table, refering parent (other options exist) + this.inheritances.forEach( inh => { + let idx = this.tables[inh.parent].findIndex( item => { return item.isKey; }); + inh.children.forEach( c => { + this.tables[c].push({ + name: inh.parent + "_id", + type: this.tables[inh.parent][idx].type, + isKey: true, + qualifiers: (this.tables[inh.parent][idx].qualifiers || "") + " foreign key references " + inh.parent, + ref: inh.parent, + }); + }); + }); // Pass 2: parse associations, add foreign keys when cardinality is 0,1 or 1,1 this.associations.forEach( a => { let newTableAttrs = [ ]; @@ -193,7 +204,7 @@ class ErDiags { this.tables[e.name].push({ isKey: e.card.length >= 2 && e.card[1] == 'R', //"weak tables" foreign keys become part of the key - name: "#" + e2.name + "_" + attr.name, + name: e2.name + "_" + attr.name, type: attr.type, qualifiers: "foreign key references " + e2.name + " " + (e.card[0]=='1' ? "not null" : ""), ref: e2.name, //easier drawMld function (fewer regexps) @@ -225,7 +236,7 @@ class ErDiags name: item.entity + "_" + f.name, isKey: true, type: f.type, - qualifiers: (f.qualifiers+" " || "") + "foreign key references " + item.entity + " not null", + qualifiers: (f.qualifiers || "") + " foreign key references " + item.entity + " not null", ref: item.entity, }); }); @@ -328,10 +339,10 @@ class ErDiags // https://www.developpez.net/forums/d1088964/general-developpement/alm/modelisation/structure-agregation-l-association-d-association/ _.shuffle(i.children).forEach( c => { if (Math.random() < 0.5) - mcdDot += '"' + c + '":name -- "' + i.parent; + mcdDot += '"' + c + '":name -- "' + i.parent + '":name [dir="forward",arrowhead="vee",'; else - mcdDot += '"' + i.parent + '":name -- "' + c; - mcdDot += '":name [dir="forward", arrowhead="vee", style="dashed"];\n'; + mcdDot += '"' + i.parent + '":name -- "' + c + '":name [dir="back",arrowtail="vee",'; + mcdDot += 'style="dashed"];\n'; }); }); // Relationships: @@ -383,7 +394,7 @@ class ErDiags }); }); mcdDot += '}'; - console.log(mcdDot); + //console.log(mcdDot); ErDiags.AjaxGet(mcdDot, graphSvg => { this.mcdGraph = graphSvg; element.innerHTML = graphSvg; @@ -402,6 +413,7 @@ class ErDiags } // Build dot graph input (assuming foreign keys not already present...) let mldDot = 'graph {\n'; + mldDot += 'rankdir="LR";\n'; mldDot += 'node [shape=plaintext];\n'; let links = ""; _.shuffle(Object.keys(this.tables)).forEach( name => { @@ -409,21 +421,31 @@ class ErDiags mldDot += '<tr><td BGCOLOR="#ae7d4e" BORDER="0"><font COLOR="#FFFFFF">' + name + '</font></td></tr>\n'; this.tables[name].forEach( f => { let label = (f.isKey ? '<u>' : '') + (!!f.qualifiers && f.qualifiers.indexOf("foreign")>=0 ? '#' : '') + f.name + (f.isKey ? '</u>' : ''); - mldDot += '<tr><td port="' + f.name + '"' + (f.isKey ? ' port="__key"' : '') - + ' BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >' + label + '</font></td></tr>\n'; + mldDot += '<tr><td port="' + f.name + '"' + ' BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >' + label + '</font></td></tr>\n'; if (!!f.ref) { + // Need to find a key attribute in reference entity (the first...) + let keyInRef = ""; + for (let field of this.tables[f.ref]) + { + if (field.isKey) + { + keyInRef = field.name; + break; + } + } if (Math.random() < 0.5) - links += '"' + f.ref + '":__key -- "' + name+'":"'+f.name+'"\n'; + links += '"' + f.ref + '":"' + keyInRef + '" -- "' + name+'":"'+f.name + '" [dir="forward",arrowhead="dot"'; else - links += '"'+name+'":"'+f.name+'" -- "' + f.ref + '":__key\n'; + links += '"'+name+'":"'+f.name+'" -- "' + f.ref + '":"' + keyInRef + '" [dir="back",arrowtail="dot"'; + links += ']\n;'; } }); mldDot += '</table>>];\n'; }); mldDot += links + '\n'; mldDot += '}\n'; - console.log(mldDot); + //console.log(mldDot); ErDiags.AjaxGet(mldDot, graphSvg => { this.mldGraph = graphSvg; element.innerHTML = graphSvg; @@ -443,11 +465,11 @@ class ErDiags sqlText += "CREATE TABLE " + name + " (\n"; let key = ""; this.tables[name].forEach( f => { - sqlText += f.name + " " + (f.type || "TEXT") + (" "+f.qualifiers || "") + ",\n"; + sqlText += "\t" + f.name + " " + (f.type || "TEXT") + " " + (f.qualifiers || "") + ",\n"; if (f.isKey) key += (key.length>0 ? "," : "") + f.name; }); - sqlText += "PRIMARY KEY (" + key + ")\n"; + sqlText += "\tPRIMARY KEY (" + key + ")\n"; sqlText += ");\n"; }); //console.log(sqlText);