GLMakie: hide control widgets before saving?

Using GLMakie I created a nice 3D view of my data surrounded by some widget (Sliders, Textboxes) to control the appearance (see below). If I now want to save this to a file I would like to only the data, the title and the color bar be included. My first idea was to hide the controls before calling save(), but unfortunately only a few widget support the visible property. Does somebody have an idea how to solve this problem? Are there some other means than visible to hide widgets? Or is it possible to only call save for a subselection of objects in a Figure?

Hm you can probably set obj.blockscene.visible[] = false on every control widget (blockscene is the container scene for all visual objects of a Block widget).

You don’t mind that you will have whitespace in all the places where widgets are hidden? If you do, you could also delete all those objects instead.

Easiest might be:

for i in reverse(eachindex(fig.content))
    c = fig.content[i]
    if !(c in list_of_objs_to_keep)
        delete!(c)
    end
end
trim!(fig.layout)

If you want to keep the figure intact because you need it after saving, another option might be to save the whole figure but crop the png to the boundingbox of the objects you want to keep (in your example that could work I guess?). You could get the boundingboxes of each by accessing obj.layoutobservables.computedbbox[] I think which you could then union together

Thanks very much for the various hints! Unfortunately, the first method leaves a lot of whitespace for the hidden widgets, as you already anticipated. And funnily for Textboxes only the box is hidden, not the text…

The second method is not optimal as I want to choose different views on the data and save each. So, deleting the widgets is a not a real option.

I’m now using the third method, as for my layout it’s possible to cut away the widgets with a simple crop. Implementing this I saw that obj.layoutobservables.computedbbox[] for colorbars only includes the bar but not the labels. For my layout this is not a problem, as they are always on the right side, so I simply can expand the crop-box to the right end of the window. But how could this be made working in general?

And I noticed that the call to save() closes the window. I can open it again in the same state and continue work. But is this expected behavior or a bug?

Thanks again!

I saw that obj.layoutobservables.computedbbox[] for colorbars only includes the bar but not the labels.

Ah right you have to also take protrusions into account, so plus the values in obj.layoutobservables.protrusions.

And you can save this way without closing:

screen = display(figure)
save("image.png", Makie.colorbuffer(screen))

Ah, cool! Directly accessing Makie.colorbuffer(screen) allows me also to skip the temporary file. And getting the screen from the fig itself via fig.scene.current_screens makes it easy to add a save button to the window widgets. (Hope both are a halfway stable interface, since they not documented or exported…)

I think so, and at least colorbuffer should probably be documented right @sdanisch ?