Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible to conditionally disable the node-editing function for a particular node? #40

Open
cbisaccia78 opened this issue Mar 23, 2021 · 1 comment

Comments

@cbisaccia78
Copy link

cbisaccia78 commented Mar 23, 2021

I want to disable the ability to resize a node if the map is zoomed out far enough, so as to prevent accidental resizing. I tried to implement this using the isNoControlsMode function provided during initialization:
isNoControlsMode: function(node){
var z = cy.zoom();
var cyW = cy.container().clientWidth;
var cyH = cy.container().clientHeight;
var nW = node.width();
var nH = node.height();
if((nW*nH*z)/(cyW*cyH) < .0005 ){
return true
}
return false
}
This approach works sometimes, but for some reason it is very finnicky. I'm wondering if this is the correct approach for such a problem/if I am misusing is isNoControlsMode function?

@msalihaltun
Copy link
Contributor

Hello @cbisaccia78. I think this would be the right approach.

The reason it might be "finnicky" as you suggested might be because of the difference between model positions and rendered positions. Your cy.container().clientWidth will give you the container DOM object's width, whereas node.width() will give you the model width of the node. More about cytoscape position logic here.

I suggest you use either rendered sizes of both the cytoscape container and nodes (maybe use eles.renderedBoundingBox()) or the model sizes of both with cy.extent() and test that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants