cytoscape / cytoscape.js-klay

The Klay layout algorithm for Cytoscape.js
MIT License
86 stars 41 forks source link

Left alignment assumed in node labels #35

Closed itf closed 3 years ago

itf commented 3 years ago

When using the option nodedimensionsincludelabels, there is an implicit assumption that the node will be to the left of the label, and that the label is larger than the width of the node.

If, for example, the label is horizontally centered in the node, we need to change the getPos function to add (nodeWidth/2) to the first step where p.x is being updated.

Otherwise, if the label is long, it will intersect with other nodes.

I believe the same is true for p.y. we need to add nodeHeight/2 in the first time it's updated, otherwise tall labels will intersect other nodes.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale, because it has not had activity within the past 30 days. It will be closed if no further activity occurs within the next 30 days. If a feature request is important to you, please consider making a pull request. Thank you for your contributions.

maxkfranz commented 3 years ago

As you may be already aware from your research: Unless the layout algorithm itself can be aware of label orientations, the best general solution is to notify the layout that additional width and height should be used. This simply tells the layout to give a node extra space for long labels. This works well when labels are centred, which is often the case.

If you have specific suggestions for customising the official Klay algorithm , you're welcome to comment there. If you have suggestions for better integrations with existing Klay algorithm options, you're welcome to make a PR here.

Thanks for your feedback