Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be better to set attr_x and attr_y to the first two variables in the model, as default? Or did I miss something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, I wanted to explicitly show that the user provided the wrong features on the input (so nothing is plotted). Do you think it is better to plot the first two features and ignore the features input in this case?

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