Pan / move the canvas so that a specific node comes at a specific positon on the screen #609
-
|
Hi, I have the following use case that does not seem to be supported or not well documented (yet).
So for example, the position of that specific node might be x:500, y:500. So it's closely related to centering a node, but instead of centering it, putting it top left :) I hope it makes sense, not sure how to put it differently :D I tried like this, but it doesn't seem to work ... Thx! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Feels related to: |
Beta Was this translation helpful? Give feedback.
-
|
Hi, thanks for the detailed description! The You can achieve this with private viewportService = inject(NgDiagramViewportService);
private modelService = inject(NgDiagramModelService);
selectAndScrollToTopLeft(nodeId: string, margin = 16): void {
const node = this.modelService.nodes().find(n => n.id === nodeId);
if (!node) return;
const { scale } = this.viewportService.viewport();
this.viewportService.moveViewport(
margin - node.position.x * scale,
margin - node.position.y * scale,
);
}
|
Beta Was this translation helpful? Give feedback.
Hi, thanks for the detailed description!
The
centerOnRectapproach won't work here because it always centers the rect in the viewport, and it requireswidth > 0andheight > 0(passing0causes it to silently do nothing).You can achieve this with
moveViewportinstead . It sets the viewport position directly: