Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interactions broken on new Makie #82

Closed
visr opened this issue May 24, 2022 · 3 comments
Closed

interactions broken on new Makie #82

visr opened this issue May 24, 2022 · 3 comments

Comments

@visr
Copy link

visr commented May 24, 2022

I saw that #80 addd Makie 0.17 support. However it seems that with Makie 0.17 the interaction examples from http://juliaplots.org/GraphMakie.jl/dev/generated/interactions/ don't work anymore.

This is the code I use, identical to the docs except for using GLMakie, and adding a log statement to the event handlers.

# ] add GLMakie GraphMakie Graphs Colors
# [5ae59095] Colors v0.12.8
# [e9467ef8] GLMakie v0.6.3
# [1ecd5474] GraphMakie v0.3.5
# [86223c79] Graphs v1.7.0

using GLMakie
using GraphMakie
using Graphs
using Colors

g = wheel_graph(10)
f, ax, p = graphplot(g,
                     edge_width = [2.0 for i in 1:ne(g)],
                     edge_color = [colorant"gray" for i in 1:ne(g)],
                     node_size = [10 for i in 1:nv(g)],
                     node_color = [colorant"red" for i in 1:nv(g)])
hidedecorations!(ax); hidespines!(ax)
ax.aspect = DataAspect()

deregister_interaction!(ax, :rectanglezoom)

# node click interaction
function node_click_action(idx, args...)
    @info "node_click_action" idx
    p.node_color[][idx] = rand(RGB)
    p.node_color[] = p.node_color[]
end
nclick = NodeClickHandler(node_click_action)
register_interaction!(ax, :nclick, nclick)

# hover interaction
function node_hover_action(state, idx, event, axis)
    @info "node_hover_action" idx
    p.node_size[][idx] = state ? 20 : 10
    p.node_size[] = p.node_size[] # trigger observable
end
nhover = NodeHoverHandler(node_hover_action)
register_interaction!(ax, :nhover, nhover)

f

If I then downgrade to the previous GraphMakie, v0.3.4, which brings along GLMakie v0.5.5, the interactions work again.

@visr
Copy link
Author

visr commented May 25, 2022

I tried to look into this a bit. Didn't get to any solution, but the additional info might be helpful.

For the case of node click handlers, nothing happens because of the last if statement below always being false. It seems that a click on a node used to give back the Scatter plot of the nodes, and now it returns a Mesh.

https://github.com/JuliaPlots/GraphMakie.jl/blob/cb19bae27141c32ded7a5ccafc6461edb69dae10/src/interaction.jl#L371-L374

In MakieOrg/Makie.jl#1658 mouse_selection was deprecated for pick, but replacing that doesn't work. Still it might be related. The new point picking docs are here: https://makie.juliaplots.org/stable/documentation/events/#point_picking

So what is this Mesh that it returns, and how do we get the Scatter plot of nodes back with pick (get_node_plot(gp::GraphPlot))?

@hexaeder
Copy link
Collaborator

hexaeder commented May 25, 2022

Thanks for bringing this up. I played around a bit but could not resolve it yet. Using the simple code below you can see that the interactions still work but the reportet elements are infact not the ones below the cursor but a bit offset. However both node and edge interactions work.

Maybe there is some problem with whether the mouse position is calculated with respect to the axis or the figure?

g = wheel_graph(10)
f, ax, p = graphplot(g,
                     edge_width = [2.0 for i in 1:ne(g)],
                     edge_color = [colorant"gray" for i in 1:ne(g)],
                     node_size = [10 for i in 1:nv(g)],
                     node_color = [colorant"red" for i in 1:nv(g)])
hidedecorations!(ax); hidespines!(ax)
deregister_interaction!(ax, :rectanglezoom)

function node_hover_action(state, idx, event, axis)
    p.node_size[][idx] = state ? 20 : 10
    p.node_size[] = p.node_size[] # trigger observable
end
nhover = NodeHoverHandler(node_hover_action)
register_interaction!(ax, :nhover, nhover)

function edge_hover_action(state, idx, event, axis)
    p.edge_width[][idx]= state ? 5.0 : 2.0
    p.edge_width[] = p.edge_width[] # trigger observable
end
ehover = EdgeHoverHandler(edge_hover_action)
register_interaction!(ax, :ehover, ehover)

@visr
Copy link
Author

visr commented Jun 10, 2022

I checked, and this example now works well on the newly released Makie v0.17.4. Thanks for tracking the issue upstream!

@visr visr closed this as completed Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants