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

Function test_packers

lib/matplotlib/tests/test_offsetbox.py:335–379  ·  view source on GitHub ↗
(align)

Source from the content-addressed store, hash-verified

333@pytest.mark.parametrize("align", ["baseline", "bottom", "top",
334 "left", "right", "center"])
335def test_packers(align):
336 # set the DPI to match points to make the math easier below
337 fig = plt.figure(dpi=72)
338 renderer = fig.canvas.get_renderer()
339
340 x1, y1 = 10, 30
341 x2, y2 = 20, 60
342 r1 = DrawingArea(x1, y1)
343 r2 = DrawingArea(x2, y2)
344
345 # HPacker
346 hpacker = HPacker(children=[r1, r2], align=align)
347 hpacker.draw(renderer)
348 bbox = hpacker.get_bbox(renderer)
349 px, py = hpacker.get_offset(bbox, renderer)
350 # width, height, xdescent, ydescent
351 assert_allclose(bbox.bounds, (0, 0, x1 + x2, max(y1, y2)))
352 # internal element placement
353 if align in ("baseline", "left", "bottom"):
354 y_height = 0
355 elif align in ("right", "top"):
356 y_height = y2 - y1
357 elif align == "center":
358 y_height = (y2 - y1) / 2
359 # x-offsets, y-offsets
360 assert_allclose([child.get_offset() for child in hpacker.get_children()],
361 [(px, py + y_height), (px + x1, py)])
362
363 # VPacker
364 vpacker = VPacker(children=[r1, r2], align=align)
365 vpacker.draw(renderer)
366 bbox = vpacker.get_bbox(renderer)
367 px, py = vpacker.get_offset(bbox, renderer)
368 # width, height, xdescent, ydescent
369 assert_allclose(bbox.bounds, (0, -max(y1, y2), max(x1, x2), y1 + y2))
370 # internal element placement
371 if align in ("baseline", "left", "bottom"):
372 x_height = 0
373 elif align in ("right", "top"):
374 x_height = x2 - x1
375 elif align == "center":
376 x_height = (x2 - x1) / 2
377 # x-offsets, y-offsets
378 assert_allclose([child.get_offset() for child in vpacker.get_children()],
379 [(px + x_height, py), (px, py - y2)])
380
381
382def test_paddedbox_default_values():

Callers

nothing calls this directly

Calls 9

DrawingAreaClass · 0.90
HPackerClass · 0.90
VPackerClass · 0.90
figureMethod · 0.80
get_rendererMethod · 0.45
drawMethod · 0.45
get_bboxMethod · 0.45
get_offsetMethod · 0.45
get_childrenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…