Skip to content

Commit

Permalink
owhierarchicalclustering: save selected branches
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcv authored and ales-erjavec committed Nov 23, 2018
1 parent 3b31631 commit e4cbbe7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Orange/widgets/unsupervised/owhierarchicalclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ class Outputs:
cut_ratio = settings.Setting(75.0)
#: Number of top clusters to select
top_n = settings.Setting(3)
#: Selected trees
selected_trees = settings.ContextSetting([])

#: Dendrogram zoom factor
zoom_factor = settings.Setting(0)
Expand Down Expand Up @@ -817,6 +819,7 @@ def __init__(self):
self.root = None
self._displayed_root = None
self.cutoff_height = 0.0
self._open_context = False

gui.comboBox(
self.controlArea, self, "linkage", items=LINKAGE, box="Linkage",
Expand Down Expand Up @@ -1060,6 +1063,7 @@ def _set_items(self, items, axis=1):
else:
self.annotation = "Enumeration"
self.openContext(items.domain)
self._open_context = True
self.label_cb.setCurrentIndex(model.indexOf(self.annotation))
else:
name_option = bool(
Expand Down Expand Up @@ -1142,9 +1146,20 @@ def _update_labels(self):
self.labels.set_labels(labels)
self.labels.setMinimumWidth(1 if labels else -1)

def _restore_selection(self):
if self.selection_method == 0 and self.matrix is not None \
and isinstance(self.matrix.row_items, Orange.data.Table):
if not self._open_context:
self.openContext(self.matrix.row_items.domain)
select_items = [self.dendrogram.item(t)
for t in self.dendrogram._items
if hash(t) in self.selected_trees]
self.dendrogram.set_selected_items(select_items)

def _invalidate_clustering(self):
self._update()
self._update_labels()
self._restore_selection()
self._invalidate_output()

def _invalidate_output(self):
Expand Down Expand Up @@ -1174,6 +1189,7 @@ def commit(self):
return

selection = self.dendrogram.selected_nodes()
self.selected_trees = list(map(hash, selection))
selection = sorted(selection, key=lambda c: c.value.first)

indices = [leaf.value.index for leaf in leaves(self.root)]
Expand Down

0 comments on commit e4cbbe7

Please sign in to comment.