1

I am working on a graph visualization and I need a way to interact with a bokeh figure in such a way that clicking on a glyph brings it to the front.

My data is as follows. For nodes:

                    x_axis  y_axis

Supplier 1          -2.0    0.0
Supplier 2          -1.8    0.3
Supplier 3          -2.0    6.0
System Integrator   -1.0    0.0
Availability Zone 1  0.0    0.0
Availability Zone 2  0.0    3.0
Availability Zone 3  0.2    3.3

for edges:

                                                        start   end
('Supplier 1', 'System Integrator', 'Rack')             Supplier 1  System Integrator
('Supplier 2', 'System Integrator', 'Memory')           Supplier 2  System Integrator
('Supplier 3', 'System Integrator', 'Rack')             Supplier 3  System Integrator
('System Integrator', 'Availability Zone 1', 'Rack')    System Integrator   Availability zone 1
('System Integrator', 'Availability Zone 2', 'Rack')    System Integrator   Availability Zone 2
('System Integrator', 'Availability Zone 3', 'Rack')    System Integrator   Availability Zone 3

and my code for plotting

import  bokeh.plotting as bp
from bokeh.palettes import  Greys9
from bokeh.models import StaticLayoutProvider, \
                ColumnDataSource, renderers,Rect

fig = bp.figure()
graph_layout = dict(zip(nodes.index, zip(nodes.x_axis, nodes.y_axis)))
layout_provider = StaticLayoutProvider(graph_layout = graph_layout)


fig = bp.figure(title = "Supply Chain Network Flow"
            ,width=800
            ,height = 600
            ,background_fill_color=Greys9[6]
            ,background_fill_alpha=0
        )

g = fig.graph(nodes, edges, layout_provider, node_size = 100, edge_line_color='grey', edge_line_alpha = 0.1, edge_line_size = 0.1)
g.node_renderer.glyph = Rect(width = .5, height = 1,angle = 0)

bp.show(fig)

yields a figure like this one: graph

I would like to have a tool such that when clicking a node that is behind another one, it is moved to the front. This is my first time using bokeh, so I don´t know if this tool exist.

Lorenzo Gutiérrez
  • 105
  • 1
  • 1
  • 10

0 Answers0