Repository: biolab/orange3

Issue:
Nomogram: Elide long variable names
<!-- 
Thanks for taking the time to report a bug!
If you're raising an issue about an add-on (i.e., installed via Options > Add-ons), raise an issue in the relevant add-on's issue tracker instead. See: https://github.com/biolab?q=orange3
To fix the bug, we need to be able to reproduce it. Please answer the following questions to the best of your ability.
-->


**What's wrong?**
<!-- Be specific, clear, and concise. Include screenshots if relevant. -->
<!-- If you're getting an error message, copy it, and enclose it with three backticks (```). -->
Nomogram is a bit problematic with long variable names. When resizing, variable names don't get resized, but the scales do. If variables names are long, this would be problematic. I propose to elide long variable names and show full names in tooltips instead.


This example shows and extreme case where variable names are long and widget is quite resized. Variable names being to overlap with scales and the below probabilities shrink to zero, because they size of the text on the left depends on variable names.
<img width="735" alt="Screen Shot 2022-03-03 at 20 29 21" src="https://user-images.githubusercontent.com/12524972/156639685-be4a1e42-d1ac-4630-a278-3b4e9bb3083f.png">



**How can we reproduce the problem?** 
<!-- Upload a zip with the .ows file and data. -->
<!-- Describe the steps (open this widget, click there, then add this...) -->
Datasets (HDI), predict continent (or Cluster if easier). Naive Bayes - Nomogram.



**What's your environment?**
<!-- To find your Orange version, see "Help → About → Version" or `Orange.version.full_version` in code -->
- Operating system: OSX
- Orange version: 3.32.dev
- How you installed Orange: pip



Discussion:

Resolving patch:
diff --git a/Orange/widgets/visualize/ownomogram.py b/Orange/widgets/visualize/ownomogram.py
--- a/Orange/widgets/visualize/ownomogram.py
+++ b/Orange/widgets/visualize/ownomogram.py
@@ -14,7 +14,7 @@
     QGraphicsEllipseItem, QGraphicsLinearLayout, QGridLayout, QLabel, QFrame,
     QSizePolicy
 )
-from AnyQt.QtGui import QColor, QPainter, QFont, QPen, QBrush
+from AnyQt.QtGui import QColor, QPainter, QFont, QPen, QBrush, QFontMetrics
 from AnyQt.QtCore import Qt, QRectF, QSize, QPropertyAnimation, QObject, \
     pyqtProperty
 
@@ -784,7 +784,7 @@ def is_resizing(self):
                 return self._is_resizing
 
             def sizeHint(self):
-                return QSize(400, 200)
+                return QSize(500, 200)
 
         class FixedSizeGraphicsView(_GraphicsView):
             def __init__(self, scene, parent):
@@ -949,11 +949,20 @@ def update_scene(self):
         attr_inds, attributes = zip(*self.get_ordered_attributes()[:n_attrs])
         self.Outputs.features.send(AttributeList(attributes))
 
-        name_items = [QGraphicsTextItem(attr.name) for attr in attributes]
         point_text = QGraphicsTextItem("Points")
+        metric = QFontMetrics(point_text.font())
+
+        def text_item(text):
+            elided_text = metric.elidedText(text, Qt.ElideRight, 200)
+            item = QGraphicsTextItem(elided_text)
+            item.setToolTip(text)
+            return item
+
+        name_items = [text_item(attr.name) for attr in attributes]
+
         probs_text = QGraphicsTextItem("Probabilities (%)")
         all_items = name_items + [point_text, probs_text]
-        name_offset = -max(t.boundingRect().width() for t in all_items) - 10
+        name_offset = -max(t.boundingRect().width() for t in all_items) - 30
         w = self.view.viewport().rect().width()
         max_width = w + name_offset - 30
 


Test patch: