Repository: biolab/orange3

Issue:
Hierarchical Clustering: output Data when setting clusters with cutoff
<!--
This is an issue template. Please fill in the relevant details in the
sections below.

Wrap code and verbatim terminal window output into triple backticks, see:
https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code

If you're raising an issue about an add-on (e.g. installed via
Options > Add-ons), raise an issue on the relevant add-on's issue
tracker instead. See: https://github.com/biolab?q=orange3
-->

##### Orange version
<!-- From menu _Help→About→Version_ or code `Orange.version.full_version` -->
3.18.dev

##### Expected behavior
HC outputs Data when selecting all the clusters.


##### Actual behavior
HC outputs this as Selected Data.


##### Steps to reproduce the behavior



##### Additional info (worksheets, data, screenshots, ...)





Discussion:
@janezd I hope I got this right. Please check.
It should output both. The same data for both, I suppose.

Resolving patch:
diff --git a/Orange/widgets/unsupervised/owhierarchicalclustering.py b/Orange/widgets/unsupervised/owhierarchicalclustering.py
--- a/Orange/widgets/unsupervised/owhierarchicalclustering.py
+++ b/Orange/widgets/unsupervised/owhierarchicalclustering.py
@@ -1256,8 +1256,7 @@ def remove_other_value(vars_):
             data = None
 
         self.Outputs.selected_data.send(selected_data)
-        annotated_data = create_annotated_table(data, selected_indices) if \
-            self.selection_method == 0 else None
+        annotated_data = create_annotated_table(data, selected_indices)
         self.Outputs.annotated_data.send(annotated_data)
 
     def sizeHint(self):


Test patch:
diff --git a/Orange/widgets/unsupervised/tests/test_owhierarchicalclustering.py b/Orange/widgets/unsupervised/tests/test_owhierarchicalclustering.py
--- a/Orange/widgets/unsupervised/tests/test_owhierarchicalclustering.py
+++ b/Orange/widgets/unsupervised/tests/test_owhierarchicalclustering.py
@@ -1,6 +1,10 @@
 # Test methods with long descriptive names can omit docstrings
 # pylint: disable=missing-docstring
 import numpy as np
+
+from AnyQt.QtCore import QPoint, Qt, QEvent
+from AnyQt.QtGui import QMouseEvent
+
 import Orange.misc
 from Orange.data import Table, Domain, ContinuousVariable, DiscreteVariable
 from Orange.distance import Euclidean
@@ -46,12 +50,12 @@ def test_selection_box_output(self):
         # change selection to 'Height ratio'
         self.widget.selection_box.buttons[1].click()
         self.assertIsNotNone(self.get_output(self.widget.Outputs.selected_data))
-        self.assertIsNone(self.get_output(self.widget.Outputs.annotated_data))
+        self.assertIsNotNone(self.get_output(self.widget.Outputs.annotated_data))
 
         # change selection to 'Top N'
         self.widget.selection_box.buttons[2].click()
         self.assertIsNotNone(self.get_output(self.widget.Outputs.selected_data))
-        self.assertIsNone(self.get_output(self.widget.Outputs.annotated_data))
+        self.assertIsNotNone(self.get_output(self.widget.Outputs.annotated_data))
 
     def test_all_zero_inputs(self):
         d = Orange.misc.DistMatrix(np.zeros((10, 10)))
@@ -123,3 +127,23 @@ def test_infinite_distances(self):
         self.assertTrue(self.widget.Error.not_finite_distances.is_shown())
         self.send_signal(self.widget.Inputs.distances, self.distances)
         self.assertFalse(self.widget.Error.not_finite_distances.is_shown())
+
+    def test_output_cut_ratio(self):
+        self.send_signal(self.widget.Inputs.distances, self.distances)
+
+        # no data is selected
+        self.assertIsNone(self.get_output(self.widget.Outputs.selected_data))
+        annotated = self.get_output(self.widget.Outputs.annotated_data)
+        self.assertIsNotNone(annotated)
+
+        # selecting clusters with cutoff should select all data
+        self.widget.eventFilter(self.widget.top_axis_view.viewport(),
+                                self._mouse_button_press_event())
+        selected = self.get_output(self.widget.Outputs.selected_data)
+        annotated = self.get_output(self.widget.Outputs.annotated_data)
+        self.assertEqual(len(selected), len(self.data))
+        self.assertIsNotNone(annotated)
+
+    def _mouse_button_press_event(self):
+        return QMouseEvent(QEvent.MouseButtonPress, QPoint(100, 10),
+                           Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)