Added support for union/intersection selections
This commit is contained in:
parent
d4f5a92010
commit
3340b1b7ac
|
@ -459,6 +459,22 @@ 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) & (xdata<x2) & (ydata>y1) & (ydata<y2))[0]
|
||||
ids = self.dataset_1.get_identifiers(self.current_dim, index)
|
||||
ids = self.update_selection(ids, key)
|
||||
self.selection_listener(self.current_dim, ids)
|
||||
|
||||
def set_current_selection(self, selection):
|
||||
|
@ -716,7 +733,7 @@ class ScatterPlot(Plot):
|
|||
self.ax.draw_artist(self.sc)
|
||||
self.canvas.draw()
|
||||
|
||||
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
|
||||
|
||||
|
@ -729,14 +746,13 @@ class ScatterPlot(Plot):
|
|||
assert y1<=y2
|
||||
|
||||
index = scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))[0]
|
||||
|
||||
ids = self.dataset_1.get_identifiers(self.current_dim, index)
|
||||
ids = self.update_selection(ids, key)
|
||||
self.selection_listener(self.current_dim, ids)
|
||||
|
||||
def set_current_selection(self, selection):
|
||||
ids = selection[self.current_dim] # current identifiers
|
||||
if len(ids)==0:
|
||||
print "nothing selected"
|
||||
return
|
||||
#self._toolbar.forward() #update data lims before draw
|
||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||
|
@ -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) & (xdata<x2) & (ydata>y1) & (ydata<y2))[0]
|
||||
ids = [node_ids[i] for i in index]
|
||||
print "Updating listener from network with dim: %s" %self.current_dim
|
||||
print "ids: "
|
||||
print ids
|
||||
ids = self.update_selection(ids, key)
|
||||
self.selection_listener(self.current_dim, ids)
|
||||
|
||||
def set_current_selection(self, selection):
|
||||
|
@ -943,7 +958,7 @@ class PanPlotMode (PlotMode):
|
|||
self._button_press = None
|
||||
self._button_release = None
|
||||
self._motion_notify = None
|
||||
|
||||
self._xypress = None
|
||||
self._button_pressed = None
|
||||
|
||||
def activate(self):
|
||||
|
@ -1144,7 +1159,8 @@ class SelectPlotMode (PlotMode):
|
|||
|
||||
def _on_select(self, start, end):
|
||||
self.plot.rectangle_select_callback(start.xdata, start.ydata,
|
||||
end.xdata, end.ydata)
|
||||
end.xdata, end.ydata, end.key)
|
||||
|
||||
|
||||
|
||||
class PlotToolbar(gtk.Toolbar):
|
||||
|
@ -1158,11 +1174,10 @@ class PlotToolbar(gtk.Toolbar):
|
|||
|
||||
## Maps toolbar buttons to PlotMode objects.
|
||||
self._mode_buttons = {}
|
||||
|
||||
self.set_property('show-arrow', False)
|
||||
|
||||
self.canvas.connect('enter-notify-event', self.on_enter_notify)
|
||||
self.show()
|
||||
|
||||
self.add_mode(DefaultPlotMode(self.plot))
|
||||
self.add_mode(PanPlotMode(self.plot))
|
||||
self.add_mode(ZoomPlotMode(self.plot))
|
||||
|
@ -1254,7 +1269,8 @@ class PlotToolbar(gtk.Toolbar):
|
|||
|
||||
def on_enter_notify(self, widget, event):
|
||||
self.set_mode(active_mode)
|
||||
|
||||
# need views (plots) to grab key-events
|
||||
widget.grab_focus()
|
||||
|
||||
# Create a view-changed signal that should be emitted every time
|
||||
# the active view changes.
|
||||
|
|
Reference in New Issue