From 4e45a8361169da750fae18d1d0b1fe4f507cddae Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Thu, 30 Jan 2020 17:01:16 +0100 Subject: [PATCH 1/6] owheatmap: Ignore width size hint for legend's pixmap --- Orange/widgets/visualize/owheatmap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Orange/widgets/visualize/owheatmap.py b/Orange/widgets/visualize/owheatmap.py index ef52521a574..91512062f32 100644 --- a/Orange/widgets/visualize/owheatmap.py +++ b/Orange/widgets/visualize/owheatmap.py @@ -2071,6 +2071,7 @@ def __init__(self, low, high, threshold_low, threshold_high, parent=None): self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.__pixitem = GraphicsPixmapWidget(parent=self, scaleContents=True, aspectMode=Qt.IgnoreAspectRatio) + self.__pixitem.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.__pixitem.setMinimumHeight(12) layout.addItem(self.__pixitem) self.__update() From 8126b2f99d42385a5e4a67dd0e04a0c4e930d67e Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Thu, 30 Jan 2020 17:19:55 +0100 Subject: [PATCH 2/6] owheatmap: Use font's line spacing to set preferred cell size --- Orange/widgets/visualize/owheatmap.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Orange/widgets/visualize/owheatmap.py b/Orange/widgets/visualize/owheatmap.py index 91512062f32..b9934984fb1 100644 --- a/Orange/widgets/visualize/owheatmap.py +++ b/Orange/widgets/visualize/owheatmap.py @@ -1836,8 +1836,9 @@ def _update_pixmap(self): self.heatmap_item.setMinimumSize(hmsize) self.averages_item.setMinimumSize(avsize) - self.heatmap_item.setPreferredSize(hmsize * 10) - self.averages_item.setPreferredSize(avsize * 10) + size = QFontMetrics(self.font()).lineSpacing() + self.heatmap_item.setPreferredSize(hmsize * size) + self.averages_item.setPreferredSize(avsize * size) self.layout().invalidate() def cell_at(self, pos): From ef79c82f5c046550265398a3e8ec3ccfc0d7124f Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Thu, 30 Jan 2020 18:01:01 +0100 Subject: [PATCH 3/6] owheatmap: Place label left of the heatmap --- Orange/widgets/visualize/owheatmap.py | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Orange/widgets/visualize/owheatmap.py b/Orange/widgets/visualize/owheatmap.py index b9934984fb1..862d6623cea 100644 --- a/Orange/widgets/visualize/owheatmap.py +++ b/Orange/widgets/visualize/owheatmap.py @@ -999,12 +999,13 @@ def setup_scene(self, parts, data): Col0 = 3 LegendRow = 0 # The column for the vertical dendrogram - DendrogramColumn = 0 + DendrogramColumn = 1 # The row for the horizontal dendrograms DendrogramRow = 1 RightLabelColumn = Col0 + M TopLabelsRow = 2 - BottomLabelsRow = Row0 + 2 * N + BottomLabelsRow = Row0 + N + GroupTitleColumn = 0 widget.setLayout(grid) @@ -1019,9 +1020,9 @@ def setup_scene(self, parts, data): for i, rowitem in enumerate(parts.rows): if rowitem.title: title = QGraphicsSimpleTextItem(rowitem.title, widget) - item = GraphicsSimpleTextLayoutItem(title, parent=grid) - item.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) - grid.addItem(item, Row0 + i * 2, Col0) + item = GraphicsSimpleTextLayoutItem(title, orientation=Qt.Vertical, parent=grid) + item.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Maximum) + grid.addItem(item, Row0 + i, GroupTitleColumn, alignment=Qt.AlignCenter) if rowitem.cluster: dendrogram = DendrogramWidget( @@ -1040,7 +1041,7 @@ def setup_scene(self, parts, data): self.__select_by_cluster(item, partindex) ) - grid.addItem(dendrogram, Row0 + i * 2 + 1, DendrogramColumn) + grid.addItem(dendrogram, Row0 + i, DendrogramColumn) sort_i.append(np.array(leaf_indices(rowitem.cluster))) row_dendrograms[i] = dendrogram else: @@ -1092,8 +1093,8 @@ def setup_scene(self, parts, data): hw.set_show_averages(self.averages) hw.set_heatmap_data(X_part) - grid.addItem(hw, Row0 + i * 2 + 1, Col0 + j) - grid.setRowStretchFactor(Row0 + i * 2 + 1, X_part.shape[0] * 100) + grid.addItem(hw, Row0 + i, Col0 + j) + grid.setRowStretchFactor(Row0 + i, X_part.shape[0] * 100) heatmap_row.append(hw) heatmap_widgets.append(heatmap_row) @@ -1121,7 +1122,7 @@ def setup_scene(self, parts, data): labelslist.setContentsMargins(0.0, 0.0, 0.0, 0.0) labelslist.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) - grid.addItem(labelslist, Row0 + i * 2 + 1, RightLabelColumn) + grid.addItem(labelslist, Row0 + i, RightLabelColumn) grid.setAlignment(labelslist, Qt.AlignLeft) row_annotation_widgets.append(labelslist) @@ -1203,8 +1204,7 @@ def __update_size_constraints(self): if mode == Qt.IgnoreAspectRatio: # Reset the row height constraints ... for i, hm_row in enumerate(self.heatmap_widget_grid): - layout.setRowMaximumHeight(3 + i * 2 + 1, np.finfo(np.float32).max) - layout.setRowPreferredHeight(3 + i * 2 + 1, 0) + layout.setRowMaximumHeight(3 + i, np.finfo(np.float32).max) # ... and resize to match the viewport, taking the minimum size # into account minsize = widget.minimumSize() @@ -1234,8 +1234,8 @@ def __update_size_constraints(self): Qt.KeepAspectRatioByExpanding) heights.append(hm_size.height()) - layout.setRowMaximumHeight(3 + i * 2 + 1, max(heights)) - layout.setRowPreferredHeight(3 + i * 2 + 1, max(heights)) + layout.setRowMaximumHeight(3 + i, max(heights)) + layout.setRowPreferredHeight(3 + i, max(heights)) # set/update the widget's height constraint = QSizeF(size.width(), -1) @@ -1505,7 +1505,7 @@ def update_column_annotations(self): TopLabelsRow = 2 Row0 = 3 - BottomLabelsRow = Row0 + 2 * len(self.heatmapparts.rows) + BottomLabelsRow = Row0 + len(self.heatmapparts.rows) layout = self.heatmap_scene.widget.layout() layout.setRowMaximumHeight(TopLabelsRow, -1 if show_top else 0) From 5f3bd5b7ed1d07aa863ac8a8d2bd59cb5da57f81 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Fri, 31 Jan 2020 10:46:09 +0100 Subject: [PATCH 4/6] owheatmap: Tighter layout --- Orange/widgets/visualize/owheatmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Orange/widgets/visualize/owheatmap.py b/Orange/widgets/visualize/owheatmap.py index 862d6623cea..2b0aca482c3 100644 --- a/Orange/widgets/visualize/owheatmap.py +++ b/Orange/widgets/visualize/owheatmap.py @@ -433,7 +433,7 @@ def _(): self.row_clustering_method = self.row_clustering.name # set default settings - self.space_x = 10 + self.space_x = 3 self.colorSettings = None self.selectedSchemaIndex = 0 From f749c2b5ba3a38b337b57ec1a6aaeef0d382f58b Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Fri, 31 Jan 2020 13:27:14 +0100 Subject: [PATCH 5/6] owheatmap: Use FLT_MAX to 'unset' the maximum row height constraints Negative max size is invalid and could cause a possbile endless loop in QGraphicsGridLayout. --- Orange/widgets/visualize/owheatmap.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Orange/widgets/visualize/owheatmap.py b/Orange/widgets/visualize/owheatmap.py index 2b0aca482c3..8ef52401b88 100644 --- a/Orange/widgets/visualize/owheatmap.py +++ b/Orange/widgets/visualize/owheatmap.py @@ -340,6 +340,9 @@ def enum_get(etype: Type[E], name: str, default: E) -> E: return default +FLT_MAX = np.finfo(np.float32).max + + class OWHeatMap(widget.OWWidget): name = "Heat Map" description = "Plot a data matrix heatmap." @@ -1204,7 +1207,7 @@ def __update_size_constraints(self): if mode == Qt.IgnoreAspectRatio: # Reset the row height constraints ... for i, hm_row in enumerate(self.heatmap_widget_grid): - layout.setRowMaximumHeight(3 + i, np.finfo(np.float32).max) + layout.setRowMaximumHeight(3 + i, FLT_MAX) # ... and resize to match the viewport, taking the minimum size # into account minsize = widget.minimumSize() @@ -1508,13 +1511,13 @@ def update_column_annotations(self): BottomLabelsRow = Row0 + len(self.heatmapparts.rows) layout = self.heatmap_scene.widget.layout() - layout.setRowMaximumHeight(TopLabelsRow, -1 if show_top else 0) + layout.setRowMaximumHeight(TopLabelsRow, FLT_MAX if show_top else 0) layout.setRowSpacing(TopLabelsRow, -1 if show_top else 0) for labelslist in self.col_annotation_widgets_bottom: labelslist.setVisible(show_bottom) - layout.setRowMaximumHeight(BottomLabelsRow, -1 if show_top else 0) + layout.setRowMaximumHeight(BottomLabelsRow, FLT_MAX if show_top else 0) self.__fixup_grid_layout() From a63c8c1bc94e9b8237cf944f0a66cc8286d6f806 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Tue, 4 Feb 2020 11:06:34 +0100 Subject: [PATCH 6/6] owheatmap: Remove unnecessary row constraints Prior to Qt 5.4 hidden QGraphicsWidgets retained their size in the layout. --- Orange/widgets/visualize/owheatmap.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Orange/widgets/visualize/owheatmap.py b/Orange/widgets/visualize/owheatmap.py index 8ef52401b88..6d562d43a04 100644 --- a/Orange/widgets/visualize/owheatmap.py +++ b/Orange/widgets/visualize/owheatmap.py @@ -1505,20 +1505,8 @@ def update_column_annotations(self): for labelslist in self.col_annotation_widgets_top: labelslist.setVisible(show_top) - - TopLabelsRow = 2 - Row0 = 3 - BottomLabelsRow = Row0 + len(self.heatmapparts.rows) - - layout = self.heatmap_scene.widget.layout() - layout.setRowMaximumHeight(TopLabelsRow, FLT_MAX if show_top else 0) - layout.setRowSpacing(TopLabelsRow, -1 if show_top else 0) - for labelslist in self.col_annotation_widgets_bottom: labelslist.setVisible(show_bottom) - - layout.setRowMaximumHeight(BottomLabelsRow, FLT_MAX if show_top else 0) - self.__fixup_grid_layout() def __select_by_cluster(self, item, dendrogramindex):