mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 15:56:00 +00:00
perspective tree layout
This commit is contained in:
@@ -633,6 +633,17 @@
|
|||||||
return settings?.canExport;
|
return settings?.canExport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// export function arrange(skipUndoChain = false) {
|
||||||
|
// switch (settings?.arrangeAlg) {
|
||||||
|
// case 'springy':
|
||||||
|
// arrange_springy(skipUndoChain);
|
||||||
|
// break;
|
||||||
|
// case 'tree':
|
||||||
|
// arrange_tree(skipUndoChain);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
export function arrange(skipUndoChain = false, arrangeAll = true, circleMiddle = { x: 0, y: 0 }) {
|
export function arrange(skipUndoChain = false, arrangeAll = true, circleMiddle = { x: 0, y: 0 }) {
|
||||||
const graph = new GraphDefinition();
|
const graph = new GraphDefinition();
|
||||||
for (const table of value?.tables || []) {
|
for (const table of value?.tables || []) {
|
||||||
@@ -653,15 +664,27 @@
|
|||||||
|
|
||||||
graph.initialize();
|
graph.initialize();
|
||||||
|
|
||||||
const layout = GraphLayout
|
let layout: GraphLayout;
|
||||||
// initial circle layout
|
switch (settings?.arrangeAlg) {
|
||||||
.createCircle(graph, circleMiddle)
|
case 'springy':
|
||||||
// simulation with Hook's, Coulomb's and gravity law
|
layout = GraphLayout
|
||||||
.springyAlg()
|
// initial circle layout
|
||||||
// move nodes to avoid overlaps
|
.createCircle(graph, circleMiddle)
|
||||||
.solveOverlaps()
|
// simulation with Hook's, Coulomb's and gravity law
|
||||||
// view box starts with [0,0]
|
.springyAlg()
|
||||||
.fixViewBox();
|
// move nodes to avoid overlaps
|
||||||
|
.solveOverlaps()
|
||||||
|
// view box starts with [0,0]
|
||||||
|
.fixViewBox();
|
||||||
|
break;
|
||||||
|
case 'tree':
|
||||||
|
layout = GraphLayout.createTree(graph, value?.rootDesignerId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!layout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// layout.print();
|
// layout.print();
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
customizeStyle: true,
|
customizeStyle: true,
|
||||||
allowDefineVirtualReferences: true,
|
allowDefineVirtualReferences: true,
|
||||||
canCheckTables: true,
|
canCheckTables: true,
|
||||||
|
arrangeAlg: 'springy',
|
||||||
}}
|
}}
|
||||||
referenceComponent={DiagramDesignerReference}
|
referenceComponent={DiagramDesignerReference}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const GRAVITY_Y = 0.01;
|
|||||||
const REPULSION = 1000;
|
const REPULSION = 1000;
|
||||||
const MAX_FORCE_SIZE = 100;
|
const MAX_FORCE_SIZE = 100;
|
||||||
const NODE_MARGIN = 30;
|
const NODE_MARGIN = 30;
|
||||||
|
const NODE_SPACE_TREE = 60;
|
||||||
const GRAVITY_EXPONENT = 1.05;
|
const GRAVITY_EXPONENT = 1.05;
|
||||||
|
|
||||||
// const MOVE_STEP = 20;
|
// const MOVE_STEP = 20;
|
||||||
@@ -299,6 +300,43 @@ export class GraphLayout {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static createTree(graph: GraphDefinition, rootId: string): GraphLayout {
|
||||||
|
const res = new GraphLayout(graph);
|
||||||
|
const root = graph.nodes[rootId];
|
||||||
|
if (!root) return res;
|
||||||
|
|
||||||
|
const rootLayout = new LayoutNode(root, root.width / 2 + NODE_MARGIN, root.height / 2 + NODE_MARGIN);
|
||||||
|
res.nodes[rootId] = rootLayout;
|
||||||
|
|
||||||
|
res.createTreeLevel([root], rootLayout.right + NODE_SPACE_TREE);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
createTreeLevel(parentNodes: GraphNode[], left: number) {
|
||||||
|
let currentY = NODE_MARGIN;
|
||||||
|
let maxRight = 0;
|
||||||
|
const nextLevel: GraphNode[] = [];
|
||||||
|
for (const parent of parentNodes) {
|
||||||
|
for (const child of parent.neightboors) {
|
||||||
|
if (child.designerId in this.nodes) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
nextLevel.push(child);
|
||||||
|
const layoutNode = new LayoutNode(child, left + child.width / 2, currentY + child.height / 2);
|
||||||
|
this.nodes[child.designerId] = layoutNode;
|
||||||
|
currentY += child.height + NODE_MARGIN;
|
||||||
|
if (layoutNode.right > maxRight) {
|
||||||
|
maxRight = layoutNode.right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextLevel.length > 0) {
|
||||||
|
this.createTreeLevel(nextLevel, maxRight + NODE_SPACE_TREE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fillEdges() {
|
fillEdges() {
|
||||||
this.edges = this.graph.edges.map(edge => {
|
this.edges = this.graph.edges.map(edge => {
|
||||||
const res = new LayoutEdge();
|
const res = new LayoutEdge();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
customizeStyle: false,
|
customizeStyle: false,
|
||||||
allowDefineVirtualReferences: false,
|
allowDefineVirtualReferences: false,
|
||||||
canCheckTables: true,
|
canCheckTables: true,
|
||||||
|
arrangeAlg: null,
|
||||||
}}
|
}}
|
||||||
referenceComponent={QueryDesignerReference}
|
referenceComponent={QueryDesignerReference}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
customizeStyle: false,
|
customizeStyle: false,
|
||||||
allowDefineVirtualReferences: false,
|
allowDefineVirtualReferences: false,
|
||||||
canCheckTables: true,
|
canCheckTables: true,
|
||||||
|
arrangeAlg: 'tree',
|
||||||
}}
|
}}
|
||||||
referenceComponent={QueryDesignerReference}
|
referenceComponent={QueryDesignerReference}
|
||||||
value={createDesignerModel(config, dbInfos)}
|
value={createDesignerModel(config, dbInfos)}
|
||||||
|
|||||||
Reference in New Issue
Block a user