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
@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
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
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).
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!