Removed need to provide plots with project/workflow on creation, is instead injected by project itself when added to it.
This commit is contained in:
parent
b807f27874
commit
6c72dec7fa
|
@ -161,15 +161,12 @@ class LargeView (gtk.Frame):
|
|||
|
||||
class Plot (gtk.Frame):
|
||||
|
||||
def __init__(self,project):
|
||||
def __init__(self):
|
||||
gtk.Frame.__init__(self)
|
||||
self.project = project
|
||||
self.mark_active(False)
|
||||
self.connect('button_press_event', self.on_button_press)
|
||||
self.sel_obj = None
|
||||
self.active = False
|
||||
if project!=None: #its not an Emptyview
|
||||
project.attach(self,'selection_update')
|
||||
|
||||
def on_button_press(self, *rest):
|
||||
# logger.log('debug', 'button pressed in plot')
|
||||
|
@ -182,12 +179,16 @@ class Plot (gtk.Frame):
|
|||
self.set_shadow_type(gtk.SHADOW_OUT)
|
||||
self.active = active
|
||||
|
||||
def update(self,project,key):
|
||||
def update(self, key):
|
||||
pass
|
||||
|
||||
def set_project(self, project):
|
||||
self.project = project
|
||||
|
||||
|
||||
class EmptyView (Plot):
|
||||
def __init__(self):
|
||||
Plot.__init__(self,None)
|
||||
Plot.__init__(self)
|
||||
|
||||
label = gtk.Label('No view')
|
||||
ebox = gtk.EventBox()
|
||||
|
@ -211,8 +212,8 @@ class EmptyView (Plot):
|
|||
|
||||
|
||||
class SinePlot(Plot):
|
||||
def __init__(self,project):
|
||||
Plot.__init__(self,project)
|
||||
def __init__(self):
|
||||
Plot.__init__(self)
|
||||
fig = Figure(figsize=(5,4), dpi=72)
|
||||
ax = fig.add_subplot(111)
|
||||
t = arange(0.0,3.0,0.01)
|
||||
|
@ -224,9 +225,8 @@ class SinePlot(Plot):
|
|||
|
||||
|
||||
class ScatterPlot(Plot):
|
||||
def __init__(self,project,dataset,id_dim,sel_dim,id_1,id_2):
|
||||
Plot.__init__(self,project)
|
||||
self.project = project
|
||||
def __init__(self, dataset, id_dim, sel_dim, id_1, id_2):
|
||||
Plot.__init__(self)
|
||||
fig = Figure(figsize=(5,4), dpi=72)
|
||||
self.ax = ax = fig.add_subplot(111)
|
||||
self.current_dim = id_dim
|
||||
|
@ -272,8 +272,8 @@ class ScatterPlot(Plot):
|
|||
ids = [id for id,ind in self.dataset[self.current_dim].items() if ind in index]
|
||||
self.project.set_selection(self.current_dim,ids)
|
||||
|
||||
def update(self,project,key):
|
||||
curr_sel = project.get_selection() # get selection object
|
||||
def update(self, key):
|
||||
curr_sel = self.project.get_selection() # get selection object
|
||||
ids = curr_sel[self.current_dim] # current identifiers
|
||||
|
||||
index = [ind for id,ind in self.dataset[self.current_dim].items() if id in ids] #conversion to index
|
||||
|
@ -283,5 +283,3 @@ class ScatterPlot(Plot):
|
|||
self.ax.plot(self.xaxis_data,self.yaxis_data,'og')
|
||||
self.ax.plot(xdata_new,ydata_new,'or')
|
||||
self.canvas.draw()
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class Project:
|
|||
"""Notifies observers"""
|
||||
for observer in self._observers[key]:
|
||||
if modifier != observer:
|
||||
observer.update(self,key)
|
||||
observer.update(key)
|
||||
|
||||
def set_selection(self,dim_name,selection):
|
||||
"""Sets a current selection and notify observers"""
|
||||
|
@ -58,6 +58,8 @@ class Project:
|
|||
elif isinstance(d, plots.Plot):
|
||||
# self.add_view(d)
|
||||
self.data_tree_insert(None, 'view', d)
|
||||
d.set_project(self)
|
||||
self.attach(d, 'selection_update')
|
||||
|
||||
def data_tree_insert(self, parent, text, data):
|
||||
tree = self.data_tree
|
||||
|
|
|
@ -107,7 +107,7 @@ class TestDataFunction(Function):
|
|||
logger.log('notice', 'Injecting foo test data')
|
||||
x = randn(20,30)
|
||||
X = dataset.Dataset(x)
|
||||
return [X, plots.SinePlot(None)]
|
||||
return [X, plots.SinePlot()]
|
||||
|
||||
|
||||
class DatasetLoadFunction(Function):
|
||||
|
@ -239,8 +239,8 @@ class PCAFunction(Function):
|
|||
# cleanup
|
||||
rpy.r.rm(["t", "m"])
|
||||
|
||||
loading_plot1 = plots.ScatterPlot(self._workflow.project,P,'ids','component','1','2')
|
||||
loading_plot2 = plots.ScatterPlot(self._workflow.project,P,'ids','component','3','4')
|
||||
score_plot = plots.ScatterPlot(self._workflow.project,T,'filename','component','1','2')
|
||||
loading_plot1 = plots.ScatterPlot(P,'ids','component','1','2')
|
||||
loading_plot2 = plots.ScatterPlot(P,'ids','component','3','4')
|
||||
score_plot = plots.ScatterPlot(T,'filename','component','1','2')
|
||||
|
||||
return [T, P, loading_plot1, loading_plot2, score_plot]
|
||||
|
|
|
@ -102,9 +102,9 @@ class PCAFunction(Function):
|
|||
#tsq = dataset.Dataset(tsq,[singel_def,data_ids[1])
|
||||
|
||||
## plots
|
||||
loading_plot1 = plots.ScatterPlot(self.workflow.project,P,'genes','comp','1','2')
|
||||
loading_plot2 = plots.ScatterPlot(self.workflow.project,P,'genes','comp','3','4')
|
||||
score_plot = plots.ScatterPlot(self.workflow.project,T,'samples','comp','1','2')
|
||||
loading_plot1 = plots.ScatterPlot(P,'genes','comp','1','2')
|
||||
loading_plot2 = plots.ScatterPlot(P,'genes','comp','3','4')
|
||||
score_plot = plots.ScatterPlot(T,'samples','comp','1','2')
|
||||
|
||||
return [T,P,E,loading_plot1,loading_plot2,score_plot]
|
||||
|
||||
|
|
Reference in New Issue