Skip to content

Commit 3f63b24

Browse files
committed
refactor(layout): compute axis band per-side, drop 'moved axis'
1 parent db40240 commit 3f63b24

1 file changed

Lines changed: 12 additions & 27 deletions

File tree

plotnine/_mpl/layout_manager/_plot_side_space.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,20 @@ def axis_title_clearance(self) -> float:
143143
raise PlotnineError("Side has no axis title") from err
144144

145145
@property
146-
def _axis_primary_extent(self) -> float:
146+
def _axis_ticks_and_text(self) -> float:
147147
"""
148-
Outward extent of a moved axis's ticks and tick labels, figure space
148+
Outward extent of this side's axis ticks and tick labels, figure space
149149
150-
This is the part of a moved axis that sits next to the panel; the
151-
axis title is excluded. Zero on sides whose axis is in its default
152-
position.
150+
The axis title is excluded. Computed from the items present on the
151+
side, identically for all four sides; zero on a side with no axis.
153152
"""
154-
return 0
155-
156-
# Typed default so strip_band_offset type-checks; concrete sides redeclare.
157-
strip_text: float = 0
153+
return self.sum_incl("axis_ticks") - self.sum_upto("axis_text")
158154

159155
def strip_band_offset(self, member: Literal["strip", "axis"]) -> float:
160156
"""
161157
Outward offset for one member of a shared strip/axis band
162158
163-
When a moved axis and a facet strip occupy the same side, the band is
159+
When a facet strip and an axis occupy the same side, the band is
164160
ordered from the panel outward. `strip_placement` chooses the order:
165161
166162
"inside": panel | strip | ticks+labels | title
@@ -171,20 +167,17 @@ def strip_band_offset(self, member: Literal["strip", "axis"]) -> float:
171167
consumed per artist in its own coordinate system: the title in figure
172168
space, the tick labels in axes fractions, the spine in points.
173169
174-
The offset is zero unless the side has both a strip and a moved axis.
175-
Bottom/left sides leave `_axis_primary_extent` at zero (a strip there
176-
would share the side with the *default* axis, which the facet API does
177-
not yet expose), so this returns zero for them.
170+
The offset is zero unless the side carries both a strip and an axis.
178171
"""
179-
strip = self.strip_text
180-
primary = self._axis_primary_extent
181-
if not (strip and primary):
172+
strip_breadth: float = self.strip_text # pyright: ignore[reportAttributeAccessIssue]
173+
axis_breadth = self._axis_ticks_and_text
174+
if not (strip_breadth and axis_breadth):
182175
return 0
183176
placement = self.items.plot.theme.getp("strip_placement")
184177
if placement == "inside":
185-
return 0 if member == "strip" else strip
178+
return 0 if member == "strip" else strip_breadth
186179
# "outside"
187-
return primary if member == "strip" else 0
180+
return axis_breadth if member == "strip" else 0
188181

189182

190183
class left_space(_plot_side_space):
@@ -435,10 +428,6 @@ def _calculate(self):
435428
if adjustment > 0:
436429
self.plot_margin += adjustment
437430

438-
@property
439-
def _axis_primary_extent(self) -> float:
440-
return self.sum_incl("axis_ticks") - self.sum_upto("axis_text")
441-
442431
@property
443432
def axis_title_clearance(self) -> float:
444433
"""
@@ -600,10 +589,6 @@ def _calculate(self):
600589
if adjustment > 0:
601590
self.plot_margin += adjustment
602591

603-
@property
604-
def _axis_primary_extent(self) -> float:
605-
return self.sum_incl("axis_ticks") - self.sum_upto("axis_text")
606-
607592
@property
608593
def axis_title_clearance(self) -> float:
609594
"""

0 commit comments

Comments
 (0)