From 3340b1b7acc9cb362488e753303277bb4d5d2286 Mon Sep 17 00:00:00 2001 From: flatberg Date: Thu, 11 Jan 2007 13:07:54 +0000 Subject: [PATCH] Added support for union/intersection selections --- fluents/plots.py | 58 ++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/fluents/plots.py b/fluents/plots.py index d55f6dc..1c90695 100644 --- a/fluents/plots.py +++ b/fluents/plots.py @@ -459,7 +459,23 @@ class Plot (View): """ self.selection_listener = listener + def update_selection(self, ids, key): + """Returns updated current selection from ids. + If a key is pressed we use the appropriate mode. + + key map: + shift : union + control : intersection + """ + if key == 'shift': + ids = set(ids).union(self._current_selection[self.current_dim]) + elif key == 'control': + ids = set(ids).intersection(self._current_selection[self.current_dim]) + else: + pass + return ids + class LineViewPlot(Plot): """Line view plot with percentiles. @@ -609,7 +625,7 @@ class ScatterMarkerPlot(Plot): self.add(self.canvas) self.canvas.show() - def rectangle_select_callback(self, x1, y1, x2, y2): + def rectangle_select_callback(self, x1, y1, x2, y2, key): ydata = self.yaxis_data xdata = self.xaxis_data @@ -622,6 +638,7 @@ class ScatterMarkerPlot(Plot): assert y1<=y2 index = scipy.nonzero((xdata>x1) & (xdatay1) & (ydatax1) & (xdatay1) & (ydata0: - lw.put(2.,index) + lw.put(2., index) self.coll.set_linewidth(lw) if self.use_blit: @@ -772,12 +788,14 @@ class NetworkPlot(Plot): kw['prog'] = 'neato' if not kw.has_key('pos') or kw['pos']: kw['pos'] = networkx.graphviz_layout(self.graph, kw['prog']) + if not kw.has_key('nodelist'): + kw['nodelist'] = self.dataset.get_identifiers(self.dim_name, sorted=True) Plot.__init__(self, kw['name']) self.current_dim = self.dim_name # Keep node size and color as dicts for fast lookup self.node_size = {} - if kw.has_key('node_size') and cb.iterable(kw['node_size']): + if kw.has_key('node_size') and cbook.iterable(kw['node_size']): kw.remove('node_size') for id, size in zip(self.dataset[self.dim_name], kw['node_size']): self.node_size[id] = size @@ -786,7 +804,7 @@ class NetworkPlot(Plot): self.node_size[id] = 30 self.node_color = {} - if kw.has_key('node_color') and cb.iterable(kw['node_color']): + if kw.has_key('node_color') and cbook.iterable(kw['node_color']): kw.remove('node_color') for id, color in zip(self.dataset[self.dim_name], kw['node_color']): self.node_color[id] = color @@ -812,13 +830,12 @@ class NetworkPlot(Plot): # Initial draw networkx.draw_networkx(self.graph, ax=self.ax, **kw) - print "Current dim is now: %s" %self.current_dim + del kw['nodelist'] def get_toolbar(self): return self._toolbar - def rectangle_select_callback(self, x1, y1, x2, y2): - print "In select callbak, current dim is now: %s" %self.current_dim + def rectangle_select_callback(self, x1, y1, x2, y2, key): pos = self.keywords['pos'] ydata = scipy.zeros((len(pos),), 'l') xdata = scipy.zeros((len(pos),), 'l') @@ -837,9 +854,7 @@ class NetworkPlot(Plot): y1, y2 = y2, y1 index = scipy.nonzero((xdata>x1) & (xdatay1) & (ydata