Skip to content
Discussion options

You must be logged in to vote

Hi, thanks for the detailed description!

The centerOnRect approach won't work here because it always centers the rect in the viewport, and it requires width > 0 and height > 0 (passing 0 causes it to silently do nothing).

You can achieve this with moveViewport instead . It sets the viewport position directly:

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 * 

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@samvloeberghs
Comment options

Answer selected by samvloeberghs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants