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

[BUG] PointDrawTool does not work for 'graph_renderer.node_renderer' #9399

Open
FabiJa opened this issue Nov 11, 2019 · 3 comments
Open

[BUG] PointDrawTool does not work for 'graph_renderer.node_renderer' #9399

FabiJa opened this issue Nov 11, 2019 · 3 comments

Comments

@FabiJa
Copy link

FabiJa commented Nov 11, 2019

Hi,
the PointDrawTool does not work with an imported networkx graph. I am asking because I would like to interactively move the nodes of a networkx graph.

My minimal code example is the following:

import networkx as nx

from bokeh.io import show, output_file
from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, BoxZoomTool, ResetTool, PointDrawTool
from bokeh.models.graphs import from_networkx
from bokeh.palettes import Spectral4

import bokeh.plotting as bpl

bpl.output_notebook()

# Prepare Data
G = nx.karate_club_graph()

SAME_CLUB_COLOR, DIFFERENT_CLUB_COLOR = "black", "red"
edge_attrs = {}

for start_node, end_node, _ in G.edges(data=True):
  edge_color = SAME_CLUB_COLOR if G.nodes[start_node]["club"] == G.nodes[end_node]["club"] else DIFFERENT_CLUB_COLOR
  edge_attrs[(start_node, end_node)] = edge_color

nx.set_edge_attributes(G, edge_attrs, "edge_color")

# Show with Bokeh
plot = Plot(plot_width=400, plot_height=400,
          x_range=Range1d(-1.1, 1.1), y_range=Range1d(-1.1, 1.1))
plot.title.text = "Graph Interaction Demonstration"

node_hover_tool = HoverTool(tooltips=[("index", "@index"), ("club", "@club")])

graph_renderer = from_networkx(G, nx.spring_layout, scale=1, center=(0, 0))

graph_renderer.node_renderer.glyph = Circle(size=15, fill_color=Spectral4[0])
graph_renderer.edge_renderer.glyph = MultiLine(line_color="edge_color", line_alpha=0.8, line_width=1)

plot.add_tools(node_hover_tool, BoxZoomTool(), ResetTool(), PointDrawTool(renderers = [graph_renderer.node_renderer], empty_value = 'black'))

plot.renderers.append(graph_renderer)

output_file("interactive_graphs.html")
show(plot)

Thanks.

Already discussed here.

@FabiJa FabiJa added the TRIAGE label Nov 11, 2019
@bryevdv
Copy link
Member

bryevdv commented Nov 12, 2019

cc @philippjfr any thoughts on this? Offhand I think the only way this makes sense is with an entirely new tool that understands graph renderers explicitly. While there is probably a fairly trivial change to make the existing tool "work" with node renderers, the that would only let people move nodes but leave edges are they are to start, which seems less than useful.

Edit: or alternatively the existing tool could be special cased to understand being passed a GraphRenderer (not one of the sub-renderers)

Also all this said I can't think of any way to make this work usefully with a non-default layout provider.

@p-himik
Copy link
Contributor

p-himik commented Jul 18, 2020

A recent question about this functionality on SO: https://stackoverflow.com/q/62950074/564509

@philippjfr
Copy link
Contributor

I think for the default LayoutProvider it probably wouldn't be too hard to support this but as you said for a StaticLayoutProvider I don't think there's anything sensible we can do. That said it may be nice to finally implement a BezierLayoutProvider or similar which is the main use case I've had to use a non-default layout provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants