Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ You need to add the following dependencies to your HTML:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quick ERD</title>

<!-- Assuming you put the rappid.css file in this path -->
<link rel="stylesheet" type="text/css" href="./examples/diagram-generator/libs/rappid.css">
<!-- Assuming you put the rappid.min.css file in this path -->
<link rel="stylesheet" type="text/css" href="./examples/diagram-generator/libs/rappid.min.css">
<link rel="stylesheet" href="./dist/quick-erd.css">

<style>
Expand Down Expand Up @@ -221,23 +221,25 @@ You need to add the following dependencies to your HTML:
import { Diagram } from './dist/quick-erd.js';

new Diagram( toERD(
`departments /insert 2
`
departments
name /nn
location
country
employees /insert 4
name /nn vc50
email /lower
cost center num
date hired
job vc255
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 }

`
), document.getElementById( 'quickERD' ) );
), '#quickERD' );
</script>
</body>
</html>
Expand All @@ -255,8 +257,8 @@ view emp_v departments employees
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quick ERD</title>

<!-- Assuming you put the rappid.css file in this path -->
<link rel="stylesheet" type="text/css" href="./examples/diagram-generator/libs/rappid.css">
<!-- Assuming you put the rappid.min.css file in this path -->
<link rel="stylesheet" type="text/css" href="./examples/diagram-generator/libs/rappid.min.css">
<link rel="stylesheet" href="./dist/quick-erd.css">

<style>
Expand Down Expand Up @@ -285,23 +287,25 @@ view emp_v departments employees

<script>
new quickERD.Diagram( quickSQL.toERD(
`departments /insert 2
`
departments
name /nn
location
country
employees /insert 4
name /nn vc50
email /lower
cost center num
date hired
job vc255
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 }

`
), document.getElementById( 'quickERD' ) );
), '#quickERD' );
</script>
</body>
</html>
Expand Down
Binary file modified assets/quick-erd-dark-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/quick-erd-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/quick-erd-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/quick-erd-light-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/quick-erd-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 18 additions & 14 deletions examples/diagram-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QuickERD</title>

<link rel="stylesheet" type="text/css" href="libs/rappid.css">
<!-- Assuming you put the rappid.min.css file in this path -->
<link rel="stylesheet" type="text/css" href="libs/rappid.min.css">

<link rel="stylesheet" href="../../dist/quick-erd.css">

<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js" integrity="sha256-qXBd/EfAdjOA2FGrGAG+b3YBn2tn5A6bhz+LSgYD96k=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/backbone@1.5.0/backbone-min.min.js"></script>

<script src="libs/rappid.min.js"></script>
<!-- Assuming you put the rappid.min.js file in this path -->
<script src="libs/rappid.min.js"></script>

<!-- <script src="../../dist/quick-erd.umd.cjs"></script>
Expand Down Expand Up @@ -61,7 +62,7 @@
</style>
</head>
<body>
<div class="container">
<div class="container" style="padding: 20px;">
<div id="sql">
<pre></pre>
</div>
Expand All @@ -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;
</script>
</body>
Expand Down
14 changes: 7 additions & 7 deletions src/quick-erd/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
};
Expand Down