Makie max pan zoom

i’d like to put a maximum on how much a user can pan or zoom out on a plot. but i could not find a function in the makie docs to set an upper bound on the axis limits. so i hacked it like this:

using GLMakie
f,a,s = scatter([1,2,3])
on(a.finallimits) do x
    if x.origin[2]>5 
        a.finallimits[] = GLMakie.GeometryBasics.HyperRectangle{2, Float32}([x.origin[1], 5], x.widths)
    end
end

try panning upwards. you can’t go above the lower y-value being 5 now.

but is there a more cannonical way to do this? did i just miss a function to do this for you? seems like it would be a nice feature to have.

small correction-- targetlimits should be modified not finallimits.

so here then is an example which prevents the user from zooming out further than the limits of the data:

using GLMakie
x, y = rand(10), rand(10)
f,a,s = scatter(x,y)
on(a.finallimits) do fl
    o1 = max(fl.origin[1], minimum(x))
    o2 = max(fl.origin[2], minimum(y))
    w1 = min(fl.widths[1]+fl.origin[1], maximum(x))-o1
    w2 = min(fl.widths[2]+fl.origin[2], maximum(y))-o2
    a.targetlimits[] = GLMakie.GeometryBasics.HyperRectangle{2, Float32}([o1,o2],[w1,w2])
end

i believe an optional feature like this is genuinely useful.

one way to build this into Makie would be to add a bounds variable to the Axis struct, and then insert a max and min in the ScrollZoom interaction to enforce it. i didn’t go to the trouble of submitting a PR due to the lackluster response this post created.

alternatively, one could deactivate_interaction! the default, and add your own, which included these modifications.