iVis-at-Bilkent / cytoscape.js-grid-guide

A Cytsocape.js extension to provide a framework for grid interactions such as grid lines and snapping to grid, and guidelines and snap support for alignment of nodes.
MIT License
59 stars 9 forks source link

Nodes center to gridline and not the center of cell #36

Closed torbgy closed 5 years ago

torbgy commented 5 years ago

Hi!

Is it possible to snap nodes to the gridline? like that the node is snapped to the cross of the gridline instead of the center of the cell?

kinimesi commented 5 years ago

No, this is not possible. In the current implementation, the dragged node positioned in the center of the closest grid (cell).

gregroyal commented 5 years ago

is this possible to get worked? whats the technical limitations?

kinimesi commented 5 years ago

It could be as simple as not adding 0.5 factor when the snap position is calculated (I think using Math.round in this case makes more sense):

https://github.com/iVis-at-Bilkent/cytoscape.js-grid-guide/blob/9649d89aafd702b097456adccdcf0395a818907d/src/snap_on_release.js#L18

Test this and see if it has the effect you want (after modifying this line, snap during drag should snap to grid line as well).

This needs to be optional, so that one can switch between the original behavior and the new one. An option named snapToGridCenter can be defined (the default value should be true).

You can do a PR if you like.

gregroyal commented 5 years ago

Created PR https://github.com/iVis-at-Bilkent/cytoscape.js-grid-guide/pull/38 to address this with your implementation suggestion. It worked like a charm!

kinimesi commented 5 years ago

@torbgy this feature is now implemented. You can pull it from unstable branch.

gregroyal commented 5 years ago

Hows the release coming? I'm still using this featured as a one-off. Any updates on the next release?