Skip to content

Commit cd3dfee

Browse files
authored
Merge pull request #5988 from VesnaT/nomogram_elide_text
Nomogram: Elide long variable names
2 parents db4043a + 55d0b7c commit cd3dfee

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Orange/widgets/visualize/ownomogram.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
QGraphicsEllipseItem, QGraphicsLinearLayout, QGridLayout, QLabel, QFrame,
1515
QSizePolicy
1616
)
17-
from AnyQt.QtGui import QColor, QPainter, QFont, QPen, QBrush
17+
from AnyQt.QtGui import QColor, QPainter, QFont, QPen, QBrush, QFontMetrics
1818
from AnyQt.QtCore import Qt, QRectF, QSize, QPropertyAnimation, QObject, \
1919
pyqtProperty
2020

@@ -784,7 +784,7 @@ def is_resizing(self):
784784
return self._is_resizing
785785

786786
def sizeHint(self):
787-
return QSize(400, 200)
787+
return QSize(500, 200)
788788

789789
class FixedSizeGraphicsView(_GraphicsView):
790790
def __init__(self, scene, parent):
@@ -949,11 +949,20 @@ def update_scene(self):
949949
attr_inds, attributes = zip(*self.get_ordered_attributes()[:n_attrs])
950950
self.Outputs.features.send(AttributeList(attributes))
951951

952-
name_items = [QGraphicsTextItem(attr.name) for attr in attributes]
953952
point_text = QGraphicsTextItem("Points")
953+
metric = QFontMetrics(point_text.font())
954+
955+
def text_item(text):
956+
elided_text = metric.elidedText(text, Qt.ElideRight, 200)
957+
item = QGraphicsTextItem(elided_text)
958+
item.setToolTip(text)
959+
return item
960+
961+
name_items = [text_item(attr.name) for attr in attributes]
962+
954963
probs_text = QGraphicsTextItem("Probabilities (%)")
955964
all_items = name_items + [point_text, probs_text]
956-
name_offset = -max(t.boundingRect().width() for t in all_items) - 10
965+
name_offset = -max(t.boundingRect().width() for t in all_items) - 30
957966
w = self.view.viewport().rect().width()
958967
max_width = w + name_offset - 30
959968

0 commit comments

Comments
 (0)