Skip to content

Commit

Permalink
Merge pull request #4390 from ales-erjavec/heatmap-layout-aspect
Browse files Browse the repository at this point in the history
[ENH] Heatmap: Tighter layout
  • Loading branch information
BlazZupan authored Feb 14, 2020
2 parents c488819 + a63c8c1 commit 9a4da3d
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions Orange/widgets/visualize/owheatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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."
Expand Down Expand Up @@ -303,7 +306,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
Expand Down Expand Up @@ -852,12 +855,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)

Expand All @@ -872,9 +876,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(
Expand All @@ -893,7 +897,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:
Expand Down Expand Up @@ -945,8 +949,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)

Expand Down Expand Up @@ -974,7 +978,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)

Expand Down Expand Up @@ -1056,8 +1060,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, FLT_MAX)
# ... and resize to match the viewport, taking the minimum size
# into account
minsize = widget.minimumSize()
Expand Down Expand Up @@ -1087,8 +1090,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)
Expand Down Expand Up @@ -1356,20 +1359,8 @@ def update_column_annotations(self):

for labelslist in self.col_annotation_widgets_top:
labelslist.setVisible(show_top)

TopLabelsRow = 2
Row0 = 3
BottomLabelsRow = Row0 + 2 * len(self.heatmapparts.rows)

layout = self.heatmap_scene.widget.layout()
layout.setRowMaximumHeight(TopLabelsRow, -1 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)

self.__fixup_grid_layout()

def __select_by_cluster(self, item, dendrogramindex):
Expand Down Expand Up @@ -1690,8 +1681,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):
Expand Down Expand Up @@ -1925,6 +1917,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()
Expand Down

0 comments on commit 9a4da3d

Please sign in to comment.