Skip to content

Commit 4bd2378

Browse files
committed
Rename _equalize to _align and simplify call sites
1 parent ab89df5 commit 4bd2378

1 file changed

Lines changed: 24 additions & 54 deletions

File tree

plotnine/_mpl/layout_manager/_layout_tree.py

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -512,53 +512,27 @@ def align_panels(self):
512512
"""
513513
Align the edges of the panels in the composition
514514
"""
515-
_equalize(
516-
self.bottom_spaces,
517-
lambda s: s.panel_bottom,
518-
"margin_alignment",
519-
)
520-
_equalize(
521-
self.top_spaces,
522-
lambda s: s.panel_top,
523-
"margin_alignment",
524-
how="min",
525-
)
526-
_equalize(
527-
self.left_spaces,
528-
lambda s: s.panel_left,
529-
"margin_alignment",
530-
)
531-
_equalize(
532-
self.right_spaces,
533-
lambda s: s.panel_right,
534-
"margin_alignment",
535-
how="min",
536-
)
515+
align_args = [
516+
(self.bottom_spaces, lambda s: s.panel_bottom, "max"),
517+
(self.top_spaces, lambda s: s.panel_top, "min"),
518+
(self.left_spaces, lambda s: s.panel_left, "max"),
519+
(self.right_spaces, lambda s: s.panel_right, "min"),
520+
]
521+
for spaces, measure, how in align_args:
522+
_align(spaces, measure, "margin_alignment", how)
537523

538524
def align_tags(self):
539525
"""
540526
Align the tags in the composition
541527
"""
542-
_equalize(
543-
self.bottom_spaces,
544-
lambda s: s.tag_height + s.tag_alignment,
545-
"tag_alignment",
546-
)
547-
_equalize(
548-
self.top_spaces,
549-
lambda s: s.tag_height + s.tag_alignment,
550-
"tag_alignment",
551-
)
552-
_equalize(
553-
self.left_spaces,
554-
lambda s: s.tag_width + s.tag_alignment,
555-
"tag_alignment",
556-
)
557-
_equalize(
558-
self.right_spaces,
559-
lambda s: s.tag_width + s.tag_alignment,
560-
"tag_alignment",
561-
)
528+
align_args = [
529+
(self.bottom_spaces, lambda s: s.tag_height + s.tag_alignment),
530+
(self.top_spaces, lambda s: s.tag_height + s.tag_alignment),
531+
(self.left_spaces, lambda s: s.tag_width + s.tag_alignment),
532+
(self.right_spaces, lambda s: s.tag_width + s.tag_alignment),
533+
]
534+
for spaces, measure in align_args:
535+
_align(spaces, measure, "tag_alignment")
562536

563537
def align_axis_titles(self):
564538
"""
@@ -572,16 +546,12 @@ def align_axis_titles(self):
572546
to store the value outside the _side_space and pick it up when
573547
setting the position of the texts!
574548
"""
575-
_equalize(
576-
self.bottom_spaces,
577-
lambda s: s.axis_title_clearance,
578-
"axis_title_alignment",
579-
)
580-
_equalize(
581-
self.left_spaces,
582-
lambda s: s.axis_title_clearance,
583-
"axis_title_alignment",
584-
)
549+
550+
def axis_title_clearance(s):
551+
return s.axis_title_clearance
552+
553+
for spaces in [self.bottom_spaces, self.left_spaces]:
554+
_align(spaces, axis_title_clearance, "axis_title_alignment")
585555

586556
for tree in self.sub_compositions:
587557
tree.align_axis_titles()
@@ -612,14 +582,14 @@ def resize_heights(self):
612582
self.sub_gridspec.set_height_ratios(height_ratios)
613583

614584

615-
def _equalize(
585+
def _align(
616586
spaces_iter: Iterator[Sequence[Any]],
617587
measure: Callable[[Any], float],
618588
attr: str,
619589
how: Literal["max", "min"] = "max",
620590
):
621591
"""
622-
Equalize a measurement across spaces by adjusting an attribute
592+
Align spaces by adjusting an attribute
623593
624594
For each group of spaces yielded by the iterator, find the extreme
625595
value (max or min) of the measurement, then add the difference to

0 commit comments

Comments
 (0)