Inserting a row or column in a Makie layout

Say I have an existing grid like this one:

using CairoMakie

f = Figure(resolution=(600, 200))
scatter(f[1,1], 1:3, 1:3)
scatter(f[1,2], 1:3, [0,0,0])
f

image

How can I insert a column between these two?

An idea would be to move everything contained in f[1,2] to f[1,3]), but can I do that?

GridLayoutBase has insertrows!and cols, should be exported?

Thanks! Yes it’s exported, though not by Makie itself so I used it like this:

f = Figure(resolution=(600, 200))
scatter(f[1,1], 1:3, 1:3)
scatter(f[1,2], 1:3, [0,0,0])
Makie.GridLayoutBase.insertcols!(f.layout, 2, 1)
Label(f[1,2], "Some text", tellheight=false)
f

image

I’m still curious though: is there a way to move a slot’s content to another slot?

You just assign it to a new location. If you don’t have the object you can use content() or if there are multiple objects contents() like f[1,4] = content(f[1,1]). The thing to remember is that the setindex operation on GridLayouts just connects an object to a layout, it doesn’t copy anything and it removes any previous connection there might have been, as each layoutable object can only have one parent.

Perfect, thanks!

For completeness here’s the code using that approach:

f = Figure(resolution=(600, 200))
scatter(f[1,1], 1:3, 1:3)
scatter(f[1,2], 1:3, [0,0,0])
f[1,3] = content(f[1,2])
Label(f[1,2], "Some text", tellheight=false)
f