# Makie interactions with nested plot

**URL:** <https://discourse.julialang.org/t/makie-interactions-with-nested-plot/80072>\
**Category:** Visualization\
**Tags:** makie, interactivity\
**Created:** [April 26, 2022, 3:49pm UTC](https://discourse.julialang.org/t/makie-interactions-with-nested-plot/80072 "2022-04-26T15:49:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Post date:** [April 26, 2022, 3:49pm UTC](https://discourse.julialang.org/t/makie-interactions-with-nested-plot/80072/1 "2022-04-26T15:49:03Z")

</div>

I am looking at using some 3rd party makie interactions for my recipe and I cannot seem to make it.  
I am leveraging the functionality of the `GraphPlot` recipe by wrapping it around a new application-specific recipe.  
Let’s take for example

```julia
@recipe(MyPlot, arg1, arg2) do scene
    Attributes(
               show_state = true,
               ...
    )
end

function Makie.plot!(myplot::MyPlot)
    ...
    ...
    GraphMakie.graphplot!(myplot, ...)
    return intplot
end

```

which I can plot with

```julia
f,ax,p = myplot(arg1, arg2)

```

Now I started looking at providing some interactions in my figure (actually already defined in GraphPlot.jl), but the example will not work: [Interaction Examples · GraphMakie.jl](https://juliaplots.org/GraphMakie.jl/stable/generated/interactions/#Drag-interactions)

```julia
function node_drag_action(state, idx, event, axis)
    p[:node_pos][][idx] = event.data
    p[:node_pos][] = p[:node_pos][]
end
ndrag = NodeDragHandler(node_drag_action)
register_interaction!(ax, :ndrag, ndrag)
ERROR: BoundsError: attempt to access 0-element Vector{AbstractPlot} at index [1]
Stacktrace:
 [1] getindex
   @ ./array.jl:861 [inlined]
 [2] registration_setup!(parent::Axis, inter::GraphMakie.DragHandler{Scatter, typeof(node_drag_action)})
   @ GraphMakie ~/.julia/dev/GraphMakie/src/interaction.jl:51
 [3] register_interaction!(parent::Axis, name::Symbol, interaction::GraphMakie.DragHandler{Scatter, typeof(node_drag_action)})
   @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/interactions.jl:19
 [4] top-level scope
   @ REPL[25]:1

```

This is because it looks only in the upper layer of my `ax` which only contains `MyPlot` and not a `GraphPlot`. This is because `GraphPlot.jl` doesn’t search recursively but only in `ax.scene.plots`. It would probably work if it was searching in `ax.scene.plots[2].plots`

Of course I respect the choice of the package author and I don’t see how a PR could help.  
I should though be able to dispatch the `registration_setup!` and provide my own implementation for `MyPlot`.  
But this doesn’t seem possible. I cannot dispatch `registration_setup!` for my type because it only accepts `Axis` and interaction (in this case `GraphInteraction` from GraphPlot.jl).  
`register_interaction!` also accepts just `Axis` ([Makie.jl/interactions.jl at 5ae4eef339be3a822323099c72c23d3b382cb969 · JuliaPlots/Makie.jl · GitHub](https://github.com/JuliaPlots/Makie.jl/blob/5ae4eef339be3a822323099c72c23d3b382cb969/src/makielayout/interactions.jl#L35)).

In other words I experience this to be somehow restrictive design for `Makie` because I cannot leverage already defined interactions in `GraphPlot.jl` for my recipe `MyPlot`.  
On the other hand maybe it’s just me being inexperienced and there is a nice workaround for this ?  
Thanks!
