Skip to content

Commit

Permalink
Scatter Plot - Handle input features that are hidden in data
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Aug 15, 2023
1 parent 9eb6490 commit 84eafd2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Orange/widgets/visualize/owscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ def _point_tooltip(self, point_id, skip_attrs=()):
def can_draw_regresssion_line(self):
return self.data is not None and \
self.data.domain is not None and \
self.attr_x is not None and self.attr_y is not None and \
self.attr_x.is_continuous and \
self.attr_y.is_continuous

Expand Down Expand Up @@ -571,12 +572,13 @@ def handleNewSignals(self):
self.attr_box.setEnabled(True)
self.vizrank.setEnabled(True)
if self.attribute_selection_list and self.data is not None and \
self.data.domain is not None and \
all(attr in self.data.domain for attr
in self.attribute_selection_list):
self.attr_x, self.attr_y = self.attribute_selection_list[:2]
self.data.domain is not None:
self.attr_box.setEnabled(False)
self.vizrank.setEnabled(False)
if all(attr in self.xy_model for attr in self.attribute_selection_list):
self.attr_x, self.attr_y = self.attribute_selection_list
else:
self.attr_x, self.attr_y = None, None
self._invalidated = self._invalidated or self._xy_invalidated
self._xy_invalidated = False
super().handleNewSignals()
Expand All @@ -593,6 +595,10 @@ def set_shown_attributes(self, attributes):
or self.attr_x != attributes[0] \
or self.attr_y != attributes[1]
else:
if self.attr_x is None or self.attr_y is None:
# scenario happens when features input removed and features
# were invalid or hidden and those attr_x and attr_h were None
self.init_attr_values()
self.attribute_selection_list = None

def set_attr(self, attr_x, attr_y):
Expand Down
32 changes: 32 additions & 0 deletions Orange/widgets/visualize/tests/test_owscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,38 @@ def test_features_and_data(self):
self.assertTrue(self.widget.attr_box.isEnabled())
self.assertTrue(self.widget.vizrank.isEnabled())

def test_features_and_hidden_data(self):
new_domain = self.data.domain.copy()
new_domain.attributes[0].attributes["hidden"] = True
data = self.data.transform(new_domain)

self.send_signal(self.widget.Inputs.data, data)
self.send_signal(self.widget.Inputs.features, AttributeList(data.domain[:2]))
self.assertIsNone(self.widget.attr_x)
self.assertIsNone(self.widget.attr_y)
self.assertFalse(self.widget.attr_box.isEnabled())
self.assertFalse(self.widget.vizrank.isEnabled())

self.send_signal(self.widget.Inputs.features, None)
self.assertEqual(self.widget.attr_x, self.data.domain[1])
self.assertEqual(self.widget.attr_y, self.data.domain[2])
self.assertTrue(self.widget.attr_box.isEnabled())
self.assertTrue(self.widget.vizrank.isEnabled())

# try with features not in data
bad_feat = AttributeList([ContinuousVariable("a"), ContinuousVariable("b")])
self.send_signal(self.widget.Inputs.features, bad_feat)
self.assertIsNone(self.widget.attr_x)
self.assertIsNone(self.widget.attr_y)
self.assertFalse(self.widget.attr_box.isEnabled())
self.assertFalse(self.widget.vizrank.isEnabled())

self.send_signal(self.widget.Inputs.features, None)
self.assertEqual(self.widget.attr_x, self.data.domain[1])
self.assertEqual(self.widget.attr_y, self.data.domain[2])
self.assertTrue(self.widget.attr_box.isEnabled())
self.assertTrue(self.widget.vizrank.isEnabled())

def test_output_features(self):
data = Table("iris")
self.send_signal(self.widget.Inputs.data, data)
Expand Down

0 comments on commit 84eafd2

Please sign in to comment.