object selection fix
This commit is contained in:
parent
56dac31529
commit
0eebd9436c
|
@ -68,6 +68,8 @@ class Dataset:
|
||||||
def extract_id_from_index(self,dim_name,index):
|
def extract_id_from_index(self,dim_name,index):
|
||||||
"""Returns a set of ids from array/list of indexes."""
|
"""Returns a set of ids from array/list of indexes."""
|
||||||
dim_ids = self.ids[dim_name]
|
dim_ids = self.ids[dim_name]
|
||||||
|
if type(index)==int:
|
||||||
|
index = [index]
|
||||||
return set([id for id,ind in dim_ids.items() if ind in index])
|
return set([id for id,ind in dim_ids.items() if ind in index])
|
||||||
|
|
||||||
def extract_index_from_id(self,dim_name,id):
|
def extract_index_from_id(self,dim_name,id):
|
||||||
|
|
|
@ -286,14 +286,14 @@ class ScatterPlot (Plot):
|
||||||
logger.log('debug','Selected:\n%s'%index)
|
logger.log('debug','Selected:\n%s'%index)
|
||||||
ids = self.x_dataset.extract_id_from_index('samples',index)
|
ids = self.x_dataset.extract_id_from_index('samples',index)
|
||||||
#update selection object
|
#update selection object
|
||||||
self.c_p.set_selection(self.c_p.sel_obj,self.current_dim,ids)
|
self.c_p.set_selection(self.current_dim,ids)
|
||||||
logger.log('debug','Selected identifiers:\n%s'%ids)
|
logger.log('debug','Selected identifiers:\n%s'%ids)
|
||||||
|
|
||||||
def update_selection(self,project):
|
def update_selection(self,project):
|
||||||
curr_sel = project.get_selection(self.c_p.sel_obj)
|
curr_sel = project.get_selection() # get selection object
|
||||||
ids = curr_sel[self.current_dim]
|
ids = curr_sel[self.current_dim] # current identifiers
|
||||||
index = self.x_dataset.extract_index_from_id(self.current_dim,ids)
|
index = self.x_dataset.extract_index_from_id(self.current_dim,ids) #conversion to index
|
||||||
xdata_new = scipy.take(self.xaxis_data,index)
|
xdata_new = scipy.take(self.xaxis_data,index) #take data
|
||||||
ydata_new = scipy.take(self.yaxis_data,index)
|
ydata_new = scipy.take(self.yaxis_data,index)
|
||||||
self.ax.plot(xdata_new,ydata_new,'or')
|
self.ax.plot(xdata_new,ydata_new,'or')
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
|
|
@ -6,9 +6,9 @@ class Project:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.dim_names = []
|
self.dim_names = []
|
||||||
self._selection_observers = []
|
self._selection_observers = []
|
||||||
self.current_selection = {}
|
|
||||||
self.current_data=[]
|
self.current_data=[]
|
||||||
self.datasets=[]
|
self.datasets=[]
|
||||||
|
self.sel_obj = dataset.Selection()
|
||||||
|
|
||||||
def attach(self, observer):
|
def attach(self, observer):
|
||||||
"""Attach observer for selection updates"""
|
"""Attach observer for selection updates"""
|
||||||
|
@ -28,16 +28,14 @@ class Project:
|
||||||
if modifier != observer:
|
if modifier != observer:
|
||||||
observer.update_selection(self)
|
observer.update_selection(self)
|
||||||
|
|
||||||
def set_selection(self,sel_obj,dim_name,selection):
|
def set_selection(self,dim_name,selection):
|
||||||
"""Sets selection and notifies observers"""
|
"""Sets selection and notifies observers"""
|
||||||
current_selection = set(selection)
|
self.sel_obj.current_selection[dim_name] = set(selection)
|
||||||
sel_obj.current_selection[dim_name] = current_selection
|
|
||||||
self.current_selection[dim_name] = current_selection
|
|
||||||
self.notify()
|
self.notify()
|
||||||
|
|
||||||
def get_selection(self,sel_obj):
|
def get_selection(self):
|
||||||
"""Returns the current selection object"""
|
"""Returns the current selection object"""
|
||||||
return sel_obj.current_selection
|
return self.sel_obj.current_selection
|
||||||
|
|
||||||
def add_dataset(self,dataset):
|
def add_dataset(self,dataset):
|
||||||
"""Appends a new Dataset to the project."""
|
"""Appends a new Dataset to the project."""
|
||||||
|
|
Reference in New Issue