diagram reference drawing

This commit is contained in:
Jan Prochazka
2022-01-06 08:35:42 +01:00
parent d52e7a3b9f
commit 28db13c995
4 changed files with 59 additions and 35 deletions

View File

@@ -57,7 +57,8 @@
}
}
function updateFromDbInfo(db) {
function updateFromDbInfo(db = 'auto') {
if (db == 'auto' && dbInfo) db = $dbInfo;
if (!settings?.updateFromDbInfo || !db) return;
onChange(current => {
@@ -301,34 +302,36 @@
json.top = e.clientY - rect.top;
callChange(current => {
const foreignKeys = _.compact([
...(json.foreignKeys || []).map(fk => {
const tables = ((current || {}).tables || []).filter(
tbl => fk.refTableName == tbl.pureName && fk.refSchemaName == tbl.schemaName
);
if (tables.length == 1)
return {
...fk,
sourceId: json.designerId,
targetId: tables[0].designerId,
};
return null;
}),
..._.flatten(
((current || {}).tables || []).map(tbl =>
(tbl.foreignKeys || []).map(fk => {
if (fk.refTableName == json.pureName && fk.refSchemaName == json.schemaName) {
const foreignKeys = settings?.useDatabaseReferences
? []
: _.compact([
...(json.foreignKeys || []).map(fk => {
const tables = ((current || {}).tables || []).filter(
tbl => fk.refTableName == tbl.pureName && fk.refSchemaName == tbl.schemaName
);
if (tables.length == 1)
return {
...fk,
sourceId: tbl.designerId,
targetId: json.designerId,
sourceId: json.designerId,
targetId: tables[0].designerId,
};
}
return null;
})
)
),
]);
}),
..._.flatten(
((current || {}).tables || []).map(tbl =>
(tbl.foreignKeys || []).map(fk => {
if (fk.refTableName == json.pureName && fk.refSchemaName == json.schemaName) {
return {
...fk,
sourceId: tbl.designerId,
targetId: json.designerId,
};
}
return null;
})
)
),
]);
const alias = getNewTableAlias(json, current?.tables);
if (alias && !settings?.allowTableAlias) return current;
@@ -360,6 +363,7 @@
: (current || {}).references,
};
});
updateFromDbInfo();
};
function recomputeReferencePositions() {
@@ -383,6 +387,7 @@
onChangeReference={changeReference}
onRemoveReference={removeReference}
designer={value}
{settings}
/>
{/each}
<!--

View File

@@ -8,6 +8,7 @@
export let onChangeReference;
export let designer;
export let domTables;
export let settings;
let src = null;
let dst = null;
@@ -17,6 +18,9 @@
const buswi = 10;
const extwi = 25;
const arwi = 12;
const arhi = 12;
const arpad = 3;
export function recomputePosition() {
const { designerId, sourceId, targetId, columns, joinType } = reference;
@@ -117,20 +121,31 @@
`}
/>
{/each}
{#if settings?.showReferenceArrow}
<polygon
points={`
${dst.x - buswi * minpos.dirdst + arpad * minpos.dirdst},${dst.y}
${dst.x + arwi * minpos.dirdst - buswi * minpos.dirdst + arpad * minpos.dirdst},${dst.y + arhi / 2}
${dst.x + arwi * minpos.dirdst - buswi * minpos.dirdst + arpad * minpos.dirdst},${dst.y - arhi / 2}
`}
/>
{/if}
</svg>
<div
use:contextMenu={createMenu}
class="wrapper"
style={`left: ${(src.x + extwi * minpos.dirsrc + dst.x + extwi * minpos.dirdst) / 2 - 16}px;
{#if settings?.showJoinType}
<div
use:contextMenu={createMenu}
class="wrapper"
style={`left: ${(src.x + extwi * minpos.dirsrc + dst.x + extwi * minpos.dirdst) / 2 - 16}px;
top: ${(src.y + dst.y) / 2 - 16}px`}
>
<div class="text">
{_.snakeCase(reference?.joinType || 'CROSS JOIN')
.replace('_', '\xa0')
.replace('_', '\xa0')}
>
<div class="text">
{_.snakeCase(reference?.joinType || 'CROSS JOIN')
.replace('_', '\xa0')
.replace('_', '\xa0')}
</div>
</div>
</div>
{/if}
{/if}
<style>

View File

@@ -11,5 +11,7 @@
allowTableAlias: false,
updateFromDbInfo: true,
useDatabaseReferences: true,
showJoinType: false,
showReferenceArrow: true,
}}
/>

View File

@@ -11,5 +11,7 @@
allowTableAlias: true,
updateFromDbInfo: false,
useDatabaseReferences: false,
showJoinType: true,
showReferenceArrow: false,
}}
/>