# Select point from graph, use button to store?

**URL:** <https://discourse.julialang.org/t/select-point-from-graph-use-button-to-store/104323>\
**Category:** General Usage\
**Tags:** plotting, glmakie, observables\
**Created:** [September 27, 2023, 5:36pm UTC](https://discourse.julialang.org/t/select-point-from-graph-use-button-to-store/104323 "2023-09-27T17:36:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkzwart](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@dkzwart](https://discourse.julialang.org/u/dkzwart)\
**Post date:** [September 27, 2023, 5:36pm UTC](https://discourse.julialang.org/t/select-point-from-graph-use-button-to-store/104323/1 "2023-09-27T17:36:51Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [September 27, 2023, 6:35pm UTC](https://discourse.julialang.org/t/select-point-from-graph-use-button-to-store/104323/2 "2023-09-27T18:35:40Z")

</div>

> [@dkzwart](#):
>
> `plt`

`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
