|
24 | 24 | ) |
25 | 25 | import pyqtgraph as pg |
26 | 26 |
|
27 | | -from Orange.data import Domain, Table, DiscreteVariable, StringVariable, \ |
28 | | - TimeVariable |
| 27 | +from Orange.data import Domain, Table |
29 | 28 | from Orange.data.sql.table import SqlTable |
30 | 29 | import Orange.distance |
31 | 30 |
|
32 | 31 | from Orange.clustering import hierarchical, kmeans |
| 32 | +from Orange.widgets.utils.itemmodels import DomainModel |
33 | 33 | from Orange.widgets.utils.stickygraphicsview import StickyGraphicsView |
34 | 34 | from Orange.widgets.utils import colorbrewer |
35 | 35 | from Orange.widgets.utils.annotated_data import (create_annotated_table, |
@@ -417,7 +417,7 @@ class Outputs: |
417 | 417 | # Display legend |
418 | 418 | legend = settings.Setting(True) |
419 | 419 | # Annotations |
420 | | - annotation_index = settings.ContextSetting(0) |
| 420 | + annotation_var = settings.ContextSetting(None) |
421 | 421 | # Stored color palette settings |
422 | 422 | color_settings = settings.Setting(None) |
423 | 423 | user_palettes = settings.Setting([]) |
@@ -552,9 +552,10 @@ def __init__(self): |
552 | 552 |
|
553 | 553 | annotbox = gui.vBox(box, "Row Annotations", addSpace=False) |
554 | 554 | annotbox.setFlat(True) |
555 | | - self.annotations_cb = gui.comboBox( |
556 | | - annotbox, self, "annotation_index", contentsLength=12, |
557 | | - items=self.annotation_vars, callback=self.update_annotations) |
| 555 | + self.annotation_model = DomainModel(placeholder="(None)") |
| 556 | + gui.comboBox( |
| 557 | + annotbox, self, "annotation_var", contentsLength=12, |
| 558 | + model=self.annotation_model, callback=self.update_annotations) |
558 | 559 |
|
559 | 560 | posbox = gui.vBox(box, "Column Labels Position", addSpace=False) |
560 | 561 | posbox.setFlat(True) |
@@ -623,9 +624,8 @@ def clear(self): |
623 | 624 | self.effective_data = None |
624 | 625 | self.kmeans_model = None |
625 | 626 | self.merge_indices = None |
626 | | - self.annotations_cb.clear() |
627 | | - self.annotations_cb.addItem('(None)') |
628 | | - self.annotation_vars = ['(None)'] |
| 627 | + self.annotation_model.set_domain(None) |
| 628 | + self.annotation_var = None |
629 | 629 | self.clear_scene() |
630 | 630 | self.selected_rows = [] |
631 | 631 | self.__columns_cache.clear() |
@@ -703,19 +703,9 @@ def set_dataset(self, data=None): |
703 | 703 | self.input_data = input_data |
704 | 704 |
|
705 | 705 | if data is not None: |
706 | | - variables = self.data.domain.class_vars + self.data.domain.metas |
707 | | - variables = [var for var in variables |
708 | | - if isinstance(var, (DiscreteVariable, |
709 | | - StringVariable, |
710 | | - TimeVariable))] |
711 | | - self.annotation_vars.extend(variables) |
712 | | - |
713 | | - for var in variables: |
714 | | - self.annotations_cb.addItem(*gui.attributeItem(var)) |
715 | | - |
716 | | - self.openContext(self.data) |
717 | | - if self.annotation_index >= len(self.annotation_vars): |
718 | | - self.annotation_index = 0 |
| 706 | + self.annotation_model.set_domain(self.input_data.domain) |
| 707 | + self.annotation_var = None |
| 708 | + self.openContext(self.input_data) |
719 | 709 |
|
720 | 710 | self.update_heatmaps() |
721 | 711 | if data is not None and self.__pending_selection is not None: |
@@ -1410,13 +1400,7 @@ def update_legend(self): |
1410 | 1400 |
|
1411 | 1401 | def update_annotations(self): |
1412 | 1402 | if self.input_data is not None: |
1413 | | - if self.annotation_vars: |
1414 | | - var = self.annotation_vars[self.annotation_index] |
1415 | | - if var == '(None)': |
1416 | | - var = None |
1417 | | - else: |
1418 | | - var = None |
1419 | | - |
| 1403 | + var = self.annotation_var |
1420 | 1404 | show = var is not None |
1421 | 1405 | if show: |
1422 | 1406 | annot_col, _ = self.input_data.get_column_view(var) |
@@ -1538,8 +1522,7 @@ def send_report(self): |
1538 | 1522 | ("Columns:", "Clustering" if self.col_clustering else "No sorting"), |
1539 | 1523 | ("Rows:", "Clustering" if self.row_clustering else "No sorting"), |
1540 | 1524 | ("Row annotation", |
1541 | | - self.annotation_index > 0 and |
1542 | | - self.annotation_vars[self.annotation_index]) |
| 1525 | + self.annotation_var is not None and self.annotation_var.name) |
1543 | 1526 | )) |
1544 | 1527 | self.report_plot() |
1545 | 1528 |
|
|
0 commit comments