"gojs": "^2.2.15",
"gojs-react": "^1.1.1",
scrollToPart works pretty well when there is only one node selected, but I need it to also handle multiple nodes selected. Looking into docs and various other postings it doesn’t seem like this feature is intended for this use, and instead I should perhaps be using scrollToRect?
But while testing it out, everything is either a little off or way off leaving me unsure what could be missing since it doesn’t seem consistent. Though, it is possible that I’m mis-understanding/mis-using or straight up missing one of the many coordinate systems involved. But it also feels like a lot of custom logic for something that may also be built-in somewhere that I just haven’t found…
So my question is; Is there a built-in method for doing this? And if not, am I headed down the right path, but maybe just mis using some coordinates or missing some variable I need to account for?
let top;
let left;
let bottom;
let right;
diagram.selection.toArray().forEach(node => {
if (!top || node.location.y - node.height / 2 < top) {
top = node.location.y - node.height / 2;
}
if (!left || node.location.x - node.width / 2 < left) {
left = node.location.x - node.width / 2;
}
if (!bottom || node.location.y + node.height / 2 > bottom) {
bottom = node.location.y + node.height / 2;
}
if (!right || node.location.x + node.width / 2 > right) {
right = node.location.x + node.width / 2;
}
});
const selectionRect = new Rect(left, top, right, bottom);
diagram.scrollToRect(selectionRect);