X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=parser.js;h=51a05e0815f2b9d60c29b2f104f610d2bab86f9d;hb=eabe4071112a744a7be577263013a9bb0e4eb524;hp=57cf81c1c39ba005d8bc1b26be0e7b1f279690ed;hpb=e2610c05f3687c9362342718eb74410bfb279079;p=erdiag.git diff --git a/parser.js b/parser.js index 57cf81c..51a05e0 100644 --- a/parser.js +++ b/parser.js @@ -16,7 +16,7 @@ class ErDiags static get TYPES() { - // SQLite types without null (TODO: be more general) + // SQLite storage classes without null return ["integer","real","text","blob"]; } @@ -67,7 +67,7 @@ class ErDiags { case '[': // Entity = { name: { attributes, [weak] } } - let name = lines[start].match(/\w+/)[0]; + let name = lines[start].match(/[^\[\]\s]+/)[0]; let entity = { attributes: this.parseAttributes(lines, start+1, end) }; if (lines[start].charAt(1) == '[') entity.weak = true; @@ -79,7 +79,7 @@ class ErDiags case '{': //association // Association = { [name], [attributes], [weak], entities: ArrayOf entity indices } let relationship = { }; - let nameRes = lines[start].match(/\w+/); + let nameRes = lines[start].match(/[^{}\s]+/); if (nameRes !== null) relationship.name = nameRes[0]; if (lines[start].charAt(1) == '{') @@ -95,15 +95,20 @@ class ErDiags let attributes = []; for (let i=start; i { + if (mcdStyle == "compact") + mcdDot += "node [shape=plaintext];\n"; + _.shuffle(Object.keys(this.entities)).forEach( name => { if (mcdStyle == "bubble") { mcdDot += name + '[shape=rectangle, label="' + name + '"'; @@ -193,16 +202,20 @@ class ErDiags mcdDot += '];\n'; if (!!this.entities[name].attributes) { - this.entities[name].attributes.forEach( a => { + _.shuffle(this.entities[name].attributes).forEach( a => { let label = (a.isKey ? '#' : '') + a.name; - mcdDot += name + '_' + a.name + '[shape=ellipse, label="' + label + '"];\n'; - mcdDot += name + '_' + a.name + ' -- ' + name + ';\n'; + let attrName = name + '_' + a.name; + mcdDot += attrName + '[shape=ellipse, label="' + label + '"];\n'; + if (Math.random() < 0.5) + mcdDot += attrName + ' -- ' + name + ';\n'; + else + mcdDot += name + ' -- ' + attrName + ';\n'; }); } } else { - mcdDot += name + '[shape=plaintext, label=<'; + mcdDot += name + '[label=<'; if (this.entities[name].weak) { mcdDot += '' + @@ -226,13 +239,17 @@ class ErDiags }); // Inheritances: this.inheritances.forEach( i => { - i.children.forEach( c => { - mcdDot += c + ':name -- ' + i.parent + ':name [len="1.00", dir="forward", arrowhead="vee", style="dashed"];\n'; + _.shuffle(i.children).forEach( c => { + if (Math.random() < 0.5) + mcdDot += c + ':name -- ' + i.parent; + else + mcdDot += i.parent + ':name -- ' + c; + mcdDot += ':name [dir="forward", arrowhead="vee", style="dashed"];\n'; }); }); // Relationships: let assoceCounter = 0; - this.associations.forEach( a => { + _.shuffle(this.associations).forEach( a => { let name = !!a.name && a.name.length > 0 ? a.name : '_assoce' + assoceCounter++; @@ -240,27 +257,36 @@ class ErDiags if (a.weak) mcdDot += ', peripheries=2'; mcdDot += '];\n'; - a.entities.forEach( e => { - mcdDot += e.name + ':name -- ' + name + '[len="1.00", label="' + ErDiags.CARDINAL[e.card] + '"];\n'; + _.shuffle(a.entities).forEach( e => { + if (Math.random() < 0.5) + mcdDot += e.name + ':name -- ' + name; + else + mcdDot += name + ' -- ' + e.name + ':name'; + mcdDot += '[label="' + ErDiags.CARDINAL[e.card] + '"];\n'; }); if (!!a.attributes) { - a.attributes.forEach( attr => { + _.shuffle(a.attributes).forEach( attr => { let label = (attr.isKey ? '#' : '') + attr.name; - mcdDot += name + '_' + attr.name + '[len="1.00", shape=ellipse, label="' + label + '"];\n'; - mcdDot += name + '_' + attr.name + ' -- ' + name + ';\n'; + mcdDot += name + '_' + attr.name + '[shape=ellipse, label="' + label + '"];\n'; + let attrName = name + '_' + attr.name; + if (Math.random() < 0.5) + mcdDot += attrName + ' -- ' + name + ';\n'; + else + mcdDot += name + ' -- ' + attrName + ';\n'; }); } }); mcdDot += '}'; - //console.log(mcdDot); + console.log(mcdDot); ErDiags.AjaxGet(mcdDot, graphSvg => { this.mcdGraph = graphSvg; element.innerHTML = graphSvg; - }) + }); } // "Modèle logique des données" + // TODO: this one should draw links from foreign keys to keys (port=... in
) drawMld(id) { let element = document.getElementById(id); @@ -288,6 +314,11 @@ class ErDiags }); }); // this.graphMld = ... + //console.log(mldDot); + ErDiags.AjaxGet(mldDot, graphSvg => { + this.mldGraph = graphSvg; + element.innerHTML = graphSvg; + }); } fillSql(id)