This commit is contained in:
parent
958c6dbfdf
commit
502cd22dc8
|
@ -263,6 +263,7 @@ class GraphDataset(Dataset):
|
||||||
Dataset.__init__(self,array=array,identifiers=identifiers,name='A')
|
Dataset.__init__(self,array=array,identifiers=identifiers,name='A')
|
||||||
self._graph = None
|
self._graph = None
|
||||||
self._type = 'g'
|
self._type = 'g'
|
||||||
|
self._pos = None
|
||||||
|
|
||||||
def asnetworkx(self,nx_type='graph'):
|
def asnetworkx(self,nx_type='graph'):
|
||||||
dim = self.get_dim_name()[0]
|
dim = self.get_dim_name()[0]
|
||||||
|
|
|
@ -249,7 +249,6 @@ class Plot (gtk.Frame):
|
||||||
def __init__(self, title):
|
def __init__(self, title):
|
||||||
gtk.Frame.__init__(self)
|
gtk.Frame.__init__(self)
|
||||||
self.title = title
|
self.title = title
|
||||||
self.sel_obj = None
|
|
||||||
self.selection_listener = None
|
self.selection_listener = None
|
||||||
self.fig = Figure()
|
self.fig = Figure()
|
||||||
self.canvas = FigureCanvas(self.fig)
|
self.canvas = FigureCanvas(self.fig)
|
||||||
|
@ -257,6 +256,7 @@ class Plot (gtk.Frame):
|
||||||
self._background = None
|
self._background = None
|
||||||
self._sel_sensitive = True
|
self._sel_sensitive = True
|
||||||
self.canvas.add_events(gtk.gdk.ENTER_NOTIFY_MASK)
|
self.canvas.add_events(gtk.gdk.ENTER_NOTIFY_MASK)
|
||||||
|
self.current_dim = None
|
||||||
|
|
||||||
def set_selection_sensitive(self,event):
|
def set_selection_sensitive(self,event):
|
||||||
if event:
|
if event:
|
||||||
|
@ -271,9 +271,19 @@ class Plot (gtk.Frame):
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def selection_changed(self, dim_name, selection):
|
||||||
if not self._sel_sensitive or not self.get_property('visible'):
|
""" Selection observer handle.
|
||||||
|
|
||||||
|
A selection change in a plot is only drawn if:
|
||||||
|
1.) plot is sensitive to selections (not freezed)
|
||||||
|
2.) plot is visible (has a view)
|
||||||
|
3.) the selections dim_name is the plot's dimension.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not self._sel_sensitive or not self.get_property('visible') or self.current_dim!=dim_name:
|
||||||
|
print "Ignored a selection changed call in plot: %s" %self.get_title()
|
||||||
return
|
return
|
||||||
|
print "Setting current selection in: %s " %self.get_title()
|
||||||
self.set_current_selection(selection)
|
self.set_current_selection(selection)
|
||||||
|
|
||||||
def set_selection_listener(self, listener):
|
def set_selection_listener(self, listener):
|
||||||
|
@ -436,6 +446,7 @@ has no color and size options."""
|
||||||
return self._toolbar
|
return self._toolbar
|
||||||
|
|
||||||
def rectangle_select_callback(self, x1, y1, x2, y2):
|
def rectangle_select_callback(self, x1, y1, x2, y2):
|
||||||
|
print "Rectangle select happened in: %s" %self.get_title()
|
||||||
ydata = self.yaxis_data
|
ydata = self.yaxis_data
|
||||||
xdata = self.xaxis_data
|
xdata = self.xaxis_data
|
||||||
|
|
||||||
|
@ -472,6 +483,7 @@ has no color and size options."""
|
||||||
self.ax.draw_artist(self._selection_line)
|
self.ax.draw_artist(self._selection_line)
|
||||||
self.canvas.blit()
|
self.canvas.blit()
|
||||||
else:
|
else:
|
||||||
|
print "A draw happened in: %s" %self.get_title()
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
|
||||||
|
|
||||||
|
@ -507,13 +519,13 @@ class ScatterPlot(Plot):
|
||||||
# create toolbar
|
# create toolbar
|
||||||
self._toolbar = PlotToolbar(self.canvas, self)
|
self._toolbar = PlotToolbar(self.canvas, self)
|
||||||
self._toolbar.chk.connect ('toggled' , self.set_selection_sensitive)
|
self._toolbar.chk.connect ('toggled' , self.set_selection_sensitive)
|
||||||
self._toolbar.set_property('show-arrow', False)
|
|
||||||
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
||||||
|
|
||||||
def get_toolbar(self):
|
def get_toolbar(self):
|
||||||
return self._toolbar
|
return self._toolbar
|
||||||
|
|
||||||
def rectangle_select_callback(self, x1, y1, x2, y2):
|
def rectangle_select_callback(self, x1, y1, x2, y2):
|
||||||
|
print "Rectangle select happened in: %s" %self.get_title()
|
||||||
ydata = self.yaxis_data
|
ydata = self.yaxis_data
|
||||||
xdata = self.xaxis_data
|
xdata = self.xaxis_data
|
||||||
|
|
||||||
|
@ -532,7 +544,9 @@ class ScatterPlot(Plot):
|
||||||
def set_current_selection(self, selection):
|
def set_current_selection(self, selection):
|
||||||
ids = selection[self.current_dim] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
if len(ids)==0:
|
if len(ids)==0:
|
||||||
|
print "nothing selected"
|
||||||
return
|
return
|
||||||
|
self._toolbar.forward() #update data lims before draw
|
||||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||||
if self.use_blit:
|
if self.use_blit:
|
||||||
if self._background is None:
|
if self._background is None:
|
||||||
|
@ -542,12 +556,13 @@ class ScatterPlot(Plot):
|
||||||
if len(index)>0:
|
if len(index)>0:
|
||||||
lw.put(2.,index)
|
lw.put(2.,index)
|
||||||
self.coll.set_linewidth(lw)
|
self.coll.set_linewidth(lw)
|
||||||
self._toolbar.forward() #update data lims before draw
|
|
||||||
|
|
||||||
if self.use_blit:
|
if self.use_blit:
|
||||||
|
print "A blit happened in : %s " %self.get_title()
|
||||||
self.canvas.blit()
|
self.canvas.blit()
|
||||||
self.ax.draw_artist(self.coll)
|
self.ax.draw_artist(self.coll)
|
||||||
else:
|
else:
|
||||||
|
print "A draw happened in : %s " %self.get_title()
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
|
||||||
|
|
||||||
|
@ -558,6 +573,7 @@ class NetworkPlot(Plot):
|
||||||
self.dataset = dataset
|
self.dataset = dataset
|
||||||
self.keywords = kw
|
self.keywords = kw
|
||||||
self.dim_name = self.dataset.get_dim_name(0)
|
self.dim_name = self.dataset.get_dim_name(0)
|
||||||
|
self.current_dim = self.dim_name
|
||||||
if not kw.has_key('name'):
|
if not kw.has_key('name'):
|
||||||
kw['name'] = self.dataset.get_name()
|
kw['name'] = self.dataset.get_name()
|
||||||
if not kw.has_key('prog'):
|
if not kw.has_key('prog'):
|
||||||
|
@ -607,14 +623,12 @@ class NetworkPlot(Plot):
|
||||||
# Setup toolbar
|
# Setup toolbar
|
||||||
self._toolbar = PlotToolbar(self.canvas, self)
|
self._toolbar = PlotToolbar(self.canvas, self)
|
||||||
self._toolbar.chk.connect ('toggled' , self.set_selection_sensitive)
|
self._toolbar.chk.connect ('toggled' , self.set_selection_sensitive)
|
||||||
self._toolbar.set_property('show-arrow', False)
|
|
||||||
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
||||||
|
|
||||||
def get_toolbar(self):
|
def get_toolbar(self):
|
||||||
return self._toolbar
|
return self._toolbar
|
||||||
|
|
||||||
def rectangle_select_callback(self, x1, y1, x2, y2):
|
def rectangle_select_callback(self, x1, y1, x2, y2):
|
||||||
'event1 and event2 are the press and release events'
|
|
||||||
pos = self.keywords['pos']
|
pos = self.keywords['pos']
|
||||||
ydata = scipy.zeros((len(pos),), 'l')
|
ydata = scipy.zeros((len(pos),), 'l')
|
||||||
xdata = scipy.zeros((len(pos),), 'l')
|
xdata = scipy.zeros((len(pos),), 'l')
|
||||||
|
@ -635,10 +649,10 @@ class NetworkPlot(Plot):
|
||||||
|
|
||||||
|
|
||||||
ids = [node_ids[i] for i in index]
|
ids = [node_ids[i] for i in index]
|
||||||
self.selection_listener(self.dataset.get_dim_name(0), ids)
|
self.selection_listener(self.current_dim, ids)
|
||||||
|
|
||||||
def set_current_selection(self, selection):
|
def set_current_selection(self, selection):
|
||||||
ids = selection[self.dataset.get_dim_name(0)] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
node_set = set(self.graph.nodes())
|
node_set = set(self.graph.nodes())
|
||||||
|
|
||||||
selected_nodes = list(ids.intersection(node_set))
|
selected_nodes = list(ids.intersection(node_set))
|
||||||
|
@ -688,6 +702,7 @@ class PlotToolbar(NavigationToolbar2,gtk.Toolbar):
|
||||||
|
|
||||||
def __init__(self, canvas, plot):
|
def __init__(self, canvas, plot):
|
||||||
self.win = None
|
self.win = None
|
||||||
|
self.plot = plot
|
||||||
gtk.Toolbar.__init__(self)
|
gtk.Toolbar.__init__(self)
|
||||||
NavigationToolbar2.__init__(self, canvas)
|
NavigationToolbar2.__init__(self, canvas)
|
||||||
self._idleId = 0
|
self._idleId = 0
|
||||||
|
@ -758,16 +773,29 @@ class PlotToolbar(NavigationToolbar2,gtk.Toolbar):
|
||||||
def on_enter_notify(self, widget, event):
|
def on_enter_notify(self, widget, event):
|
||||||
if self._active != active_mode:
|
if self._active != active_mode:
|
||||||
self.set_mode(active_mode)
|
self.set_mode(active_mode)
|
||||||
|
self.set_mode(active_mode)
|
||||||
|
|
||||||
def set_mode(self, active):
|
def set_mode(self, active):
|
||||||
|
print "Set mode called in toolbar from: %s" %self.plot.get_title()
|
||||||
# if state is unkown or not set, set to default
|
# if state is unkown or not set, set to default
|
||||||
if active == None or active not in self._states.keys():
|
if active == None or active not in self._states.keys():
|
||||||
active = 'DEFAULT'
|
active = 'DEFAULT'
|
||||||
|
|
||||||
# remove current Selector:
|
# remove current Selector:
|
||||||
if self._selector:
|
if self._selector != None:
|
||||||
print "Removing selector"
|
# problem is ... i have mutliple selectors still connected
|
||||||
|
# trying to remove old selectors connections
|
||||||
|
#
|
||||||
|
# blah
|
||||||
|
# Her Einar ...
|
||||||
|
#
|
||||||
|
self.canvas.mpl_disconnect(self._selector.onmove)
|
||||||
|
self.canvas.mpl_disconnect(self._selector.press)
|
||||||
|
self.canvas.mpl_disconnect(self._selector.release)
|
||||||
|
self.canvas.mpl_disconnect(self._selector.update_background)
|
||||||
|
print "Removing selector in: %s" %self.plot.get_title()
|
||||||
self._selector = None
|
self._selector = None
|
||||||
|
|
||||||
# remove current button bindings
|
# remove current button bindings
|
||||||
if self._idPress != None:
|
if self._idPress != None:
|
||||||
self._idPress = self.canvas.mpl_disconnect(self._idPress)
|
self._idPress = self.canvas.mpl_disconnect(self._idPress)
|
||||||
|
@ -782,14 +810,14 @@ class PlotToolbar(NavigationToolbar2,gtk.Toolbar):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if state == 'SELECT':
|
if state == 'SELECT':
|
||||||
ax, = self.canvas.figure.get_axes()
|
for ax in self.canvas.figure.get_axes():
|
||||||
props = dict(facecolor='blue', edgecolor = 'black',
|
props = dict(facecolor='blue', edgecolor = 'black',
|
||||||
alpha=0.3, fill=True)
|
alpha=0.3, fill=True)
|
||||||
self._selector = RectangleSelector(ax, self.onselect,
|
print "creating a selector"
|
||||||
drawtype='box', useblit=True,
|
self._selector = RectangleSelector(ax, self.on_select,
|
||||||
rectprops=props)
|
drawtype='box', useblit=True,
|
||||||
self.mode = 'Select rectangle mode'
|
rectprops=props)
|
||||||
print self.mode
|
self.mode = 'Select rectangle mode'
|
||||||
|
|
||||||
elif state == 'PAN':
|
elif state == 'PAN':
|
||||||
self._idPress = self.canvas.mpl_connect(
|
self._idPress = self.canvas.mpl_connect(
|
||||||
|
@ -837,10 +865,11 @@ class PlotToolbar(NavigationToolbar2,gtk.Toolbar):
|
||||||
return
|
return
|
||||||
self.set_mode('SELECT')
|
self.set_mode('SELECT')
|
||||||
|
|
||||||
def onselect(self,eclick, erelease):
|
def on_select(self,eclick, erelease):
|
||||||
'eclick and erelease are matplotlib events at press and release'
|
'eclick and erelease are matplotlib events at press and release'
|
||||||
if self._select_callback:
|
if self._select_callback:
|
||||||
self._select_callback(eclick.xdata, eclick.ydata, erelease.xdata, erelease.ydata)
|
print "Onselect called"
|
||||||
|
self._select_callback(eclick.xdata, eclick.ydata, erelease.xdata, erelease.ydata)
|
||||||
|
|
||||||
def pan(self, button):
|
def pan(self, button):
|
||||||
"""Activate the pan/zoom tool. pan with left button, zoom with right"""
|
"""Activate the pan/zoom tool. pan with left button, zoom with right"""
|
||||||
|
@ -886,9 +915,6 @@ class PlotToolbar(NavigationToolbar2,gtk.Toolbar):
|
||||||
# legacy method; new method is canvas.draw_idle
|
# legacy method; new method is canvas.draw_idle
|
||||||
self.canvas.draw_idle()
|
self.canvas.draw_idle()
|
||||||
|
|
||||||
def mpl_draw_rubberband(self,event):
|
|
||||||
"""Use RectangleSelector for rubberband drawing"""
|
|
||||||
|
|
||||||
def draw_rubberband(self, event, x0, y0, x1, y1):
|
def draw_rubberband(self, event, x0, y0, x1, y1):
|
||||||
'adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744'
|
'adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744'
|
||||||
drawable = self.canvas.window
|
drawable = self.canvas.window
|
||||||
|
|
|
@ -25,12 +25,12 @@ class Project:
|
||||||
|
|
||||||
def add_selection_observer(self, observer):
|
def add_selection_observer(self, observer):
|
||||||
self._selection_observers.append(observer)
|
self._selection_observers.append(observer)
|
||||||
observer.selection_changed(self.get_selection())
|
#observer.selection_changed(self.get_selection())
|
||||||
|
|
||||||
def notify_selection_listeners(self, dim_name):
|
def notify_selection_listeners(self, dim_name):
|
||||||
"""Notifies observers"""
|
"""Notifies observers"""
|
||||||
for observer in self._selection_observers:
|
for observer in self._selection_observers:
|
||||||
observer.selection_changed(self.get_selection())
|
observer.selection_changed(dim_name, self.get_selection())
|
||||||
|
|
||||||
def add_dataset_observer(self, observer):
|
def add_dataset_observer(self, observer):
|
||||||
self._dataset_observers.append(observer)
|
self._dataset_observers.append(observer)
|
||||||
|
|
|
@ -139,7 +139,7 @@ class DimListController:
|
||||||
values = (selection.title, selection, dataset.get_dim_name(0))
|
values = (selection.title, selection, dataset.get_dim_name(0))
|
||||||
self.selstore.insert_after(i, None, values)
|
self.selstore.insert_after(i, None, values)
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def selection_changed(self, dim_name, selection):
|
||||||
"""Callback function from Project."""
|
"""Callback function from Project."""
|
||||||
|
|
||||||
for dim in selection.dims():
|
for dim in selection.dims():
|
||||||
|
|
|
@ -103,7 +103,7 @@ class TestDataFunction(workflow.Function):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logger.log('notice', 'Injecting foo test data')
|
logger.log('notice', 'Injecting foo test data')
|
||||||
x = randn(5000,4)
|
x = randn(500,4)
|
||||||
X = dataset.Dataset(x)
|
X = dataset.Dataset(x)
|
||||||
p = plots.ScatterPlot(X, X, 'rows', 'rows', '0_1', '0_2',name='scatter')
|
p = plots.ScatterPlot(X, X, 'rows', 'rows', '0_1', '0_2',name='scatter')
|
||||||
p2 = plots.ScatterMarkerPlot(X, X, 'rows', 'rows', '0_1', '0_2',name='marker')
|
p2 = plots.ScatterMarkerPlot(X, X, 'rows', 'rows', '0_1', '0_2',name='marker')
|
||||||
|
|
Reference in New Issue