Plot tab: HH:MM:SS x-axis ticks, date label in control bar
Replace pg.DateAxisItem with a custom TimeAxisItem that formats ticks as HH:MM:SS, eliminating locale-dependent day/date prefixes on the axis. Add a per-plot date label (right-aligned in the control bar) that shows the date range of the visible window — single date when the view stays within one day, "YYYY-MM-DD – YYYY-MM-DD" when it spans midnight. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+24
-2
@@ -384,6 +384,12 @@ class DashboardTab(QWidget):
|
|||||||
|
|
||||||
# ── Plot tab ──────────────────────────────────────────────────────────────────
|
# ── Plot tab ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class TimeAxisItem(pg.AxisItem):
|
||||||
|
"""X-axis that shows HH:MM:SS, suppressing any date prefix."""
|
||||||
|
def tickStrings(self, values, scale, spacing):
|
||||||
|
return [datetime.fromtimestamp(v).strftime("%H:%M:%S") for v in values]
|
||||||
|
|
||||||
|
|
||||||
class PlotTab(QWidget):
|
class PlotTab(QWidget):
|
||||||
NUM_PLOTS = 8
|
NUM_PLOTS = 8
|
||||||
MAX_TRACES = 4
|
MAX_TRACES = 4
|
||||||
@@ -421,6 +427,7 @@ class PlotTab(QWidget):
|
|||||||
self._proxies: list = []
|
self._proxies: list = []
|
||||||
self._add_combos: list[QComboBox] = []
|
self._add_combos: list[QComboBox] = []
|
||||||
self._chip_bars: list[QHBoxLayout] = []
|
self._chip_bars: list[QHBoxLayout] = []
|
||||||
|
self._date_labels: list[QLabel] = []
|
||||||
|
|
||||||
for i in range(self.NUM_PLOTS):
|
for i in range(self.NUM_PLOTS):
|
||||||
cell = QWidget()
|
cell = QWidget()
|
||||||
@@ -465,12 +472,18 @@ class PlotTab(QWidget):
|
|||||||
ctrl_row.addLayout(chip_bar)
|
ctrl_row.addLayout(chip_bar)
|
||||||
ctrl_row.addStretch()
|
ctrl_row.addStretch()
|
||||||
|
|
||||||
|
date_lbl = QLabel("")
|
||||||
|
date_lbl.setStyleSheet("color: #666688; font-size: 10px;")
|
||||||
|
date_lbl.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
||||||
|
self._date_labels.append(date_lbl)
|
||||||
|
ctrl_row.addWidget(date_lbl)
|
||||||
|
|
||||||
cell_vbox.addWidget(ctrl)
|
cell_vbox.addWidget(ctrl)
|
||||||
|
|
||||||
# plot
|
# plot
|
||||||
pw = pg.PlotWidget(
|
pw = pg.PlotWidget(
|
||||||
background="#12121e",
|
background="#12121e",
|
||||||
axisItems={"bottom": pg.DateAxisItem(orientation="bottom")},
|
axisItems={"bottom": TimeAxisItem(orientation="bottom")},
|
||||||
)
|
)
|
||||||
pw.showGrid(x=True, y=True, alpha=0.3)
|
pw.showGrid(x=True, y=True, alpha=0.3)
|
||||||
pw.addLegend(offset=(0, 0), labelTextSize="8pt")
|
pw.addLegend(offset=(0, 0), labelTextSize="8pt")
|
||||||
@@ -663,7 +676,16 @@ class PlotTab(QWidget):
|
|||||||
name=label,
|
name=label,
|
||||||
)
|
)
|
||||||
|
|
||||||
pw.setXRange(x_min if x_min is not None else cutoff, now, padding=0.02)
|
x_lo = x_min if x_min is not None else cutoff
|
||||||
|
pw.setXRange(x_lo, now, padding=0.02)
|
||||||
|
|
||||||
|
d_lo = datetime.fromtimestamp(x_lo).date()
|
||||||
|
d_hi = datetime.fromtimestamp(now).date()
|
||||||
|
if d_lo == d_hi:
|
||||||
|
date_str = d_lo.strftime("%Y-%m-%d")
|
||||||
|
else:
|
||||||
|
date_str = f"{d_lo.strftime('%Y-%m-%d')} – {d_hi.strftime('%Y-%m-%d')}"
|
||||||
|
self._date_labels[i].setText(date_str)
|
||||||
|
|
||||||
# ── cursor tracing ────────────────────────────────────────────────────────
|
# ── cursor tracing ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user