Skip to content

Commit

Permalink
Fix: initial workspace centering
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Apr 1, 2024
1 parent d7a384c commit 9f14d02
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/hooks/events/workspace-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@ const useWorkspaceLoad = (props: ISTKProps) => {
if (props.data) {
store.dispatch(sync(props.data));
setTimeout(() => {
const { height: workspaceheight, width: workspaceWidth } = d3Extended.selectionBounds(
d3Extended.selectById(ids.workspace)
);
const {
height: workspaceheight,
width: workspaceWidth,
top: workspaceTop,
left: workspaceLeft
} = d3Extended.selectionBounds(d3Extended.selectById(ids.workspace));
const workspaceGroup = d3Extended.select(selectors.workspaceGroup);
const {
left: wgOffsetLeft,
top: wgOffsetTop,
height: workspaceGroupHeight,
width: workspaceGroupWidth
} = d3Extended.selectionBounds(workspaceGroup);
let scaleFactor = props.data.workspace?.initialViewBoxScale ?? 1;
if (props.data.workspace?.visibilityOffset) {
workspaceGroup.attr(dataAttributes.visibilityOffset, props.data.workspace.visibilityOffset);
if (workspaceGroupHeight && workspaceGroupWidth) {
let scaleFactor = props.data.workspace?.initialViewBoxScale ?? 1;
if (props.data.workspace?.visibilityOffset) {
workspaceGroup.attr(dataAttributes.visibilityOffset, props.data.workspace.visibilityOffset);
}
scaleFactor *= 1.05;
panAndZoom({
k: scaleFactor,
y:
(workspaceheight + workspaceTop - (wgOffsetTop * scaleFactor * 2 + workspaceGroupHeight * scaleFactor)) /
2,
x:
(workspaceWidth + workspaceLeft - (wgOffsetLeft * scaleFactor * 2 + workspaceGroupWidth * scaleFactor)) /
2
});
store.dispatch(initializeWorkspace());
}
scaleFactor *= 1.05;
panAndZoom({
k: scaleFactor,
y: (workspaceheight - (wgOffsetTop * scaleFactor * 2 + workspaceGroupHeight * scaleFactor)) / 2 - 10,
x: (workspaceWidth - (wgOffsetLeft * scaleFactor * 2 + workspaceGroupWidth * scaleFactor)) / 2
});
store.dispatch(initializeWorkspace());
}, 0);
} else {
store.dispatch(initializeElements());
Expand Down

0 comments on commit 9f14d02

Please sign in to comment.