Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-layout leave some room for toolbar #295

Merged
merged 1 commit into from
May 10, 2023
Merged
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
27 changes: 17 additions & 10 deletions ui/src/lib/store/canvasSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,9 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
// consider the output box
const id2height = new Map<string, number>();
const id2width = new Map<string, number>();
// Leave some room for the top toolbar.
// FIXME fixed value.
const paddingTopPod = 50;
nodes.forEach((node) => {
const bottom = document.querySelector(`#result-${node.id}-bottom`);
const right = document.querySelector("#result-" + node.id + "-right");
Expand All @@ -991,9 +994,9 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
const tmpNodes: NodeType[] = nodes.map((node) => ({
id: node.id,
x: node.position.x + id2width.get(node.id)! / 2,
y: node.position.y + id2height.get(node.id)! / 2,
y: node.position.y + id2height.get(node.id)! / 2 + paddingTopPod / 2,
width: id2width.get(node.id)!,
height: id2height.get(node.id)!,
height: id2height.get(node.id)! + paddingTopPod,
}));
const tmpEdges = edges.map((edge) => ({
source: edge.source,
Expand Down Expand Up @@ -1029,7 +1032,7 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
simulation.tick(10);
tmpNodes.forEach((node) => {
node.x -= id2width.get(node.id)! / 2;
node.y -= id2height.get(node.id)! / 2;
node.y -= id2height.get(node.id)! / 2 - paddingTopPod;
});
// The nodes will all have new positions now. I'll need to make the graph to be top-left, i.e., the leftmost is 20, the topmost is 20.
// get the min x and y
Expand All @@ -1038,9 +1041,13 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
let y1s = tmpNodes.map((node) => node.y);
let miny = Math.min(...y1s);
// calculate the offset, leave 50 padding for the scope.
const padding = 50;
const offsetx = padding - minx;
const offsety = padding - miny;
// Leave some room at the top of the scope for inner pod toolbars.
const paddingTop = 70;
const paddingBottom = 50;
const paddingLeft = 50;
const paddingRight = 50;
const offsetx = paddingLeft - minx;
const offsety = paddingTop - miny;
// move the nodes
tmpNodes.forEach((node) => {
node.x += offsetx;
Expand Down Expand Up @@ -1072,12 +1079,12 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
const scope = nodesMap.get(scopeId);
nodesMap.set(scopeId, {
...scope!,
width: maxx - minx + padding * 2,
height: maxy - minx + padding * 2,
width: maxx - minx + paddingLeft + paddingRight,
height: maxy - miny + paddingTop + paddingBottom,
style: {
...scope!.style,
width: maxx - minx + padding * 2,
height: maxy - minx + padding * 2,
width: maxx - minx + paddingLeft + paddingRight,
height: maxy - miny + paddingTop + paddingBottom,
},
});
}
Expand Down