kaluginserg / cytoscape-node-html-label

Labels for cytoscape node. Demo:
https://kaluginserg.github.io/cytoscape-node-html-label/
MIT License
100 stars 42 forks source link

Update parent when dragging a child node. #17

Closed joeltg closed 5 years ago

joeltg commented 5 years ago

First, thanks so much for creating this extension! You've saved me boatloads of time.

Compound (== "parent") nodes in Cytoscape don't receive the drag events of their children (although drag events on child nodes bubble up to their parent node). This means that dragging the compound parent successfully updates the positions of both the parent's HTML label and (recursively) all its children, dragging a child node won't update the the position of the parent's HTML label. This means that if you drag a child outside the previous bounding box of its parent, Cytoscape will render the new bounding box correctly, but the HTML label remain stuck in the old position until something else updates it (like dragging the compound node directly).

All that we need to do to update this is bind the same moveCyHandler to the bounds event, which is fired for every compound node whenever its bounding box is changed. It's not publicly documented, but mentioned (and recommended!) here with intent to document it soon.