graph_tool.draw.interactive_window

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

graph_tool.draw.interactive_window

Rolf Sander
Hello,

The function graph_tool.draw.interactive_window is great for exploring a
graph interactively. Often I just need some part of a graph, for which I
can easily define a filter (or view). My question is: Is it possible to
switch between the full graph and a filtered subset of the graph
interactively? I tried something like the code below but it didn't work:

def my_key_press_callback(self, g, keyval, picked, pos, vprops, eprops):
     if (chr(keyval)=='1'):
         self.g = g1
         self.queue_draw()
     if (chr(keyval)=='2'):
         self.g = g2
         self.queue_draw()

g1 = gt.load_graph("mygraph.xml.gz")
g2 = gt.GraphView(g1, vfilt=SOMEFILTER)
gt.interactive_window(g1, key_press_callback=my_key_press_callback)

Any suggestions are appreciated.

Best regards
Rolf

ps: Sorry if you receive this email twice; my previous post somehow
     ended up hidden in an old thread.

--
-----------------------------------------------------------------------
   Rolf Sander                              phone: [+49] 6131/305-4610
   Max-Planck Institute of Chemistry        email: [hidden email]
   PO Box 3060, 55020 Mainz, Germany     homepage: www.rolf-sander.net
-----------------------------------------------------------------------
               https://www.encyclopedia-of-geosciences.net
             https://www.geoscientific-model-development.net
-----------------------------------------------------------------------
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: graph_tool.draw.interactive_window

Tiago Peixoto
Administrator
Am 10.05.20 um 11:14 schrieb Rolf Sander:

> Hello,
>
> The function graph_tool.draw.interactive_window is great for exploring a
> graph interactively. Often I just need some part of a graph, for which I
> can easily define a filter (or view). My question is: Is it possible to
> switch between the full graph and a filtered subset of the graph
> interactively? I tried something like the code below but it didn't work:
>
> def my_key_press_callback(self, g, keyval, picked, pos, vprops, eprops):
>     if (chr(keyval)=='1'):
>         self.g = g1
>         self.queue_draw()
>     if (chr(keyval)=='2'):
>         self.g = g2
>         self.queue_draw()
I'm afraid this will never work; you cannot replace the underlying graph
from under the hood like this. What you can do, however, is to work with
the same filtered graph the whole time, and then change the values of
the filter property map dynamically.

Best,
Tuago

--
Tiago de Paula Peixoto <[hidden email]>


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool

signature.asc (849 bytes) Download Attachment
--
Tiago de Paula Peixoto <tiago@skewed.de>
Reply | Threaded
Open this post in threaded view
|

Re: graph_tool.draw.interactive_window

Rolf Sander
In reply to this post by Rolf Sander
Hello Tiago,

 > you cannot replace the underlying graph from under the hood like this.
 > What you can do, however, is to work with the same filtered graph the
 > whole time, and then change the values of the filter property map
 > dynamically.

Thanks for the hint, this is exactly what I need!

In case anyone else is interested in this great feature, I've written a
small minimal working example, see below.

Best regards
Rolf


##############################################################################

import graph_tool.all as gt

def mykeypressed(self, g, keyval, picked, pos, vprops, eprops):
     if (chr(keyval)=='1'):
         g.vp.myfilter.a = True
         self.fit_to_window()
         self.regenerate_surface(reset=True)
         self.queue_draw()
     if (chr(keyval)=='2'):
         g.vp.myfilter.a = True
         g.vp.myfilter.a = [n%2==0 for n in g.vertex_index]
         self.fit_to_window()
         self.regenerate_surface(reset=True)
         self.queue_draw()
     if (chr(keyval)=='3'):
         g.vp.myfilter.a = True
         g.vp.myfilter.a = [n%3==0 for n in g.vertex_index]
         self.fit_to_window()
         self.regenerate_surface(reset=True)
         self.queue_draw()

g1 = gt.random_graph(10, lambda: (3, 3))
g1.vp.myfilter = g1.new_vertex_property('bool')
g1.vp.myfilter.a = True
g1.set_vertex_filter(g1.vp.myfilter)
gt.interactive_window(g1, key_press_callback=mykeypressed,
                       vertex_text=g1.vertex_index)

##############################################################################


--
-----------------------------------------------------------------------
   Rolf Sander                              phone: [+49] 6131/305-4610
   Max-Planck Institute of Chemistry        email: [hidden email]
   PO Box 3060, 55020 Mainz, Germany     homepage: www.rolf-sander.net
-----------------------------------------------------------------------
               https://www.encyclopedia-of-geosciences.net
             https://www.geoscientific-model-development.net
-----------------------------------------------------------------------
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool