# Makie: vlines! and mouse events

**URL:** <https://discourse.julialang.org/t/makie-vlines-and-mouse-events/69321>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [October 6, 2021, 6:16pm UTC](https://discourse.julialang.org/t/makie-vlines-and-mouse-events/69321 "2021-10-06T18:16:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [October 6, 2021, 6:16pm UTC](https://discourse.julialang.org/t/makie-vlines-and-mouse-events/69321/1 "2021-10-06T18:16:59Z")

</div>

Hi,  
another Julia moment which lasts too long.  
Got stuck when trying to change the manual example to a vertical crosshair:

```julia
using GLMakie
GLMakie.activate!()

fig, ax, p = scatter(rand(Point2f0, 100))
pos = Node([Point2f0(0)]) # observable
scatter!(ax, pos, marker = "+")
#vlines!.(ax, pos.val[1][2], color = :red) # <<<<<<<< how ?
display(fig)

# on move, higher priority that interactions (runs first)
on(events(ax.scene).mouseposition, priority = 2) do _
    if ispressed(ax.scene, Mouse.left)
        pos[] = [mouseposition(ax.scene)]
        return Consume(true) # this would block rectangle zoom
    end
    return Consume(false)
end

# on left click/release
on(events(ax.scene).mousebutton, priority = 2) do mb
    if mb.button == Mouse.left 
        pos[] = [mouseposition(ax.scene)]
        return Consume(true)
    end
    return Consume(false)
end

```

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [October 6, 2021, 8:16pm UTC](https://discourse.julialang.org/t/makie-vlines-and-mouse-events/69321/2 "2021-10-06T20:16:10Z")

</div>

If you use `pos.val` you’re accessing the data stored in the observable. So you’re just passing a value to vlines. You want to do something like `map(p -> [p[1][2]], pos)`. Though I think you can also just have `map(p -> p[2], pos)` with `pos[] = mouseposition(ax.scene)` in the event.

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [October 6, 2021, 8:32pm UTC](https://discourse.julialang.org/t/makie-vlines-and-mouse-events/69321/3 "2021-10-06T20:32:49Z")

</div>

Interesting, thx!

But how does it actually work?  
Why do scatter and vlines! get updated, given that they are not inside the on … if block?

```julia
using GLMakie
GLMakie.activate!()

fig, ax, p = scatter(rand(Point2f0, 100))
pos = Node([Point2f0(0)]) # observable
vlines!(ax, map(p -> [p[1][1]], pos))
display(fig)

# on move, higher priority that interactions (runs first)
on(events(ax.scene).mouseposition, priority = 2) do _
    if ispressed(ax.scene, Mouse.left)
        pos[] = [mouseposition(ax.scene)]
        scatter!(ax, pos, marker = "+")
        return Consume(true) # this would block rectangle zoom
    end
    return Consume(false)
end

# on left click/release
on(events(ax.scene).mousebutton, priority = 2) do mb
    if mb.button == Mouse.left 
        pos[] = [mouseposition(ax.scene)]
        return Consume(true)
    end
    return Consume(false)
end

```
