
    rbi\$                         d Z ddlZddlmZ ddlmZmZ ddlZddlm	Z	 ddl
mZ ddlmZmZ ddlmZ ddlZ G d	 d
e	j        e	j                  Z G d de          Zd Zd Zd Zd Zd Zd Zd Zd ZdS )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.

    N)relpath)PurePathPath)nodes)
directives)FigureImage)ExtensionErrorc                       e Zd ZdS )
figmplnodeN)__name__
__module____qualname__     u/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/matplotlib/sphinxext/figmpl_directive.pyr   r      s        Dr   r   c            	           e Zd ZdZdZdZdZdZej	        ej
        ej        ej        ej        ej        ej	        ej	        dZd ZdS )	FigureMpla  
    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                 (   t                      }| j        d         }| j                            dd          |d<   | j                            dd           |d<   | j                            dd           |d<   | j                            dd           |d<   | j                            dd           |d<   | j                            dd           |d<   | j                            d	d           |d	<   ||d
<   | j                            dd           |d<   |gS )Nr   r    r   r   r   r   r   r   urir   )r   	argumentsoptionsget)self
image_nodeimagenms      r   runzFigureMpl.runZ   s   \\
.# L,,UB77
5"l..w==
7"l..w==
7"l..w==
7#|//$??
8"l..w==
7 $ 0 0D A A
9 $
5#|//$??
8|r   N)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       s        ( (T K %#/<+('&	 	K    r   r   c                 f   |                      d          }i }|D ]}|                                                     d          }t          |          dk    r|d         |d<   Ht          |          dk    r)|d         dd         }|d         |t          |          <   t	          d| d	          |S )
z
    parse srcset...
    , r   r   r   Nzsrcset argument "z" is invalid.)splitstriplenfloatr
   )stentriesr   entrysplmults         r   _parse_srcsetNodesrA   q   s     hhsmmGF K Kkkmm!!#&&s88q==AF1IIXX]]q6#2#;D"%a&F5;; !IU!I!I!IJJJMr   c                    |d         rt          |d                   }nd }t          | j        d                   j        }| j        j        }t          ||                              dd                              t          j	        d          }t          |          r|dz  }t          | j        j        | j        j                  }t          |                              dd           |rJ|                                D ]4}t          ||          }||j        z   }	t#          j        |||	z             5n8t          ||d                   }||j        z   }	t#          j        |||	z             |||fS )	Nr   source.r    -T)parentsexist_okr!   )rA   r   documentparentbuildersrcdirr   replaceossepr:   outdirimagedirr   mkdirvaluesnameshutilcopyfile)
r%   noder   	docsourcesrctoprelrP   srcabspathrS   s
             r   _copy_images_figmplr\      so    H~ #DN33 x0118I \ F
)V
$
$
,
,S"
5
5
=
=bfc
J
JC
3xx s
 +T\-BCCH 	NN555  	2==?? 	6 	6Cy#..G%DOGX_5555		6 9d5k22W\!D111VS  r   c           	         t          | |          \  }}}t          | j        d                   }t          | j        j        d          }t          ||          }t          | j        j        d          }||z  }	t          t          ||	j                                                            }
| j        j	        dk    rd|
 }
t          |d         dd                    j	        }|
 d| | }||d         d	}|}|rud
}d}|
                                D ]O\  }}t          |dd                    j	        }|
 d| | }||z  }|dk    r|dz  }n
|d|ddz  }||k    r|}|}P|d d         |d<   |d         d                    |d                   |d<   dD ]<}||         r2d|vr| d||          d|d<    |dxx         | d||          dz  cc<   =| j                            |                     |d|d         rd|d          nd                     | j                            |                     |dd|           | j        |dfi |z   d z              |d!         r| j                            |                     |d"                     | j                            |                     |d#                     | j                            |                     |d$d%                     | j                            |d!                    | j                            d&           | j                            d'           d S )(NrC   r    dirhtmlz..r!   r   /r   )rZ   r   r7   r   z, r6   z1.2fzx, r   r   )r   r   r   stylez: ;figurer   zalign-zalign-center)CLASSaz"reference internal image-reference)rd   hrefimgz</a>
r   
figcaptionpspanzcaption-textz</span></p></figcaption>
z
</figure>
)r\   r   rH   rJ   rK   r   rO   rI   as_posixrS   itemsjoinbodyappendstarttagemptytag)r%   rV   rP   r   rY   rW   rX   	relsourcedesttopdestimagerelnmr!   	img_attrsmaxsrcmaxmultsrcsetstr@   rZ   pathra   s                        r   visit_figmpl_htmlr|      s   /d;;Hfc x011I dl)2..F	6**It|*B//GYD $+6677@@BBH|I%%"?? 
$u+abb/	"	"	'B
!
!
!R
!
!CDK00I F , 	 	ID##abb'""'B***b**DHqyyD ......g~~ 'ssm	(G}  XXd7m44	'- A A; 	Ai''(-%?%?e%?%?%?	'""'"""&@&@$u+&@&@&@@""" 	I(.27mO*4=*** 	 	Q 	QR R R 	IdC'K! 	 	# 	#dE//Y//	0 		  
 I 7	t\::;;;	tS11222	tV>JJKKK	i)))	5666I]#####r   c                     |d         Ct          | |          \  }}d}t          |d          }t          ||                   j        |d<   |                     |           d S )Nr   r7   )defaultr!   )r\   maxr   rS   visit_figure)r%   rV   rP   r   ry   s        r   visit_figmpl_latexr      si    H~!.tT::&fb)))vg//4Udr   c                     d S Nr   r%   rV   s     r   depart_figmpl_htmlr     s    Dr   c                 0    |                      |           d S r   )depart_figurer   s     r   depart_figmpl_latexr     s    tr   c                 p    |                      t          t          t          ft          t
          f           d S )N)htmllatex)add_noder   r|   r   r   r   )apps    r   figurempl_addnoder     s@    LL(*<=*,?@  B B B B Br   c                 z    |                      dt                     t          |            ddt          j        d}|S )Nz
figure-mplT)parallel_read_safeparallel_write_safeversion)add_directiver   r   
matplotlib__version__)r   metadatas     r   setupr     sB    lI...c&*4%13 3HOr   )r)   rM   os.pathr   pathlibr   r   rT   docutilsr   docutils.parsers.rstr   &docutils.parsers.rst.directives.imagesr   r	   sphinx.errorsr
   r   GeneralElementr   r   rA   r\   r|   r   r   r   r   r   r   r   r   <module>r      s    
			       " " " " " " " "        + + + + + + @ @ @ @ @ @ @ @ ( ( ( ( ( (    	 	 	 	 	 	 	 	N N N N N N N Nb  $$! $! $!NR$ R$ R$j	 	 		 	 	  B B B    r   