
    h#                         S r SSKJr  SSKJr  SSKJrJr  SSKrSSK	J
r
  SSKJrJr  SSKrSSKJr  SSKr " S	 S
\R$                  \R&                  5      r " S S\5      rS rS rS rS rS rS rS rS rg)a   
Add a ``figure-mpl`` directive that is a responsive version of ``figure``.

This implementation is very similar to ``.. figure::``, except it also allows a
``srcset=`` argument to be passed to the image tag, hence allowing responsive
resolution images.

There is no particular reason this could not be used standalone, but is meant
to be used with :doc:`/api/sphinxext_plot_directive_api`.

Note that the directory organization is a bit different than ``.. figure::``.
See the *FigureMpl* documentation below.

    )nodes)
directives)FigureImageN)relpath)PurePathPath)ExtensionErrorc                       \ rS rSrSrg)
figmplnode    N)__name__
__module____qualname____firstlineno____static_attributes__r       W/var/www/html/env/lib/python3.13/site-packages/matplotlib/sphinxext/figmpl_directive.pyr   r      s    r   r   c            	           \ rS rSrSrSrSrSrSr\	R                  \	R                  \	R                  \	R                  \R                  \	R                   \	R                  \	R                  S.rS rSrg	)
	FigureMpl"   a&  
Implements a directive to allow an optional hidpi image.

Meant to be used with the *plot_srcset* configuration option in conf.py,
and gets set in the TEMPLATE of plot_directive.py

e.g.::

    .. figure-mpl:: plot_directive/some_plots-1.png
        :alt: bar
        :srcset: plot_directive/some_plots-1.png,
                 plot_directive/some_plots-1.2x.png 2.00x
        :class: plot-directive

The resulting html (at ``some_plots.html``) is::

    <img src="sphx_glr_bar_001_hidpi.png"
        srcset="_images/some_plot-1.png,
                _images/some_plots-1.2x.png 2.00x",
        alt="bar"
        class="plot_directive" />

Note that the handling of subdirectories is different than that used by the sphinx
figure directive::

    .. figure-mpl:: plot_directive/nestedpage/index-1.png
        :alt: bar
        :srcset: plot_directive/nestedpage/index-1.png
                 plot_directive/nestedpage/index-1.2x.png 2.00x
        :class: plot_directive

The resulting html (at ``nestedpage/index.html``)::

    <img src="../_images/nestedpage-index-1.png"
        srcset="../_images/nestedpage-index-1.png,
                ../_images/_images/nestedpage-index-1.2x.png 2.00x",
        alt="bar"
        class="sphx-glr-single-img" />

where the subdirectory is included in the image name for uniqueness.
F      )altheightwidthscalealignclasscaptionsrcsetc                 2   [        5       nU R                  S   nU R                  R                  SS5      US'   U R                  R                  SS 5      US'   U R                  R                  SS 5      US'   U R                  R                  SS 5      US'   U R                  R                  SS 5      US'   U R                  R                  SS 5      US'   U R                  R                  S	S 5      US	'   X!S
'   U R                  R                  SS 5      US'   U/$ )Nr   r    r   r    r   r   r   r!   urir"   )r   	argumentsoptionsget)self
image_nodeimagenms      r   runFigureMpl.run\   s   \
..# LL,,UB7
5"ll..w=
7"ll..w=
7"ll..w=
7#||//$?
8"ll..w=
7 $ 0 0D A
9 $5#||//$?
8|r   r   N)r   r   r   r   __doc__has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   	unchangedlength_or_unitless length_or_percentage_or_unitlessnonnegative_intr   r   class_optionoption_specr,   r   r   r   r   r   r   "   ss    (T K %##//<<++((''&&	Kr   r   c                    U R                  S5      n0 nU Hr  nUR                  5       R                  S5      n[        U5      S:X  a
  US   US'   M;  [        U5      S:X  a  US   SS nUS   U[        U5      '   Me  [	        SU S	35      e   U$ )
