Excluding Part sub-components from diagram image


We are using Diagram.makeImageData() to export our diagrams as images. We would like some elements that are visible in a live diagram to be excluded from its image representation.

We are aware of the various ways this can be done for Parts (temporary layers, makeImageData’s “parts” parameter, etc), however we would need more granular control, i.e. the ability to exclude Part sub-components such as Panels, Shapes, etc.

Here’s an example to give an idea of the use cases we’d like to cover: our nodes comprise a label, an image and a custom expand/collapse button allowing the user to show/hide related nodes. When exporting the diagram to an image, we would like to keep each node’s label and image, but exclude the button. That button being implemented as a Panel, is there any way to prevent it from showing up in the exported image?

Thanks in advance for any advice regarding this.

You could set the GraphObject.opacity to zero on those GraphObjects, before you call makeImage, and then set it back.

(Don’t set GraphObject.visible to false, because that might cause the Panels to lay out differently.)

I had thought about iterating through the GraphObjects and hiding them prior to the call to makeImage, but I wanted to make sure there wasn’t a simpler or more elegant solution first.

Thank you guys for the nice pointer about relying on GraphObject.opacity rather than GraphObject.visible to achieve this.