Expose numeric trend segment formulas from native reconstruction models
This commit is contained in:
28
python/set_devices/qt_ports/plot_annotations.py
Normal file
28
python/set_devices/qt_ports/plot_annotations.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Small right-aligned mathematical annotations shared by Qt plots."""
|
||||
try:
|
||||
from PySide6.QtCore import QRectF, Qt
|
||||
from PySide6.QtGui import QColor
|
||||
except ImportError:
|
||||
from PySide2.QtCore import QRectF, Qt
|
||||
from PySide2.QtGui import QColor
|
||||
|
||||
|
||||
def paint_formulas(painter, rect, entries):
|
||||
"""Draw (color, text) entries in the right half, wrapping long formulas."""
|
||||
painter.save()
|
||||
painter.setClipRect(rect)
|
||||
metrics = painter.fontMetrics()
|
||||
width = max(1., rect.width() * .48 - 12)
|
||||
top = rect.top() + 5
|
||||
flags = int(Qt.AlignRight | Qt.AlignTop | Qt.TextWordWrap)
|
||||
for color, text in entries:
|
||||
box = QRectF(rect.right() - width - 6, top, width, max(1., rect.bottom() - top))
|
||||
height = painter.boundingRect(box, flags, text).height()
|
||||
box.setHeight(height)
|
||||
painter.fillRect(box.adjusted(-3, -1, 3, 1), QColor('#0b1119'))
|
||||
painter.setPen(QColor(color))
|
||||
painter.drawText(box, flags, text)
|
||||
top += height + metrics.height() * .4
|
||||
if top >= rect.bottom():
|
||||
break
|
||||
painter.restore()
|
||||
@@ -332,6 +332,17 @@ class PlotProcessingAttachment(QObject):
|
||||
self._dirty = True
|
||||
self._refresh_timer.start(0)
|
||||
|
||||
def formula_entries(self, x, origin=0., unit=''):
|
||||
entries = []
|
||||
offset = self._external_offset if self._external_curve is not None else 0.
|
||||
for curve in self.curves:
|
||||
piece = curve.piece_at(x + offset)
|
||||
if piece is not None:
|
||||
color_index = self.panel._result_ids[id(curve)] if self._external_curve is None else 0
|
||||
text = curve.label + '\n' + piece.text(origin + offset, unit)
|
||||
entries.append((RESULT_COLORS[color_index % len(RESULT_COLORS)], text))
|
||||
return entries
|
||||
|
||||
def refresh(self):
|
||||
if self.panel is not None:
|
||||
self.panel.set_snapshot(self.snapshot())
|
||||
|
||||
Reference in New Issue
Block a user