Obtaining the axis of a `Colorbar`

I am trying to implement a scroll-behaviour on a Colorbar placed in a gridlayout cell (e.g. fig[1,2]).
However, I cannot find out, how to obtain the corresponding axis, which I need to register_interaction!(ax) the scroll events.
So how does one obtain the axis of a given GridPosition or how does one get the axis from the cb=Colorbar(fig[1,2]) call?
I tried to call ax = Axis(fig[1,2]) for the same cell after the Colorbar was created, and this sort of works, but gives odd behaviour, as this seems to be a new axis, slightly displayed from the actual colorbar, which is seen, if you limit its size.

There’s no axis, only a scene, which doesn’t have the more complex interaction machinery, only base events. You get it via cbar.scene


Hmm. I see. So that means, I need to go via the “on()” mechanism to hook into mouse scroll events on the colorbar and test for mousepositon being inside the scene of the colorbar?

I think so, yes

1 Like

Unfortunately cb.scene does not work. Did you mean cb.parent?

Oh maybe I refactored it at some point and it doesn’t have its own scene. Then you just have to check if the mouse is in the colorbar rectangle, for the main figure scene

I see. Any hint on how to determine the corresponding rectangle either to the subfigure [1,2] or the colorbar?

I think I figured it out:

    scene = cb.parent.scene
    on(events(scene).scroll, priority = 2) do event
        mouse = scene.events.mouseposition[]
        c_start = cb.layoutobservables.suggestedbbox.val.origin
        c_stop = cb.layoutobservables.suggestedbbox.val.origin .+ cb.layoutobservables.suggestedbbox.val.widths
        if ! (all(mouse.>c_start) && all(mouse .<c_stop))
            return Consume(false)