From b997cd956a96ec453944cc725c90a8273c2b5339 Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Fri, 20 Nov 2026 06:39:25 +1000 Subject: [PATCH 1/3] Charts: axis fits close runs, target on every availability chart, Results can be maximised - A percentage axis under one point wide is drawn to fit (runs from 99.85 % to 99.995 % sat in the top sixth of a 99-100 % axis). - The page's target is drawn on the ladder, the waterfall and both year charts; 'A bad year' said 'no threshold was set' beside a target. - The Run tab's content-height cap applied while it was a tab behind Results, so the bottom panel could not be dragged taller. - The Results title bar has Maximise / Restore. --- raptor/api/insight/axes.py | 12 ++- raptor/api/insight/charts.py | 45 ++++++--- raptor/gui/ui/chart_widget.py | 21 ++++- raptor/gui/ui/charts_page.py | 15 ++- raptor/gui/ui/dock_chrome.py | 34 ++++++- raptor/gui/ui/dock_float_mixin.py | 17 ++++ raptor/gui/ui/main_window.py | 4 +- raptor/gui/ui/run_panel.py | 19 +++- raptor/render/charts_svg.py | 8 +- tests/unit/insight/test_charts.py | 2 +- .../unit/test_charts_target_range_maximise.py | 91 +++++++++++++++++++ 11 files changed, 240 insertions(+), 28 deletions(-) create mode 100644 tests/unit/test_charts_target_range_maximise.py diff --git a/raptor/api/insight/axes.py b/raptor/api/insight/axes.py index 89c01682..a447d839 100644 --- a/raptor/api/insight/axes.py +++ b/raptor/api/insight/axes.py @@ -41,10 +41,18 @@ def nice_range(low: float, high: float, count: int = 5, *, """[low, high] widened to whole tick steps (so the axis ends on a tick). `share`: the values are fractions (availability, a share), so the axis - never leaves 0..1 and spans at least one point. Every run at 100 % - drew an axis to 101 %, and a spread of 6e-8 gave ticks at 8 decimals.""" + never leaves 0..1. Every run at 100 % drew an axis to 101 %, and a + spread of 6e-8 gave ticks at 8 decimals, so a spread under a thousandth + of a point is drawn one point wide. A larger spread under one point is + drawn to fit, with a tenth of it as margin: runs from 99.85 % to + 99.995 % were drawn on a 99 % to 100 % axis, all in its top sixth. + Callers put the target in `low`..`high`, so it is always on the axis.""" if share: low, high = max(0.0, min(low, 1.0)), max(0.0, min(high, 1.0)) + if 1e-5 <= high - low < 0.01: + margin = 0.1 * (high - low) + low, high = nice_range(max(0.0, low - margin), min(1.0, high + margin), count) + return max(0.0, low), min(1.0, high) if high - low < 0.01: middle = (low + high) / 2 low, high = middle - 0.005, middle + 0.005 diff --git a/raptor/api/insight/charts.py b/raptor/api/insight/charts.py index 9918c45f..975cd9db 100644 --- a/raptor/api/insight/charts.py +++ b/raptor/api/insight/charts.py @@ -467,7 +467,8 @@ def downtime_pareto(attribution: dict[str, Any], top: int = 10) -> ChartSpec: def downtime_waterfall(attribution: dict[str, Any], - operational: float | None = None) -> ChartSpec: + operational: float | None = None, + target: float | None = None) -> ChartSpec: """C3: from 100 % availability to the achieved one, one step per cause.""" causes = attribution.get("causes") or {} loss = 1.0 - operational if operational is not None else None @@ -496,13 +497,16 @@ def downtime_waterfall(attribution: dict[str, Any], "waterfall", "From full availability to the achieved one", "each step is a cause's share of the loss", "cause", "share of loss", series=steps, - marks=[{"kind": "end", "value": running}] if steps else [], + # a target only means something on the availability scale + marks=([{"kind": "end", "value": running}] if steps else []) + + ([{"kind": "target", "value": target}] + if target is not None and operational is not None and steps else []), caption=caption, provenance={"runs": attribution.get("runs", 0), "format": "percent", "operational": operational}) -def availability_ladder(ladder: dict[str, Any]) -> ChartSpec: +def availability_ladder(ladder: dict[str, Any], target: float | None = None) -> ChartSpec: """C4: inherent, achieved and operational availability with their gaps.""" order = (("inherent", "Inherent (repair only)"), ("achieved", "Achieved (+ planned maintenance)"), @@ -526,6 +530,7 @@ def availability_ladder(ladder: dict[str, Any]) -> ChartSpec: "ladder", "What each kind of availability keeps", "the gap between rungs is what the next cause takes away", "availability", "fraction", series=present, + marks=[{"kind": "target", "value": target}] if target is not None else [], caption=caption, provenance={"runs": ladder.get("runs"), "format": "percent"}) @@ -932,7 +937,17 @@ def annual_capacity_fan(periods: dict[str, Any]) -> ChartSpec: return spec -def annual_fan(periods: dict[str, Any]) -> ChartSpec: +def _year_line(periods: dict[str, Any], target: float | None + ) -> tuple[float | None, str]: + """The line the year charts draw and its name: the Charts page's + target when one is set (it said "no threshold was set" beside a + target the other charts drew), else the summary's own threshold.""" + if target is not None: + return target, "target" + return periods.get("threshold"), "threshold" + + +def annual_fan(periods: dict[str, Any], target: float | None = None) -> ChartSpec: """K6: does a bad year happen, and does it get worse with age?""" rows = [row for row in periods.get("by_index") or [] if row.get("n") and row.get("p50") is not None] @@ -941,7 +956,7 @@ def annual_fan(periods: dict[str, Any]) -> ChartSpec: "p50": row.get("p50"), "p75": row.get("p75"), "p95": row.get("p95"), "n": row.get("n")} for row in rows] - threshold = periods.get("threshold") + threshold, line = _year_line(periods, target) few = len(series) < FAN_LINE_MIN medians = ", ".join(pct(row["p50"]) for row in series) if not series: @@ -967,17 +982,17 @@ def annual_fan(periods: dict[str, Any]) -> ChartSpec: "across the runs: the dark band holds the middle half, the light one " "9 in 10, the line is the median"), "year", "availability", series=series, - marks=[{"kind": "target", "value": threshold}] + marks=[{"kind": "target", "value": threshold, "label": line}] if threshold is not None else [], caption=caption, provenance={"runs": periods.get("runs", 0), "format": "percent", "periods_per_run": periods.get("periods_per_run", 0)}) -def annual_dots(periods: dict[str, Any]) -> ChartSpec: +def annual_dots(periods: dict[str, Any], target: float | None = None) -> ChartSpec: """K7: all run-years as a dot plot against the guarantee.""" pooled = periods.get("pooled") or {} - threshold = periods.get("threshold") + threshold, line = _year_line(periods, target) n = int(pooled.get("n") or 0) if pooled.get("dots"): values = [float(v) for v in pooled["dots"]] @@ -992,9 +1007,15 @@ def annual_dots(periods: dict[str, Any]) -> ChartSpec: subtitle = "each dot is one of the quantiles P1 to P99 of the run-years" dots = [{"value": v} for v in values] below = pooled.get("p_below") - caption = (f"{pct(below)} of run-years fall below the threshold." - if isinstance(below, (int, float)) else - f"{pooled.get('n', 0)} run-years; no threshold was set.") + about = "" + if target is not None and target != periods.get("threshold") and values: + # equal-share dots: the share of dots below is the share of + # run-years below, exactly when there is one dot per run-year + below = sum(v < target for v in values) / len(values) + about = "" if len(values) == n else "about " + caption = (f"{about}{pct(below)} of run-years fall below the {line}." + if isinstance(below, (int, float)) and threshold is not None else + f"{pooled.get('n', 0)} run-years; no target was set.") if values: # a tall stack at the top had no scale: say how many it holds top = max(values) @@ -1006,7 +1027,7 @@ def annual_dots(periods: dict[str, Any]) -> ChartSpec: "dot_plot", "A bad year, as a frequency", subtitle, "availability", "years", series=[{"name": "run-years", "dots": dots}], - marks=[{"kind": "target", "value": threshold}] + marks=[{"kind": "target", "value": threshold, "label": line}] if threshold is not None else [], caption=caption, provenance={"runs": periods.get("runs", 0), "format": "percent", diff --git a/raptor/gui/ui/chart_widget.py b/raptor/gui/ui/chart_widget.py index deebbac4..424ef79c 100644 --- a/raptor/gui/ui/chart_widget.py +++ b/raptor/gui/ui/chart_widget.py @@ -698,7 +698,9 @@ def _paint_waterfall(self, painter, spec, palette, area) -> None: if not steps: return self._paint_none(painter, spec, palette, area) operational = spec.provenance.get("operational") - ends = [float(s["to"]) for s in steps] + [float(s["from"]) for s in steps] + target = self._target(spec) if _number(operational) else None + ends = [float(s["to"]) for s in steps] + [float(s["from"]) for s in steps] \ + + ([target] if target is not None else []) # Zoomed so the steps fill the height, with room under the result # so its bar is never a sliver. span = max(ends) - min(ends) @@ -768,6 +770,10 @@ def _paint_waterfall(self, painter, spec, palette, area) -> None: self._column_label(painter, palette, QRectF(x, r.bottom() + 4, width, 2 * fm.height()), "achieved" if _number(operational) else "rest") + if target is not None: + # last, over the result column, so its label is not hidden + self._target_line(painter, palette, frame, target, horizontal=True, + label=f"target {format_value(target, 'percent', 5)}") def _column_label(self, painter, palette, rect: QRectF, text: str) -> None: fm = QFontMetrics(self.font()) @@ -782,11 +788,13 @@ def _paint_ladder(self, painter, spec, palette, area) -> None: return self._paint_none(painter, spec, palette, area) fm = QFontMetrics(self.font()) values = [float(r["value"]) for r in rows] + target = self._target(spec) # Zoomed towards 100 %: the rungs differ by small amounts, and on a # 0-100 % axis every bar would look full. top_value = 1.0 if max(values) <= 1.0 else max(values) - span = max(top_value - min(values), 1e-9) - low, high = nice_range(min(values) - 0.6 * span, top_value, 4, + bottom = min(values + ([target] if target is not None else [])) + span = max(top_value - bottom, 1e-9) + low, high = nice_range(bottom - 0.6 * span, top_value, 4, share=top_value <= 1.0) low, high = max(0.0, low), (min(1.0, high) if top_value <= 1.0 else high) gutter = min(area.width() * 0.45, @@ -824,6 +832,9 @@ def _paint_ladder(self, painter, spec, palette, area) -> None: Qt.AlignmentFlag.AlignVCenter, text) self._hit(QRectF(r.left(), top, r.width(), bar_h), "rung", str(row["name"]), f"{row['name']}: {text}") + if target is not None: + self._target_line(painter, palette, frame, target, horizontal=False, + label=f"target {format_value(target, 'percent', 5)}") def _paint_histogram(self, painter, spec, palette, area) -> None: bins = [b for b in spec.series if _number(b.get("lo")) and _number(b.get("hi")) @@ -1121,8 +1132,10 @@ def _paint_fan(self, painter, spec, palette, area) -> None: else: self._paint_fan_bands(painter, palette, frame, rows) if target is not None: + word = next((str(m.get("label")) for m in spec.marks + if m.get("kind") == "target" and m.get("label")), "threshold") self._target_line(painter, palette, frame, target, horizontal=True, - label=f"threshold {format_value(target, fmt, 5)}") + label=f"{word} {format_value(target, fmt, 5)}") def read(px: float) -> list[tuple[QPointF, str]]: i = min(n - 1, max(0, round(frame.value_at_x(px)) - 1)) diff --git a/raptor/gui/ui/charts_page.py b/raptor/gui/ui/charts_page.py index b628d38e..aae3a521 100644 --- a/raptor/gui/ui/charts_page.py +++ b/raptor/gui/ui/charts_page.py @@ -61,7 +61,8 @@ class _Entry: #: The charts that draw a target line, where the Target button is shown. TARGET_CHARTS = ("trial-outcome", "ecdf", "convergence", "availability-through-run", - "interval-availability", "availability-band") + "interval-availability", "availability-band", "availability-ladder", + "downtime-waterfall", "annual-fan", "annual-dots") _RECORD_AO = ("These charts are drawn from the availability plot. " + run_needs.gui_hint("availability_plot")) @@ -371,6 +372,10 @@ def _catalogue(self) -> list[_Entry]: # noqa: C901, PLR0915 - one table of char periods = i.get("periods") report_data = i.get("report_data") or [] target, units = i.get("target"), i.get("units") or "" + # The ladder, the waterfall and the year charts are availability + # whatever the headline measure is: a dependability target is not + # drawn on them. + a_target = target if (i.get("measure") or "availability") == "availability" else None entries: list[_Entry] = [] def add(key: str, title: str, group: str, @@ -395,7 +400,7 @@ def add(key: str, title: str, group: str, lambda: charts.ecdf(per_run, measure, label=label, target=target, units=units), no_runs) add("availability-ladder", "Availability ladder", "The answer", - lambda: _with_run_id(charts.availability_ladder(_ladder(per_run)), i), + lambda: _with_run_id(charts.availability_ladder(_ladder(per_run), a_target), i), no_runs) add("convergence", "Has the run settled?", "The answer", lambda: charts.convergence(per_run, measure, target=target), @@ -448,7 +453,7 @@ def drivers_missing(_need: str = "") -> str: ("downtime-pareto", "Who causes the downtime", lambda: charts.downtime_pareto(a), ""), ("downtime-waterfall", "Where availability is lost", - lambda: charts.downtime_waterfall(a, operational), ""), + lambda: charts.downtime_waterfall(a, operational, a_target), ""), ("downtime-treemap", "Downtime treemap", lambda: charts.downtime_treemap(a), ""), ("phase-downtime", "Downtime by phase", @@ -508,10 +513,10 @@ def drivers_missing(_need: str = "") -> str: ("attribution",) if not attribution and not action else ()) p = periods or {} add("annual-fan", "Availability year by year", "Year by year", - lambda: charts.annual_fan(p), no_years, action if not attribution else "", + lambda: charts.annual_fan(p, a_target), no_years, action if not attribution else "", needs=years_needs) add("annual-dots", "A bad year, as a frequency", "Year by year", - lambda: charts.annual_dots(p), no_years, action if not attribution else "", + lambda: charts.annual_dots(p, a_target), no_years, action if not attribution else "", needs=years_needs) add("annual-capacity-fan", "Capacity delivered year by year", "Year by year", lambda: charts.annual_capacity_fan(p), diff --git a/raptor/gui/ui/dock_chrome.py b/raptor/gui/ui/dock_chrome.py index c57a9a72..089bb994 100644 --- a/raptor/gui/ui/dock_chrome.py +++ b/raptor/gui/ui/dock_chrome.py @@ -34,6 +34,36 @@ _SIDE = ("left", "right") + +def _sync_maximise(button: QToolButton, dock: QDockWidget) -> None: + """"Restore" while the Results fill the screen in their own window.""" + try: + full = dock.isFloating() and dock.isMaximized() + except RuntimeError: # torn down + return + button.setText("Restore" if full else "Maximise") + button.setToolTip("Put the Results back in the main window" if full + else "Show the Results full screen in their own window") + + +def _maximise_button(win: Any, dock: QDockWidget, layout: QHBoxLayout) -> QToolButton | None: + """The Results' Maximise / Restore button (no other dock has one). + + The bottom strip keeps the canvas's own minimum, so on a short screen + a chart could not be seen whole: Maximise gives the Results a window + of their own at full screen, Restore docks them again.""" + if dock is not getattr(win, "_results_dock", None): + return None + button = QToolButton() + button.setAutoRaise(True) + button.setText("Maximise") + button.setToolTip("Show the Results full screen in their own window") + button.setAccessibleName("Maximise the Results") + button.clicked.connect(lambda _checked=False: win._maximise_results()) + dock.topLevelChanged.connect(lambda _floating: _sync_maximise(button, dock)) + layout.addWidget(button) + return button + class DockSlotChrome: """Title bars, minimise/restore and the closed stub for one dock slot.""" @@ -78,6 +108,8 @@ def _build_entry(self, dock: QDockWidget) -> dict[str, Any]: tb.addWidget(label) tb.addStretch(1) + max_btn = _maximise_button(win, dock, tb) + min_btn = QToolButton() min_btn.setAutoRaise(True) min_btn.setText(self.glyph_collapse) @@ -124,7 +156,7 @@ def _build_entry(self, dock: QDockWidget) -> dict[str, Any]: return {"dock": dock, "content": content, "titlebar": titlebar, "icon_label": icon_label, "label": label, - "min_btn": min_btn, "float_btn": float_btn, + "min_btn": min_btn, "float_btn": float_btn, "max_btn": max_btn, "close_btn": close_btn, "stub": stub, "edge": self.edge, "normal_min_width": max(dock.minimumWidth(), 0), diff --git a/raptor/gui/ui/dock_float_mixin.py b/raptor/gui/ui/dock_float_mixin.py index 21c108e1..cd216adb 100644 --- a/raptor/gui/ui/dock_float_mixin.py +++ b/raptor/gui/ui/dock_float_mixin.py @@ -60,6 +60,23 @@ def _results_window_title(self) -> str: apart from the main window in the taskbar and Alt+Tab.""" return self.windowTitle().replace("RAPTOR Studio", "Results", 1) + def _maximise_results(self) -> None: + """Maximise: the Results in their own window, full screen; pressed + again (Restore), back in the main window at their docked size.""" + dock = self._results_dock + if dock.isFloating() and dock.isMaximized(): + self._float_results_properly(dock, False) + else: + if not dock.isFloating(): + self._float_results_properly(dock, True) + dock.showMaximized() + dock.raise_() + dock.activateWindow() + entry = (getattr(self, "_dock_chrome_entries", None) or {}).get(dock) or {} + if entry.get("max_btn") is not None: + from raptor.gui.ui.dock_chrome import _sync_maximise + _sync_maximise(entry["max_btn"], dock) + def _float_results(self, checked: bool): self._float_results_properly(self._results_dock, checked) diff --git a/raptor/gui/ui/main_window.py b/raptor/gui/ui/main_window.py index 6047f892..594362d4 100644 --- a/raptor/gui/ui/main_window.py +++ b/raptor/gui/ui/main_window.py @@ -3741,7 +3741,9 @@ def _on_ribbon_tab_changed(self, index: int): # arrived clipped to the 150 px startup strip (reported: # "ok when I click the Run panel, not when I open the # Simulate ribbon"). Measure it here, the way the tab click - # does. + # does, as the tab on show (fit_height lifts its cap for a + # tab behind another). + self._bottom_active_dock = run if hasattr(run, "fit_height"): run.fit_height() sync = (getattr(self, "_dock_state_sync", None) or {}).get(run) diff --git a/raptor/gui/ui/run_panel.py b/raptor/gui/ui/run_panel.py index 098a61d9..a8706c5a 100644 --- a/raptor/gui/ui/run_panel.py +++ b/raptor/gui/ui/run_panel.py @@ -1821,7 +1821,13 @@ def fit_height(self) -> None: hidden = self.isHidden() except RuntimeError: # C++ object gone (window closing) return - if self.isFloating() or hidden: + win = self.window() + # A tab behind Results is moved off screen, not hidden, so + # isHidden() alone kept the cap on it, and the shared strip could + # not be dragged taller than the Run panel while Results was on show. + active = getattr(win, "_bottom_active_dock", None) + behind = active is not self if active is not None else self._behind_a_tab(win) + if self.isFloating() or hidden or behind: self.setMaximumHeight(16777215) return tb = self.titleBarWidget() @@ -1838,6 +1844,17 @@ def fit_height(self) -> None: if not getattr(self, "_growing", False) and self.height() < want: self._grow_to(want) + def _behind_a_tab(self, win) -> bool: + """True when a tab bar holds this dock and another tab is on show + (a restored layout has no active bottom tab recorded yet).""" + from PySide6.QtWidgets import QTabBar + title = self.windowTitle() + for bar in win.findChildren(QTabBar): + titles = [bar.tabText(i) for i in range(bar.count())] + if title in titles and bar.parent() is win: + return bar.tabText(bar.currentIndex()) != title + return False + def _grow_to(self, want: int) -> None: """Ask the window for a taller bottom strip (one shared strip).""" win = self.window() diff --git a/raptor/render/charts_svg.py b/raptor/render/charts_svg.py index 43bb710d..9ccefe3c 100644 --- a/raptor/render/charts_svg.py +++ b/raptor/render/charts_svg.py @@ -318,6 +318,12 @@ def _target(spec: ChartSpec) -> float | None: if m.get("kind") == "target" and _number(m.get("value"))), None) +def _target_word(spec: ChartSpec) -> str: + """"target" for the Charts page's target, "threshold" for a summary's.""" + return next((str(m["label"]) for m in spec.marks + if m.get("kind") == "target" and m.get("label")), "threshold") + + def _target_line(out: list[str], frame: _Frame, value: float, *, horizontal: bool, label: str) -> None: box = frame.box @@ -942,7 +948,7 @@ def _fan(spec: ChartSpec, area: _Box) -> list[str]: _fan_bands(out, rows, frame) if target is not None: _target_line(out, frame, target, horizontal=True, - label=f"threshold {format_value(target, fmt, 5)}") + label=f"{_target_word(spec)} {format_value(target, fmt, 5)}") return out diff --git a/tests/unit/insight/test_charts.py b/tests/unit/insight/test_charts.py index 370e53e6..92ae9aec 100644 --- a/tests/unit/insight/test_charts.py +++ b/tests/unit/insight/test_charts.py @@ -209,7 +209,7 @@ def test_the_annual_fan_keeps_the_bands_and_the_threshold(): periods["by_index"] = periods["by_index"] * 2 spec = charts.annual_fan(periods) assert spec.kind == "fan" and len(spec.series) == 4 - assert spec.marks == [{"kind": "target", "value": 0.95}] + assert spec.marks == [{"kind": "target", "value": 0.95, "label": "threshold"}] assert "median moves" in spec.caption and "band" in spec.subtitle diff --git a/tests/unit/test_charts_target_range_maximise.py b/tests/unit/test_charts_target_range_maximise.py new file mode 100644 index 00000000..8dd1eeca --- /dev/null +++ b/tests/unit/test_charts_target_range_maximise.py @@ -0,0 +1,91 @@ +"""The target on every availability chart, an axis that fits runs close +to 100 %, and a Results panel that can be seen whole.""" +from __future__ import annotations + +import os + +import pytest + +from raptor.api.insight import charts +from raptor.api.insight.axes import nice_range +from raptor.api.insight.periods import summarise + +os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") + + +@pytest.mark.parametrize("low, high, floor", [ + (0.9985, 0.99995, 0.998), # DC2-like runs: was 99 % to 100 % + (0.998, 0.99995, 0.9975), # a 99.8 % target in the range + (0.9999, 0.99999, 0.9998), +]) +def test_runs_close_to_100_are_drawn_to_fit(low, high, floor): + lo, hi = nice_range(low, high, 5, share=True) + assert floor <= lo <= low and high <= hi <= 1.0 + + +def _target(spec): + return [m for m in spec.marks if m.get("kind") == "target"] + + +def test_the_year_charts_use_the_pages_target(): + years = [[0.997, 0.999, 1.0], [0.9985, 0.9995, 0.999]] + periods = summarise(years) # no threshold of its own + dots = charts.annual_dots(periods, 0.998) + assert _target(dots) == [{"kind": "target", "value": 0.998, "label": "target"}] + assert dots.caption.startswith("16.7 % of run-years fall below the target") + assert "no target was set" in charts.annual_dots(periods).caption + fan = charts.annual_fan(periods, 0.998) + assert _target(fan)[0]["value"] == 0.998 + + +def test_the_ladder_and_waterfall_carry_the_target(): + ladder = charts.availability_ladder({"inherent": {"value": 0.9995}}, 0.998) + assert _target(ladder)[0]["value"] == 0.998 + att = {"runs": 2, "causes": {"repair": 1.0}, "elements": []} + assert _target(charts.downtime_waterfall(att, 0.999, 0.998))[0]["value"] == 0.998 + # as shares of the loss there is no availability scale for a target + assert _target(charts.downtime_waterfall(att, None, 0.998)) == [] + + +@pytest.fixture +def window(): + from PySide6.QtTest import QTest + from PySide6.QtWidgets import QApplication + + from raptor.gui.ui.main_window import MainWindow + app = QApplication.instance() or QApplication([]) + w = MainWindow() + w.resize(1400, 800) + w.show() + QTest.qWait(200) + w._results_dock.raise_() + QTest.qWait(200) + yield w + w._persist_layout = False + w.close() + w.deleteLater() + app.processEvents() + + +def test_the_run_tab_behind_results_does_not_cap_the_strip(window): + from PySide6.QtCore import Qt + from PySide6.QtTest import QTest + window._run_dock.fit_height() + assert window._run_dock.maximumHeight() == 16777215 + before = window._results_dock.height() + window.resizeDocks([window._results_dock], [before + 60], Qt.Orientation.Vertical) + QTest.qWait(200) + assert window._results_dock.height() > before + + +def test_maximise_and_restore_the_results(window): + from PySide6.QtTest import QTest + dock = window._results_dock + button = window._dock_chrome_entries[dock]["max_btn"] + assert button.text() == "Maximise" + button.click() + QTest.qWait(200) + assert dock.isFloating() and dock.isMaximized() and button.text() == "Restore" + button.click() + QTest.qWait(200) + assert not dock.isFloating() and button.text() == "Maximise" From e16eef4a3ad9a2f007c58de771d2ab9e5f56d703 Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Fri, 20 Nov 2026 06:50:35 +1000 Subject: [PATCH 2/3] Results back from maximised fit the window Restore and Redock docked the Results while they were still maximised: the dock kept the full screen's height, the window, its status bar and the chart's foot went off screen, and the full-screen size was remembered as the floating size for the next Float. They now leave maximised first (the floating window's own size is remembered), the docked height is asked for once the layout has taken the dock back, and a window stretched past its screen goes back inside it. --- raptor/gui/ui/dock_float_mixin.py | 73 +++++++++++++++---- .../unit/test_charts_target_range_maximise.py | 22 ++++++ 2 files changed, 82 insertions(+), 13 deletions(-) diff --git a/raptor/gui/ui/dock_float_mixin.py b/raptor/gui/ui/dock_float_mixin.py index cd216adb..03c7fb36 100644 --- a/raptor/gui/ui/dock_float_mixin.py +++ b/raptor/gui/ui/dock_float_mixin.py @@ -35,6 +35,7 @@ def _clamp_dock_height(self, target: int) -> int: ... _dock_chrome: dict _dock_resize_generation: int _dock_stubs: dict + def _ensure_status_bar_visible(self) -> Any: ... _inspector_dock: PySide6.QtWidgets.QDockWidget def _release_bottom_strip_ceiling(self) -> None: ... def _resize_docks(self, docks: Any, sizes: Any, orientation: Any) -> None: ... @@ -108,6 +109,8 @@ def _float_results_properly(self, dock: QDockWidget, floating: bool): # topLevelChanged handler; do not remember that as the # docked height. entry["_skip_extent_remember"] = True + if not floating and dock.isFloating(): + self._unmaximise_floating_results(dock) dock.setFloating(floating) if floating: # A floated dock is a frameless tool window: no taskbar entry, @@ -135,25 +138,62 @@ def _float_results_properly(self, dock: QDockWidget, floating: bool): dock.raise_() dock.activateWindow() else: - # Remember where the user left the floating window before - # re-docking, so the next Float restores it. - if dock.geometry().isValid(): - self._results_float_geom = dock.geometry() dock.setWindowState(Qt.WindowState.WindowNoState) dock.setWindowTitle("Results") # its tab's text again dock.raise_() # back in front of its tabbed neighbours # Re-docked: drop the leftover floated geometry, give the # strip a usable height and let the splitter control it # from there (not 50-60% of the screen, not a 260px sliver). - try: - self._update_dock_max_heights() - target = getattr(self, "_results_dock_height_before_float", - None) or 480 - self._resize_docks([dock], - [self._clamp_dock_height(target)], - Qt.Orientation.Vertical) - except Exception: - pass + # Deferred, and asked twice: on the turn of setFloating(False) + # the layout has not taken the dock back and discards the + # request, and a full-screen dock then pushed the window, its + # status bar and the chart's foot off the screen. + target = getattr(self, "_results_dock_height_before_float", None) or 480 + self._settle_docked_results(dock, target) + QTimer.singleShot(0, lambda: self._settle_docked_results(dock, target)) + QTimer.singleShot(120, lambda: self._settle_docked_results(dock, target)) + + def _unmaximise_floating_results(self, dock: QDockWidget) -> None: + """Before the Results go back in the dock: remember the floating + window's own size (not the full screen it was maximised to, which + the next Float would reopen at) and take it out of maximised.""" + full = dock.isMaximized() or dock.isFullScreen() + geometry = dock.normalGeometry() if full else dock.geometry() + if geometry.isValid() and geometry.width() > 200 and geometry.height() > 120: + self._results_float_geom = geometry + if full: + dock.showNormal() + dock.setWindowState(Qt.WindowState.WindowNoState) + + def _fit_window_to_screen(self) -> None: + """A window that a full-screen dock stretched past its screen goes + back inside it (a maximised one is already held to the screen).""" + host = self.window() + if host.isMaximized() or host.isFullScreen(): + return + screen = host.screen() + if screen is None: + return + room = screen.availableGeometry() + frame = host.frameGeometry() + extra = frame.height() - host.height() # the title bar + if frame.height() > room.height() or frame.bottom() > room.bottom(): + host.resize(host.width(), max(200, room.height() - extra)) + host.move(host.x(), max(room.top(), host.y()) if + host.y() + room.height() <= room.bottom() + extra else room.top()) + + def _settle_docked_results(self, dock: QDockWidget, target: int) -> None: + """Size the re-docked Results to `target`, never past what fits.""" + try: + if dock.isFloating(): + return + self._fit_window_to_screen() + self._update_dock_max_heights() + self._resize_docks([dock], [self._clamp_dock_height(int(target))], + Qt.Orientation.Vertical) + self._ensure_status_bar_visible() + except (RuntimeError, AttributeError, TypeError): + pass def _show_dock_back_button(self, dock, entry, show: bool) -> None: """A detached panel gets "back to the dock" instead of collapse. @@ -481,10 +521,17 @@ def _redock(self, dock: QDockWidget) -> None: """Put a floating panel back where it was docked, at its own size.""" entry = ((getattr(self, "_dock_chrome_entries", None) or {}) .get(dock)) or {} + results = dock is getattr(self, "_results_dock", None) + if results and dock.isFloating(): + # docked while still maximised, it kept the full screen's size + self._unmaximise_floating_results(dock) edge = self._current_dock_edge(dock, entry.get("edge")) entry["edge"] = edge dock.setFloating(False) self._restore_dock_extent(dock, entry, edge) + if results: + QTimer.singleShot(0, self._fit_window_to_screen) + QTimer.singleShot(150, self._ensure_status_bar_visible) if dock is getattr(self, "_results_dock", None): dock.setWindowTitle("Results") dock.show() diff --git a/tests/unit/test_charts_target_range_maximise.py b/tests/unit/test_charts_target_range_maximise.py index 8dd1eeca..2136e806 100644 --- a/tests/unit/test_charts_target_range_maximise.py +++ b/tests/unit/test_charts_target_range_maximise.py @@ -89,3 +89,25 @@ def test_maximise_and_restore_the_results(window): button.click() QTest.qWait(200) assert not dock.isFloating() and button.text() == "Maximise" + + +@pytest.mark.parametrize("way", ["restore", "redock"]) +def test_back_from_maximised_fits_the_window(window, way): + """Docked while still maximised, the Results kept their full-screen + size: the window, its status bar and the chart's foot went off screen, + and the next Float reopened full screen.""" + from PySide6.QtTest import QTest + dock = window._results_dock + window._maximise_results() + QTest.qWait(200) + if way == "redock": + window._redock(dock) + else: + window._dock_chrome_entries[dock]["max_btn"].click() + QTest.qWait(400) + assert not dock.isFloating() and not dock.isMaximized() + assert dock.height() <= window._max_bottom_dock_height() + assert window.statusBar().geometry().bottom() <= window.height() + remembered = window._results_float_geom + screen = window.screen().availableGeometry() + assert remembered is not None and remembered.size() != screen.size() From 7aaa7987081279ef61b02a739d2065bdccd376db Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Fri, 20 Nov 2026 07:06:30 +1000 Subject: [PATCH 3/3] Test: pick the Results' Minimise button by name The Results title bar now starts with Maximise, so the first tool button is no longer Minimise. --- tests/unit/test_gui_ux_fixes.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_gui_ux_fixes.py b/tests/unit/test_gui_ux_fixes.py index 4d1416b3..28a93ddb 100644 --- a/tests/unit/test_gui_ux_fixes.py +++ b/tests/unit/test_gui_ux_fixes.py @@ -268,12 +268,11 @@ def test_dock_minimize_bottom_pair_yoked(qapp): tabified into one bottom slot, so the same toggle drives both docks' stubs together.""" from raptor.gui.ui.main_window import MainWindow - from PySide6.QtWidgets import QToolButton w = MainWindow() bottom, tables = w._results_dock, w._data_tables_dock bottom_content, tables_content = bottom.widget(), tables.widget() - min_btn = bottom.titleBarWidget().findChildren(QToolButton)[0] + min_btn = w._dock_chrome_entries[bottom]["min_btn"] # Maximise comes first min_btn.click() assert bottom_content.isHidden() and tables_content.isHidden() @@ -281,7 +280,7 @@ def test_dock_minimize_bottom_pair_yoked(qapp): assert tables.minimumHeight() == tables.maximumHeight() < 100 # restoring via EITHER dock's own titlebar button restores both - tables.titleBarWidget().findChildren(QToolButton)[0].click() + w._dock_chrome_entries[tables]["min_btn"].click() assert not bottom_content.isHidden() and not tables_content.isHidden() # The restore applies the remembered height fixed, then releases the # fix on the next event-loop pass (splitter draggable again) — pump