From efc98bdf4cb6e8e3dc5515c01540dffa5d0aae8b Mon Sep 17 00:00:00 2001 From: goodboy Date: Wed, 18 Mar 2026 15:08:24 -0400 Subject: [PATCH] Gate `size_to_values()` on macOS in `_axes.py` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NOTE, this reversion was discovered as needed by @goodboy after extensively manually testing the new zoom-by-font-size feats introduced alongside macOS support. Use class-body `if _friggin_macos:` branching to conditionally define `size_to_values()` for both `PriceAxis` and `DynamicDateAxis` — macOS gets the new `_updateWidth()`/`_updateHeight()` + geometry recalc path, other platforms fall back to the original `setWidth()`/`setHeight()` calls. Deats, - add `platform` import and module-level `_friggin_macos: bool` flag. - `PriceAxis.size_to_values()`: macOS branch calls `_updateWidth()` + `updateGeometry()`; else branch uses `self.setWidth(self.typical_br.width())`. - `DynamicDateAxis.size_to_values()`: macOS branch calls `_updateHeight()` + `updateGeometry()`; else uses `self.setHeight(self.typical_br.height() + 1)`. - reorder imports: `platform` before `typing`. (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- piker/ui/_axes.py | 54 ++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/piker/ui/_axes.py b/piker/ui/_axes.py index a4ae601b..1dac898c 100644 --- a/piker/ui/_axes.py +++ b/piker/ui/_axes.py @@ -20,8 +20,9 @@ Chart axes graphics and behavior. """ from __future__ import annotations from functools import lru_cache -from typing import Callable from math import floor +import platform +from typing import Callable import polars as pl import pyqtgraph as pg @@ -42,6 +43,7 @@ from ._style import DpiAwareFont, hcolor, _font from ._interaction import ChartView from ._dataviz import Viz +_friggin_macos: bool = platform.system() == 'Darwin' _axis_pen = pg.mkPen(hcolor('bracket')) @@ -172,6 +174,7 @@ class Axis(pg.AxisItem): text_offset = None if self.orientation in ('bottom',): text_offset = floor(0.25 * font_size) + elif self.orientation in ('left', 'right'): text_offset = floor(font_size / 2) @@ -293,15 +296,22 @@ class PriceAxis(Axis): ) -> None: self._min_tick = size - def size_to_values(self) -> None: - # Call PyQtGraph's internal width update mechanism - # This respects autoExpandTextSpace and updates min/max constraints - self._updateWidth() - # tell Qt our preferred size changed so layout recalculates - self.updateGeometry() - # force parent plot item to recalculate its layout - if self.pi and hasattr(self.pi, 'updateGeometry'): - self.pi.updateGeometry() + if _friggin_macos: + def size_to_values(self) -> None: + # Call PyQtGraph's internal width update mechanism + # This respects autoExpandTextSpace and updates min/max constraints + self._updateWidth() + # tell Qt our preferred size changed so layout recalculates + self.updateGeometry() + # force parent plot item to recalculate its layout + if self.pi and hasattr(self.pi, 'updateGeometry'): + self.pi.updateGeometry() + + else: + def size_to_values(self) -> None: + # XXX, old code! + self.setWidth(self.typical_br.width()) + # XXX: drop for now since it just eats up h space @@ -344,15 +354,21 @@ class DynamicDateAxis(Axis): 1: '%H:%M:%S', } - def size_to_values(self) -> None: - # Call PyQtGraph's internal height update mechanism - # This respects autoExpandTextSpace and updates min/max constraints - self._updateHeight() - # tell Qt our preferred size changed so layout recalculates - self.updateGeometry() - # force parent plot item to recalculate its layout - if self.pi and hasattr(self.pi, 'updateGeometry'): - self.pi.updateGeometry() + if _friggin_macos: + def size_to_values(self) -> None: + # Call PyQtGraph's internal height update mechanism + # This respects autoExpandTextSpace and updates min/max constraints + self._updateHeight() + # tell Qt our preferred size changed so layout recalculates + self.updateGeometry() + # force parent plot item to recalculate its layout + if self.pi and hasattr(self.pi, 'updateGeometry'): + self.pi.updateGeometry() + + else: + def size_to_values(self) -> None: + # XXX, old code! + self.setHeight(self.typical_br.height() + 1) def _indexes_to_timestrs( self,