'Zoom in a selected node

I come to you because I am trying to implement a feature to zoom in on a node I have selected.

For this, I used the camera and the animated function by providing the coordinates of my node and my zoom ratio: 0.1.

However, when I zoom on my node the zoom does not center on my node because when I zoom the coordinates of my camera change and do not seem to follow a logic allowing me to add a director coefficient.

Here is my code:

let camera = this.renderer.getCamera();
      
        camera.animate({
            x: this.graph.getNodeAttribute(node.id, "x"),
            y: this.graph.getNodeAttribute(node.id, "y"),               
        });

        camera.setState({ x: this.graph.getNodeAttribute(node.id, "x"), y: this.graph.getNodeAttribute(node.id, "y") })

        camera.animate({
            ratio: 0.1
        });

Thanks everyone for your help !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source