mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 21:36:00 +00:00
diagram improvements
This commit is contained in:
@@ -85,6 +85,34 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleShowDiagram = async () => {
|
||||||
|
const db = await getDatabaseInfo({
|
||||||
|
conid: connection._id,
|
||||||
|
database: name,
|
||||||
|
});
|
||||||
|
openNewTab(
|
||||||
|
{
|
||||||
|
title: 'Diagram #',
|
||||||
|
icon: 'img diagram',
|
||||||
|
tabComponent: 'DiagramTab',
|
||||||
|
props: {
|
||||||
|
conid: connection._id,
|
||||||
|
database: name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
editor: {
|
||||||
|
tables: db.tables.map(table => ({
|
||||||
|
...table,
|
||||||
|
designerId: `${table.pureName}-${uuidv1()}`,
|
||||||
|
})),
|
||||||
|
references: [],
|
||||||
|
autoLayout: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const handleDisconnect = () => {
|
const handleDisconnect = () => {
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
if (electron) {
|
if (electron) {
|
||||||
@@ -138,6 +166,7 @@
|
|||||||
{ divider: true },
|
{ divider: true },
|
||||||
{ onClick: handleImport, text: 'Import' },
|
{ onClick: handleImport, text: 'Import' },
|
||||||
{ onClick: handleExport, text: 'Export' },
|
{ onClick: handleExport, text: 'Export' },
|
||||||
|
{ onClick: handleShowDiagram, text: 'Show diagram' },
|
||||||
{ onClick: handleSqlGenerator, text: 'SQL Generator' },
|
{ onClick: handleSqlGenerator, text: 'SQL Generator' },
|
||||||
{ onClick: handleOpenJsonModel, text: 'Open model as JSON' },
|
{ onClick: handleOpenJsonModel, text: 'Open model as JSON' },
|
||||||
{ onClick: handleExportModel, text: 'Export DB model - experimental' },
|
{ onClick: handleExportModel, text: 'Export DB model - experimental' },
|
||||||
@@ -157,6 +186,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import getConnectionLabel from '../utility/getConnectionLabel';
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
|
import uuidv1 from 'uuid/v1';
|
||||||
|
|
||||||
import _, { find } from 'lodash';
|
import _, { find } from 'lodash';
|
||||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
|
|||||||
@@ -551,7 +551,7 @@
|
|||||||
tables: [
|
tables: [
|
||||||
{
|
{
|
||||||
...data,
|
...data,
|
||||||
designerId: uuidv1(),
|
designerId: `${data.pureName}-${uuidv1()}`,
|
||||||
autoAddReferences: true,
|
autoAddReferences: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -53,6 +53,8 @@
|
|||||||
export const activator = createActivator('Designer', true);
|
export const activator = createActivator('Designer', true);
|
||||||
|
|
||||||
let domCanvas;
|
let domCanvas;
|
||||||
|
let canvasWidth = 3000;
|
||||||
|
let canvasHeight = 3000;
|
||||||
|
|
||||||
const sourceDragColumn$ = writable(null);
|
const sourceDragColumn$ = writable(null);
|
||||||
const targetDragColumn$ = writable(null);
|
const targetDragColumn$ = writable(null);
|
||||||
@@ -87,6 +89,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
detectSize(tables, domTables);
|
||||||
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (dbInfo && value?.autoLayout) {
|
if (dbInfo && value?.autoLayout) {
|
||||||
performAutoActions($dbInfo);
|
performAutoActions($dbInfo);
|
||||||
@@ -145,6 +151,16 @@
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function detectSize(tables, domTables) {
|
||||||
|
await tick();
|
||||||
|
const rects = _.values(domTables).map(x => x.getRect());
|
||||||
|
const maxX = _.max(rects.map(x => x.right));
|
||||||
|
const maxY = _.max(rects.map(x => x.bottom));
|
||||||
|
|
||||||
|
canvasWidth = Math.max(3000, maxX + 50);
|
||||||
|
canvasHeight = Math.max(3000, maxY + 50);
|
||||||
|
}
|
||||||
|
|
||||||
function callChange(changeFunc, skipUndoChain = undefined) {
|
function callChange(changeFunc, skipUndoChain = undefined) {
|
||||||
onChange(changeFunc, skipUndoChain);
|
onChange(changeFunc, skipUndoChain);
|
||||||
tick().then(recomputeReferencePositions);
|
tick().then(recomputeReferencePositions);
|
||||||
@@ -556,7 +572,13 @@
|
|||||||
<div class="empty">Drag & drop tables or views from left panel here</div>
|
<div class="empty">Drag & drop tables or views from left panel here</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="canvas" bind:this={domCanvas} on:dragover={e => e.preventDefault()} on:drop={handleDrop}>
|
<div
|
||||||
|
class="canvas"
|
||||||
|
bind:this={domCanvas}
|
||||||
|
on:dragover={e => e.preventDefault()}
|
||||||
|
on:drop={handleDrop}
|
||||||
|
style={`width:${canvasWidth}px;height:${canvasHeight}px;`}
|
||||||
|
>
|
||||||
{#each references || [] as ref (ref.designerId)}
|
{#each references || [] as ref (ref.designerId)}
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={referenceComponent}
|
this={referenceComponent}
|
||||||
@@ -614,8 +636,6 @@
|
|||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
.canvas {
|
.canvas {
|
||||||
width: 3000px;
|
|
||||||
height: 3000px;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -368,6 +368,7 @@ export class GraphLayout {
|
|||||||
doMoveSteps() {
|
doMoveSteps() {
|
||||||
let res: GraphLayout = this;
|
let res: GraphLayout = this;
|
||||||
let score = res.score();
|
let score = res.score();
|
||||||
|
const start = new Date().getTime();
|
||||||
for (let step = 0; step < MOVE_STEP_COUNT; step++) {
|
for (let step = 0; step < MOVE_STEP_COUNT; step++) {
|
||||||
const lastRes = res;
|
const lastRes = res;
|
||||||
res = res.tryMoveElement();
|
res = res.tryMoveElement();
|
||||||
@@ -377,7 +378,7 @@ export class GraphLayout {
|
|||||||
}
|
}
|
||||||
const newScore = res.score();
|
const newScore = res.score();
|
||||||
// console.log('STEP, SCORE, NEW SCORE', step, score, newScore);
|
// console.log('STEP, SCORE, NEW SCORE', step, score, newScore);
|
||||||
if (score - newScore < MINIMAL_SCORE_BENEFIT) {
|
if (score - newScore < MINIMAL_SCORE_BENEFIT || new Date().getTime() - start > 1000) {
|
||||||
lastRes.fillEdges();
|
lastRes.fillEdges();
|
||||||
return lastRes;
|
return lastRes;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user