Skip to content

Commit 5d673dd

Browse files
committed
heatmap: Add title to gradient legend
1 parent 6687af2 commit 5d673dd

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Orange/widgets/visualize/utils/heatmap.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,8 @@ def set_preferred_size(item, size):
862862
container.addItem(legend)
863863
elif isinstance(colormap, GradientColorMap):
864864
legend = GradientLegendWidget(
865-
*colormap.span, colormap,
866-
sizePolicy=QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum)
865+
*colormap.span, colormap, title=name,
866+
sizePolicy=QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum),
867867
)
868868
legend.setMinimumWidth(100)
869869
container.addItem(legend)
@@ -1262,7 +1262,8 @@ def showEvent(self, event):
12621262

12631263
class GradientLegendWidget(QGraphicsWidget):
12641264
def __init__(
1265-
self, low, high, colormap: GradientColorMap, parent=None, **kwargs
1265+
self, low, high, colormap: GradientColorMap, parent=None, title="",
1266+
**kwargs
12661267
):
12671268
kwargs.setdefault(
12681269
"sizePolicy", QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
@@ -1271,13 +1272,20 @@ def __init__(
12711272
self.low = low
12721273
self.high = high
12731274
self.colormap = colormap
1275+
self.title = title
12741276

12751277
layout = QGraphicsLinearLayout(Qt.Vertical)
12761278
layout.setContentsMargins(0, 0, 0, 0)
12771279
layout.setSpacing(0)
12781280
self.setLayout(layout)
1281+
if title:
1282+
titleitem = SimpleLayoutItem(
1283+
QGraphicsSimpleTextItem(title, self), parent=layout,
1284+
anchor=(0.5, 1.), anchorItem=(0.5, 1.0)
1285+
)
1286+
layout.addItem(titleitem)
12791287
self.__axis = axis = _GradientLegendAxisItem(
1280-
orientation="top", maxTickLength=3)
1288+
orientation="top", maxTickLength=3, text=title)
12811289
axis.setRange(low, high)
12821290
layout.addItem(axis)
12831291
pen = QPen(self.palette().color(QPalette.Text))

0 commit comments

Comments
 (0)