Select point from graph, use button to store?

I have a plot that I want to pick a point from. Once I select the correct point, I want to press a button to store it (using PostgreSQL). Currently, when I press the ‘save’ button, it selects a different point and stores the coordinates of the new point. I was hoping it would only select a point if I clicked on the axis with the plot and not update if I click somewhere else. Is there something I can do to facilitate that?

The following is a smaller working example of what I am doing. I may be showing my ignorance of the whole affair, so if there is a much simpler way of doing this, please let me know

using GLMakie
using LibPQ

fig = Figure()
topGrid = fig[1:2,1] = GridLayout(default_colgap=0,rowgap=1,padding=(0.0,0.0,0.0,0.0))
ax = GLMakie.Axis(topGrid[1,1])
guiTextboxGrid = topGrid[2,1] = GridLayout(default_colgap=0,rowgap=1,padding=(0.0,0.0,0.0,0.0))
global textboxes = Vector{Any}(undef,2)
textboxes[1] =  Textbox(guiTextboxGrid[1,1], reset_on_defocus=true,placeholder = "Diameter", height=40,width=150,fontsize=22)
textboxes[2] =  Textbox(guiTextboxGrid[2,1], reset_on_defocus=false,placeholder = "value", height=40,width=150,fontsize=22)
btn = Button(fig, label = "Update Diameter")
guiTextboxGrid[2, 2] = [btn]

numpts = 10
x = 1:numpts
y = 2*x
positions = (Point2f[])
for i = 1:numpts
    push!(positions,(x[i],y[i]))
end
positions = Observable(positions)
p = lines!(ax,positions)

on(events(ax).mousebutton, priority = 2) do event
    if event.button == Mouse.left && event.action == Mouse.press
        plt,i = pick(fig)
        colors = ones(numpts)
        colors[i] = 10
        p = scatter!(positions, color = colors, colormap = :viridis)
        Makie.set!(textboxes[2],"$(y[i])")
        end
end

on(btn.clicks) do _
    dia = parse(Float64,textboxes[2].displayed_string[])
    cmdwrite = "INSERT INTO table(id, dia) VALUES('$channel', $dia) ON CONFLICT (id) DO UPDATE SET dia = EXCLUDED.dia;"
    execute(connwrite, cmdwrite)
end

1 Like

pick in this configuration will use any thing in the whole Figure, you would need to check that the picked plot plt is the one you care about

1 Like