Arrange tables in import from source (#28)
This commit is contained in:
parent
4a87935412
commit
11e83bb12b
@ -132,6 +132,7 @@ export default function Modal({
|
|||||||
if (importSource.overwrite) {
|
if (importSource.overwrite) {
|
||||||
setTables(d.tables);
|
setTables(d.tables);
|
||||||
setRelationships(d.relationships);
|
setRelationships(d.relationships);
|
||||||
|
setTransform((prev) => ({ ...prev, pan: { x: 0, y: 0 } }));
|
||||||
setNotes([]);
|
setNotes([]);
|
||||||
setAreas([]);
|
setAreas([]);
|
||||||
setTypes([]);
|
setTypes([]);
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import { Cardinality } from "../data/constants";
|
import {
|
||||||
|
Cardinality,
|
||||||
|
tableColorStripHeight,
|
||||||
|
tableFieldHeight,
|
||||||
|
tableHeaderHeight,
|
||||||
|
} from "../data/constants";
|
||||||
|
|
||||||
export function astToDiagram(ast) {
|
export function astToDiagram(ast) {
|
||||||
const tables = [];
|
const tables = [];
|
||||||
@ -14,8 +19,6 @@ export function astToDiagram(ast) {
|
|||||||
table.color = "#175e7a";
|
table.color = "#175e7a";
|
||||||
table.fields = [];
|
table.fields = [];
|
||||||
table.indices = [];
|
table.indices = [];
|
||||||
table.x = 0;
|
|
||||||
table.y = 0;
|
|
||||||
e.create_definitions.forEach((d) => {
|
e.create_definitions.forEach((d) => {
|
||||||
if (d.resource === "column") {
|
if (d.resource === "column") {
|
||||||
const field = {};
|
const field = {};
|
||||||
@ -278,5 +281,25 @@ export function astToDiagram(ast) {
|
|||||||
|
|
||||||
relationships.forEach((r, i) => (r.id = i));
|
relationships.forEach((r, i) => (r.id = i));
|
||||||
|
|
||||||
|
let maxHeight = -1;
|
||||||
|
const tableWidth = 200;
|
||||||
|
const gapX = 54;
|
||||||
|
const gapY = 40;
|
||||||
|
tables.forEach((table, i) => {
|
||||||
|
if (i < tables.length / 2) {
|
||||||
|
table.x = i * tableWidth + (i + 1) * gapX;
|
||||||
|
table.y = gapY;
|
||||||
|
const height =
|
||||||
|
table.fields.length * tableFieldHeight +
|
||||||
|
tableHeaderHeight +
|
||||||
|
tableColorStripHeight;
|
||||||
|
maxHeight = Math.max(height, maxHeight);
|
||||||
|
} else {
|
||||||
|
const index = tables.length - i - 1;
|
||||||
|
table.x = index * tableWidth + (index + 1) * gapX;
|
||||||
|
table.y = maxHeight + 2 * gapY;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return { tables, relationships };
|
return { tables, relationships };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user