Hi,
we are having an issue which calculating a position & scale change when double clicking on the diagram. We are trying to implement that when double clicking on the diagram the viewport will center to the click point and set the scale to 1 and do a transition animation from the current viewport size and position to this new one.
We have tried several different ways of calculating this animation but most of them have the issue when trying to change the position when the scale is also changing as the calculation is done before the scale and thus the viewport either overshoots or undershoots the new position.
The latest method we have tried is the following:
private onBackgroundDoubleClicked(event: DiagramEvent): void {
const { lastInput } = event.diagram;
const clickPoint = lastInput.documentPoint;
const newDiagramPoint = new Point(
clickPoint.x - this.diagram.viewportBounds.width / 2,
clickPoint.y - this.diagram.viewportBounds.height / 2
);
const animation = new Animation();
animation.add(this.diagram, 'scale', this.diagram.scale, 1);
animation.add(this.diagram, 'position', this.diagram.position, newDiagramPoint);
animation.start();
}
We also tried to use scrollToRect but this does not seem to allow scaling to be animated at the same time (presumably due to it handling its own animation?).
Are we thinking about this the wrong way when trying to implement this or is there a built in function that we have missed?