MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _get_aligned_offsets

Function _get_aligned_offsets

lib/matplotlib/offsetbox.py:151–199  ·  view source on GitHub ↗

Align boxes each specified by their ``(y0, y1)`` spans. For simplicity of the description, the terminology used here assumes a horizontal layout (i.e., vertical alignment), but the function works equally for a vertical layout. Parameters ---------- yspans List

(yspans, height, align="baseline")

Source from the content-addressed store, hash-verified

149
150
151def _get_aligned_offsets(yspans, height, align="baseline"):
152 """
153 Align boxes each specified by their ``(y0, y1)`` spans.
154
155 For simplicity of the description, the terminology used here assumes a
156 horizontal layout (i.e., vertical alignment), but the function works
157 equally for a vertical layout.
158
159 Parameters
160 ----------
161 yspans
162 List of (y0, y1) spans of boxes to be aligned.
163 height : float or None
164 Intended total height. If None, the maximum of the heights
165 (``y1 - y0``) in *yspans* is used.
166 align : {'baseline', 'left', 'top', 'right', 'bottom', 'center'}
167 The alignment anchor of the boxes.
168
169 Returns
170 -------
171 (y0, y1)
172 y range spanned by the packing. If a *height* was originally passed
173 in, then for all alignments other than "baseline", a span of ``(0,
174 height)`` is used without checking that it is actually large enough).
175 descent
176 The descent of the packing.
177 offsets
178 The bottom offsets of the boxes.
179 """
180
181 _api.check_in_list(
182 ["baseline", "left", "top", "right", "bottom", "center"], align=align)
183 if height is None:
184 height = max(y1 - y0 for y0, y1 in yspans)
185
186 if align == "baseline":
187 yspan = (min(y0 for y0, y1 in yspans), max(y1 for y0, y1 in yspans))
188 offsets = [0] * len(yspans)
189 elif align in ["left", "bottom"]:
190 yspan = (0, height)
191 offsets = [-y0 for y0, y1 in yspans]
192 elif align in ["right", "top"]:
193 yspan = (0, height)
194 offsets = [height - y1 for y0, y1 in yspans]
195 elif align == "center":
196 yspan = (0, height)
197 offsets = [(height - (y1 - y0)) * .5 - y0 for y0, y1 in yspans]
198
199 return yspan, offsets
200
201
202class OffsetBox(martist.Artist):

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…