z
parse srcset...
, r   r   r   Nzsrcset argument "z" is invalid.)splitstriplenfloatr
   )stentriesr"   entrysplmults         r   _parse_srcsetNodesrF   s   s     hhsmGFkkm!!#&s8q=AF1IX]q6#2;D"%a&F5; #4UG=!IJJ  Mr   c                    US   (       a  [        US   5      nOS n[        U R                  S   5      R                  nU R                  R
                  n[        X45      R                  SS5      R                  [        R                  S5      n[        U5      (       a  US-  n[        U R                  R                  U R                  R                  5      n[        U5      R                  SSS9  U(       aJ  UR                  5        H5  n[        X75      nXXR                   -   n	["        R$                  " XU	-  5        M7     O5[        X1S   5      nXXR                   -   n	["        R$                  " XU	-  5        XbU4$ )	Nr"   source.r$   -T)parentsexist_okr%   )rF   r   documentparentbuildersrcdirr   replaceossepr?   outdirimagedirr	   mkdirvaluesnameshutilcopyfile)
r)   noder"   	docsourcesrctoprelrU   srcabspathrX   s
             r   _copy_images_figmplra      s1    H~#DN3 x0188I \\  F
)
$
,
,S"
5
=
=bffc
JC
3xxs
 ++T\\-B-BCH 	N5 ==?Cy.G%DOOG_5	 # 95k2\\!D1S  r   c                 L   [        X5      u  p#n[        U R                  S   5      n[        U R                  R                  S5      n[        XV5      n[        U R                  R                  S5      nX-  n	[        [        X)R                  5      5      R                  5       n
U R                  R                  S:X  a  SU
 3n
[        US   SS  5      R                  nU
 SU U 3nUnSnU(       ai  SnUR                  5        HN  u  nn[        USS  5      R                  nU
 SU U 3nUU-  nUS	:X  a  US
-  nO
USUS S3-  nUU:  d  MJ  UnUnMP     US S nUS   nUS   b  SR                  US   5      nSU S3nOSn/ SQnSnU H  nUU   (       d  M  UU SUU    S3-  nM     US   (       a  US   OSnSU SU SU SU SU S3nSU S3nUS U S3-  nUS!U S"3-  nUS#   (       a  US$-  nUS%US#    S&3-  nUS'-  nUS(-  nU R                  R                  U5        g ))NrH   r$   dirhtmlz..r%   r   /r<   r   z, r;   z1.2fzx, r   r    zclass="")r   r   r   z: ;r   centerz
<img src="z	" style="z
" srcset="z" alt="z" z/>z<figure class="align-z">
z6  <a class="reference internal image-reference" href="z    z
  </a>
r!   z  <figcaption>
z!   <p><span class="caption-text">z</span></p>
z  </figcaption>
z
</figure>
)ra   r   rM   rO   rP   r   rT   rN   as_posixrX   itemsjoinbodyappend)r)   r[   rU   r"   r^   r\   r]   	relsourcedesttopdestimagerelnmr%   maxsrcsrcsetstmaxmultrE   r_   pathr   classststylersstyleststylefigalign	img_block
html_blocks                              r   visit_figmpl_htmlr~      s   /;Hc x01I dll))2.F	*It||**B/GD ++67@@BH||I%z? 
$u+ab/	"	'	'BJauRD
!C FHID##ab'"''BZqbT*DHqyD aT{#..g~ ( CR=
u+CG} ((4=)G9A& *GG;;%4;-q11G  !%WtG}8H cU)G9Jxj IRy,I(
$7JJ6(RVWWJD:..JI((
9$y/9J-XX
))
-JIIZ r   c                     US   b3  [        X5      u  p#Sn[        USS9n[        X4   5      R                  US'   U R	                  U5        g )Nr"   r<   )defaultr%   )ra   maxr   rX   visit_figure)r)   r[   rU   r"   ru   s        r   visit_figmpl_latexr     sN    H~!.t:fb)v/44Udr   c                     g Nr   r)   r[   s     r   depart_figmpl_htmlr     s    r   c                 &    U R                  U5        g r   )depart_figurer   s     r   depart_figmpl_latexr     s    tr   c                 V    U R                  [        [        [        4[        [
        4S9  g )N)htmllatex)add_noder   r~   r   r   r   )apps    r   figurempl_addnoder     s(    LL(*<=*,?@  Br   c                 p    U R                  S[        5        [        U 5        SS[        R                  S.nU$ )Nz
figure-mplT)parallel_read_safeparallel_write_safeversion)add_directiver   r   
matplotlib__version__)r   metadatas     r   setupr     s4    lI.c&*4%113HOr   )r.   docutilsr   docutils.parsers.rstr   &docutils.parsers.rst.directives.imagesr   r   rR   os.pathr   pathlibr   r	   rY   sphinx.errorsr
   r   GeneralElementr   r   rF   ra   r~   r   r   r   r   r   r   r   r   <module>r      sx     + @ 	  "  ( 	 	N Nb$$!NR!j		Br   