removed SinePlot and and added general selection sensitive function thingy
This commit is contained in:
parent
b000792faa
commit
fc2891bad8
|
@ -253,7 +253,9 @@ class Plot (gtk.Frame):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def selection_changed(self, selection):
|
||||||
pass
|
if not self._sel_sensitive or not self.get_property('visible'):
|
||||||
|
return
|
||||||
|
self.set_current_selection(selection)
|
||||||
|
|
||||||
def set_selection_listener(self, listener):
|
def set_selection_listener(self, listener):
|
||||||
"""Allow project to listen to selections.
|
"""Allow project to listen to selections.
|
||||||
|
@ -267,6 +269,7 @@ class Plot (gtk.Frame):
|
||||||
def get_toolbar(self):
|
def get_toolbar(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class EmptyView (Plot):
|
class EmptyView (Plot):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Plot.__init__(self, 'Empty view')
|
Plot.__init__(self, 'Empty view')
|
||||||
|
@ -391,25 +394,6 @@ class PlotToolbar(NavToolbar):
|
||||||
self.insert(toolitem, -1)
|
self.insert(toolitem, -1)
|
||||||
self.show_all()
|
self.show_all()
|
||||||
self.message.hide()
|
self.message.hide()
|
||||||
|
|
||||||
class SinePlot(Plot):
|
|
||||||
def __init__(self):
|
|
||||||
Plot.__init__(self, 'Sine plot')
|
|
||||||
|
|
||||||
fig = Figure(figsize=(5,4), dpi=72)
|
|
||||||
ax = fig.add_subplot(111)
|
|
||||||
t = arange(0.0,3.0,0.01)
|
|
||||||
s = sin(2*pi*t)
|
|
||||||
ax.plot(t,s)
|
|
||||||
|
|
||||||
self.canvas = FigureCanvas(fig)
|
|
||||||
self._toolbar = NavToolbar(self.canvas, None)
|
|
||||||
self._toolbar.set_property('show-arrow', False)
|
|
||||||
self.add(self.canvas)
|
|
||||||
self.canvas.show()
|
|
||||||
|
|
||||||
def get_toolbar(self):
|
|
||||||
return self._toolbar
|
|
||||||
|
|
||||||
|
|
||||||
class LineViewPlot(Plot):
|
class LineViewPlot(Plot):
|
||||||
|
@ -461,9 +445,7 @@ class LineViewPlot(Plot):
|
||||||
def clear_background(self,event):
|
def clear_background(self,event):
|
||||||
self._background = None
|
self._background = None
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def set_current_selection(self, selection):
|
||||||
if not self._sel_sensitive:
|
|
||||||
return
|
|
||||||
ids = selection[self.current_dim] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
index = self.dataset.get_indices(self.current_dim, ids)
|
index = self.dataset.get_indices(self.current_dim, ids)
|
||||||
if self.use_blit:
|
if self.use_blit:
|
||||||
|
@ -548,9 +530,7 @@ has no color and size options."""
|
||||||
ids = self.dataset_1.get_identifiers(self.current_dim, index)
|
ids = self.dataset_1.get_identifiers(self.current_dim, index)
|
||||||
self.selection_listener(self.current_dim, ids)
|
self.selection_listener(self.current_dim, ids)
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def set_current_selection(self, selection):
|
||||||
if not self._sel_sensitive:
|
|
||||||
return
|
|
||||||
ids = selection[self.current_dim] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||||
xdata_new = scipy.take(self.xaxis_data, index) #take data
|
xdata_new = scipy.take(self.xaxis_data, index) #take data
|
||||||
|
@ -568,27 +548,23 @@ has no color and size options."""
|
||||||
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2,c='b',s=30, name="Scatter plot"):
|
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2,c='b',s=30, name="Scatter plot"):
|
||||||
Plot.__init__(self, name)
|
Plot.__init__(self, name)
|
||||||
self.ax = ax = self.fig.add_subplot(111)
|
self.ax = ax = self.fig.add_subplot(111)
|
||||||
#self.ax.set_position([0.01,0.01,.99,.99])
|
|
||||||
self.current_dim = id_dim
|
self.current_dim = id_dim
|
||||||
self.dataset_1 = dataset_1
|
self.dataset_1 = dataset_1
|
||||||
|
|
||||||
x_index = dataset_1[sel_dim][id_1]
|
x_index = dataset_1[sel_dim][id_1]
|
||||||
y_index = dataset_2[sel_dim][id_2]
|
y_index = dataset_2[sel_dim][id_2]
|
||||||
|
|
||||||
self.xaxis_data = dataset_1._array[:,x_index]
|
self.xaxis_data = dataset_1._array[:,x_index]
|
||||||
self.yaxis_data = dataset_2._array[:,y_index]
|
self.yaxis_data = dataset_2._array[:,y_index]
|
||||||
|
lw = scipy.zeros(self.xaxis_data.shape,'f')
|
||||||
ax.scatter(self.xaxis_data,self.yaxis_data,s=s,c=c,faceted=False,edgecolor='k',alpha=.6,cmap = cm.Set1)
|
ax.scatter(self.xaxis_data,self.yaxis_data,s=s,c=c,linewidth=lw,edgecolor='k',alpha=.6,cmap = cm.Set1)
|
||||||
ax.set_title(self.get_title())
|
ax.set_title(self.get_title())
|
||||||
#ax.set_xlabel("%s - %s" % (sel_dim, id_1))
|
|
||||||
#ax.set_ylabel("%s - %s" % (sel_dim, id_2))
|
|
||||||
|
|
||||||
# collection
|
# collection
|
||||||
self.coll = ax.collections[0]
|
self.coll = ax.collections[0]
|
||||||
###
|
|
||||||
|
# add canvas to widget
|
||||||
self.add(self.canvas)
|
self.add(self.canvas)
|
||||||
self.canvas.show()
|
self.canvas.show()
|
||||||
|
|
||||||
|
# create toolbar
|
||||||
self._toolbar = PlotToolbar(self.canvas, None)
|
self._toolbar = PlotToolbar(self.canvas, None)
|
||||||
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
|
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
|
||||||
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
||||||
|
@ -613,14 +589,12 @@ has no color and size options."""
|
||||||
ids = self.dataset_1.get_identifiers(self.current_dim, index)
|
ids = self.dataset_1.get_identifiers(self.current_dim, index)
|
||||||
self.selection_listener(self.current_dim, ids)
|
self.selection_listener(self.current_dim, ids)
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def set_current_selection(self, selection):
|
||||||
if not self._sel_sensitive:
|
|
||||||
return
|
|
||||||
ids = selection[self.current_dim] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||||
lw = scipy.zeros(self.xaxis_data.shape,'f')
|
lw = scipy.zeros(self.xaxis_data.shape,'f')
|
||||||
zo = lw.copy() + 1 #z-order
|
|
||||||
scipy.put(lw,index,2.)
|
scipy.put(lw,index,2.)
|
||||||
|
zo = lw.copy() + 1 #z-order, selected on top
|
||||||
self.coll.set_linewidth(lw)
|
self.coll.set_linewidth(lw)
|
||||||
self.coll.set_zorder(zo)
|
self.coll.set_zorder(zo)
|
||||||
self._toolbar.forward() #update data lims before draw
|
self._toolbar.forward() #update data lims before draw
|
||||||
|
@ -711,7 +685,7 @@ 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.dataset.get_dim_name(0), ids)
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def set_current_selection(self, selection):
|
||||||
ids = selection[self.dataset.get_dim_name(0)] # current identifiers
|
ids = selection[self.dataset.get_dim_name(0)] # current identifiers
|
||||||
node_set = set(self.graph.nodes())
|
node_set = set(self.graph.nodes())
|
||||||
|
|
||||||
|
|
Reference in New Issue