From ad7a9a246ec81b59968441b502b189910f772623 Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Mon, 19 Feb 2024 13:58:00 +0100 Subject: [PATCH] owheatmap: Fix inconsistent row_color_annotations A combo box for choosing row annotation color is limited to metas and class vars, and thus, when a selected feature was moved from metas to attributes, an incompatible context would match. That did not trigger any crashes because the combo box was updated through special functions, but it did leave the UI in an inconsistent state: an element with index of -1 was selected in the combo (""), and, the saved color was still shown in the map. --- Orange/widgets/visualize/owheatmap.py | 6 +++--- Orange/widgets/visualize/tests/test_owheatmap.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Orange/widgets/visualize/owheatmap.py b/Orange/widgets/visualize/owheatmap.py index 53d1845331d..4ba24e8db84 100644 --- a/Orange/widgets/visualize/owheatmap.py +++ b/Orange/widgets/visualize/owheatmap.py @@ -146,9 +146,9 @@ class Outputs: selected_data = Output("Selected Data", Table, default=True) annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table) - settings_version = 3 + settings_version = 4 - settingsHandler = settings.DomainContextHandler() + settingsHandler = settings.DomainContextHandlerPosition() # Disable clustering for inputs bigger than this MaxClustering = 25000 @@ -170,7 +170,7 @@ class Outputs: #: text row annotation (row names) annotation_var = settings.ContextSetting(None) #: color row annotation - annotation_color_var = settings.ContextSetting(None) + annotation_color_var = settings.ContextSetting(None, exclude_attributes=True) column_annotation_color_key: Optional[Tuple[str, str]] = settings.ContextSetting(None) # Discrete variable used to split that data/heatmaps (vertically) diff --git a/Orange/widgets/visualize/tests/test_owheatmap.py b/Orange/widgets/visualize/tests/test_owheatmap.py index d6f42f29154..7649a3299ef 100644 --- a/Orange/widgets/visualize/tests/test_owheatmap.py +++ b/Orange/widgets/visualize/tests/test_owheatmap.py @@ -365,6 +365,20 @@ def test_row_color_annotations_with_na(self): widget.set_annotation_color_var(None) self.assertFalse(widget.scene.widget.right_side_colors[0].isVisible()) + def test_row_color_annotations_invalid_context(self): + widget = self.widget + data = self.brown_selected[::5] + self.send_signal(widget.Inputs.data, data, widget=widget) + widget.set_annotation_color_var(data.domain["function"]) + self.assertTrue(widget.scene.widget.right_side_colors[0].isVisible()) + # attributes are ignored in for annotation_color_var, so the following + # data should not match any context + data_attributes = self.brown_selected.transform( + Domain(data.domain.attributes + data.domain.class_vars)) + self.send_signal(widget.Inputs.data, data_attributes, widget=widget) + self.assertEqual(widget.row_side_color_cb.currentText(), "(None)") + self.assertFalse(widget.scene.widget.right_side_colors[0].isVisible()) + def test_col_color_annotations(self): widget = self.widget data = self._brown_selected_10()