Prevent calling scrollToPart if node is x% (or majorly) visible on viewport

Hi Walter,

In my diagram, when a node not completely visible on viewport is selected, I am calling scrollToPart to make the node visible in the viewport. I am using below to check the visibilty condition -

diagram.viewportBounds.containsRect(selection.actualBounds)

Now, I have a requirement where -

  • If the node is x% (e.g. 80%) visible, then we don’t want call scrollToPart to make it visible

Can you please help?

Thanks

I would compare the area of the node (its actualBounds) with the area of its intersection with the viewport:

myDiagram.viewportBounds.copy().intersectRect(node.actualBounds)