Todd Barry
Todd Barry

Reputation: 41

How can I fix the node's coordinates relative to the screen?

I need to attach a node to a point on the screen. It is required to displace this node when panning and zooming so that it does not change its position and size relative to the screen. That is, so that it looks like a menu button that does not change when panning and zooming.

Some attempts to implement this through the calculation of cy.pan() and node.position(), node.relativePosition() did not give the desired result.

Upvotes: 2

Views: 445

Answers (1)

Todd Barry
Todd Barry

Reputation: 41

Sorry, I incorrectly used the parameters I called. I did not correctly interpret their meaning. This code works correctly.

cy.on('pan', function(){
    pos = cy.pan();
    rel = {x: 20, y: 20};
    zoom = cy.zoom();
    node.position({
        x: (rel.x - pos.x) / zoom,
        y: (rel.y - pos.y) / zoom
    });
});

Upvotes: 2

Related Questions