Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cytoscape.js: wrong mouse pointer position after container change

Tags:

cytoscape.js

I use cytoscape.js 2.2.5 to draw a graph in an angular.js app and I can properly select nodes. When the <div> with the graph moves, the mouse pointer position on the canvas is not updated. That means I have to click on the 'old' position of a node to select it.

I tried cy.reset(), cy.center() and cy.fit(), but the mouse pointer position doesn't change.

How can I update the graph after I change the position of the cytoscape <div>?

Original page:

enter image description here

After change of <div> position

When I remove the blue panel and the graph <div> moves up, the mouse pointer position is wrong. I use the ng-show directive (which uses css hidden/visible). enter image description here

like image 519
Martin Preusse Avatar asked May 04 '14 20:05

Martin Preusse


1 Answers

When you resize (or move, I suppose) the cy div, you need to notify the core of the change. Unfortunately, the browser DOM model doesn't have a way to track this automatically.

cy.resize(); // notify that the container has changed dims

http://cytoscape.github.io/cytoscape.js/#core/viewport-manipulation/cy.resize

Perhaps cy.resize() should have an alias like cy.invalidateDimensions() so it's clear you need it for your usecase.

like image 145
maxkfranz Avatar answered Oct 22 '22 01:10

maxkfranz