@@ -73,24 +74,27 @@
import { Diagram } from '../../dist/quick-erd.js';
const input =
-`departments /insert 2
- name /nn
- location
- country
- employees /insert 4
- name /nn vc50
- email /lower
- cost center num
- date hired
- job vc255
+`
+departments
+ name /nn
+ location
+ country
+employees
+ departments_id /fk departments
+ name /nn vc50
+ email /lower
+ cost center num
+ date hired
+ job vc255
view emp_v departments employees
# settings = { "prefix": null, "semantics": "CHAR", "DV": false }
`
// new quickERD.Diagram( quickSQL.toERD( input ), document.getElementById( 'quickERD' ) );
- new Diagram( toERD( input, document.getElementById( 'quickERD' ) ) );
+ new Diagram( toERD(input), '#quickERD' );
+
document.querySelector( '#sql > pre' ).innerText = input;
diff --git a/src/quick-erd/utils.js b/src/quick-erd/utils.js
index 492da3a..0e46e36 100644
--- a/src/quick-erd/utils.js
+++ b/src/quick-erd/utils.js
@@ -3,6 +3,8 @@
var utils = {};
+const FONT_NAME = getComputedStyle(document.querySelector(':root')).getPropertyValue('--qs-diagram-font-family') || 'Arial';
+
utils.newGuid = function () {
function _s8(s) {
var p = (Math.random().toString(16) + '000000000').substr(2, 8);
@@ -16,17 +18,15 @@ utils.calcWidth = function (schema, name, columns) {
if (schema) {
objName = schema.concat('.').concat(name);
}
- var nameWidth = utils.getTextWidth(objName, '12pt Arial');
- var colWidth = 60;
+ var nameWidth = utils.getTextWidth(objName, `12pt ${FONT_NAME}`);
+ var colWidth = 0;
var dtWidth = 0;
- var indexWidth = 0;
for (var i = 0; i < columns.length; i++) {
- colWidth = Math.max(colWidth, utils.getTextWidth(columns[i].name, '10pt Arial'));
- dtWidth = Math.max(dtWidth, utils.getTextWidth(columns[i].datatype, '10pt Arial'));
+ colWidth = Math.max(colWidth, utils.getTextWidth(columns[i].name, `10pt ${FONT_NAME}`));
+ dtWidth = Math.max(dtWidth, utils.getTextWidth(columns[i].datatype, `10pt ${FONT_NAME}`));
}
- const bonus = 40; // colWidth > 100 ? 15 : 40;
- const cdtWidth = colWidth + bonus + dtWidth;
+ const cdtWidth = (dtWidth > colWidth) ? (dtWidth * 2) : colWidth + dtWidth + 20;
let width = Math.max(nameWidth, cdtWidth);
return width;
};