|
13 | 13 | from plotnine._utils.yippie import geom as g |
14 | 14 | from plotnine._utils.yippie import plot |
15 | 15 | from plotnine.composition import inset_element, plot_annotation |
| 16 | +from plotnine.exceptions import PlotnineWarning |
16 | 17 |
|
17 | 18 |
|
18 | 19 | def _smiley() -> np.ndarray: |
@@ -374,3 +375,39 @@ def test_inset_on_facet_host(): |
374 | 375 | + inset_element(plot.tomato, 0, 0, 0.25, 0.25) |
375 | 376 | ) |
376 | 377 | assert p == "inset_on_facet_host" |
| 378 | + |
| 379 | + |
| 380 | +class TestFooterInset: |
| 381 | + """ |
| 382 | + align_to="footer" maps the inset bbox onto the footer band |
| 383 | + """ |
| 384 | + |
| 385 | + def test_footer_logo_right_aligned(self): |
| 386 | + # A logo placed in the right portion of the footer band, inline |
| 387 | + # with left-justified footer text. |
| 388 | + p = ( |
| 389 | + plot.white |
| 390 | + + g.points |
| 391 | + + labs(footer="Source: Example Corp") |
| 392 | + + inset_element( |
| 393 | + SMILEY_FACE, |
| 394 | + left=0.9, |
| 395 | + bottom=0.0, |
| 396 | + right=1.0, |
| 397 | + top=1.0, |
| 398 | + align_to="footer", |
| 399 | + ) |
| 400 | + ) |
| 401 | + assert p == "footer_logo_right_aligned" |
| 402 | + |
| 403 | + def test_footer_inset_without_footer_text(self): |
| 404 | + # No footer text -> degenerate footer band. The inset is skipped |
| 405 | + # and a warning is emitted; the rendered plot is just the host. |
| 406 | + # The == comparison draws the plot, which triggers the warning. |
| 407 | + p = ( |
| 408 | + plot.white |
| 409 | + + g.points |
| 410 | + + inset_element(SMILEY_FACE, 0.9, 0.0, 1.0, 1.0, align_to="footer") |
| 411 | + ) |
| 412 | + with pytest.warns(PlotnineWarning, match="no footer text"): |
| 413 | + assert p == "footer_inset_no_footer_text" |
0 commit comments