refactor: relocate live stream controls to ReadoutPanel and update chart axis rendering
This commit is contained in:
@@ -44,6 +44,11 @@ class TrendChartItem(QQuickPaintedItem):
|
||||
|
||||
self._data: list[float] = []
|
||||
self._padding: int = 8
|
||||
# Separate from `_padding` (breathing room around the plot area): these
|
||||
# reserve space for the axis labels themselves, which are wider than
|
||||
# `_padding` alone — that mismatch is what clipped y-axis text before.
|
||||
self._margin_left: int = 34
|
||||
self._margin_bottom: int = 16
|
||||
self._line_color = QColor("#5B9DF5")
|
||||
self._grid_color = QColor("#2A3441")
|
||||
self._text_color = QColor("#CBD5E1")
|
||||
@@ -153,9 +158,11 @@ class TrendChartItem(QQuickPaintedItem):
|
||||
if w <= 0 or h <= 0:
|
||||
return
|
||||
|
||||
plot_rect = QRectF(self._padding, self._padding,
|
||||
max(1, w - 2 * self._padding),
|
||||
max(1, h - 2 * self._padding))
|
||||
left = self._padding + self._margin_left
|
||||
bottom_inset = self._padding + self._margin_bottom
|
||||
plot_rect = QRectF(left, self._padding,
|
||||
max(1, w - left - self._padding),
|
||||
max(1, h - self._padding - bottom_inset))
|
||||
|
||||
self._draw_grid(painter, plot_rect)
|
||||
|
||||
@@ -220,16 +227,36 @@ class TrendChartItem(QQuickPaintedItem):
|
||||
font = QFont(painter.font())
|
||||
font.setPointSizeF(max(7.0, font.pointSizeF() * 0.85))
|
||||
painter.setFont(font)
|
||||
|
||||
rows = 4
|
||||
label_w = self._margin_left - 4 # 4px gutter before the plot area
|
||||
for i in range(rows + 1):
|
||||
t = i / rows
|
||||
y_val = y_max - t * (y_max - y_min)
|
||||
y_px = plot_rect.top() + t * plot_rect.height()
|
||||
label = f"{y_val:.1f}"
|
||||
painter.drawText(QRectF(0, y_px - 7, self._padding, 14),
|
||||
painter.drawText(QRectF(0, y_px - 7, label_w, 14),
|
||||
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter,
|
||||
label)
|
||||
|
||||
# X-axis: sample index. `trendData` carries plain averages with no
|
||||
# timestamps attached, so index is the only x-coordinate available —
|
||||
# it reads correctly for review mode (index == frame number) and as a
|
||||
# relative recency order for the live rolling window. paint() already
|
||||
# guarantees len(self._data) >= 2 before calling this.
|
||||
n = len(self._data)
|
||||
cols = min(4, n - 1)
|
||||
y_px = plot_rect.bottom() + 4
|
||||
for i in range(cols + 1):
|
||||
idx = round((i / cols) * (n - 1))
|
||||
x_px = self._x_to_px(idx, n, plot_rect)
|
||||
align = (Qt.AlignmentFlag.AlignLeft if i == 0
|
||||
else Qt.AlignmentFlag.AlignRight if i == cols
|
||||
else Qt.AlignmentFlag.AlignHCenter)
|
||||
painter.drawText(QRectF(x_px - 20, y_px, 40, 14),
|
||||
align | Qt.AlignmentFlag.AlignTop,
|
||||
str(idx))
|
||||
|
||||
def _draw_line(
|
||||
self,
|
||||
painter: QPainter,
|
||||
|
||||
Reference in New Issue
Block a user