rL i\$dZddlZddlmZddlmZmZddlZddlm Z ddl m Z ddl m Z mZddlmZddlZGd d e j$e j&ZGd d e Zd ZdZdZdZdZdZdZdZy)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)PurePathPath)nodes) directives)FigureImage)ExtensionErrorc eZdZy) figmplnodeN)__name__ __module__ __qualname__k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/sphinxext/figmpl_directive.pyr r srr c eZdZdZdZdZdZdZejejejeje jejejejdZdZy) 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:: bar 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``):: bar where the subdirectory is included in the image name for uniqueness. F)altheightwidthscalealignclasscaptionsrcsetc4t}|jd}|jjdd|d<|jjdd|d<|jjdd|d<|jjdd|d<|jjdd|d<|jjdd|d<|jjd d|d <||d <|jjd d|d <|gS) Nrrrrrrrrurir)r argumentsoptionsget)self image_nodeimagenms rrunz FigureMpl.runZs\ ..# LL,,UB7 5"ll..w= 7"ll..w= 7"ll..w= 7#||//$? 8"ll..w= 7 $ 0 0D A 9 $ 5#||//$? 8|rN)r rr__doc__ has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer unchangedlength_or_unitless length_or_percentage_or_unitlessnonnegative_intr r class_option option_specr(rrrrr ss(TK %##//<<++((''&& Krrc|jd}i}|D]n}|jjd}t|dk(r |d|d<9t|dk(r|ddd}|d|t|<at d|d |S) z parse srcset... , rrrNzsrcset argument "z " is invalid.)splitstriplenfloatr )stentriesrentrysplmults r_parse_srcsetNodesrAqshhsmG FKkkm!!#& s8q=AF1I X]q6#2;D"%a&F5;  #4UG=!IJ JK Mrc|drt|d}nd}t|jdj}|jj }t ||jddjtjd}t|r|dz }t|jj|jj}t|jdd|rJ|jD]6}t||}||j z} t#j$||| z 8n7t||d}||j z} t#j$||| z |||fS) Nrsource.r -T)parentsexist_okr!)rArdocumentparentbuildersrcdirrreplaceossepr:outdirimagedirrmkdirvaluesnameshutilcopyfile) r%noder docsourcesrctoprelrPsrcabspathrSs r_copy_images_figmplr\sD H~#DN3x0188I\\ F )V $ , ,S" 5 = =bffc JC 3x s  ++T\\-B-BCH N5==? 6Cy#.G%D OOGX_ 5  6 9d5k2W\\!D1 VS  rc t||\}}}t|jd}t|jjd}t ||}t|jj d}||z } tt || jj} |jjdk(rd| } t|dddj} | d|| } | |dd } | }|rid }d}|jD]J\}}t|ddj} | d|| }||z }|d k(r|d z }n |d |ddz }||kDsG|}|}L|dd| d<|dd j|d| d<dD]1}||s d| vr|d||d| d<| dxx|d||dz cc<3|jj|j|d|drd|dnd|jj|j|dd||j|dfi| zd z|d!r|jj|j|d"|jj|j|d#|jj|j|d$d%|jj|d!|jjd&|jjd'y)(NrCr dirhtmlz..r!r/r)rZrr7rz, r6z1.2fzx, rr)rrrstylez: ;figurerzalign-z align-center)CLASSaz"reference internal image-reference)rdhrefimgz r figcaptionpspanz caption-textz

z )r\rrHrJrKrrOrIas_posixrSitemsjoinbodyappendstarttagemptytag)r%rVrPrrYrWrX relsourcedesttopdestimagerelnmr! img_attrsmaxsrcmaxmultsrcsetstr@rZpathras rvisit_figmpl_htmlr|sD/d;Hfcx01Idll))2 .F 6*It||**B/G Y D$++67@@BH ||I%z? $u+ab/ " ' 'B JauRD !CDK0IF  ID##ab'"''BZqbT*D  HqyD aT{#..g~ 'sm ( G}  XXd7m4 '-A ;i'(-wbe Q%? '"'"r$u+a&@@" A" II (.27mF4=/*  QR II dC'K!  # dE/Y/ 0    I t\:; tS12 tV>JK i) 56II]#rc|d9t||\}}d}t|d}t||j|d<|j |y)Nrr7)defaultr!)r\maxrrS visit_figure)r%rVrPrrys rvisit_figmpl_latexrsT H~!.tT:&fb)vg/44U drcyNrr%rVs rdepart_figmpl_htmlr src&|j|yr) depart_figurers rdepart_figmpl_latexrstrc\|jtttftt fy)N)htmllatex)add_noder r|rrr)apps rfigurempl_addnoders(LL(*<=*,?@Brcp|jdtt|ddtjd}|S)Nz figure-mplT)parallel_read_safeparallel_write_safeversion) add_directiverr matplotlib __version__)rmetadatas rsetuprs4lI.c&*4%113H Or)r)rMos.pathrpathlibrrrTdocutilsrdocutils.parsers.rstr&docutils.parsers.rst.directives.imagesrr sphinx.errorsr rGeneralElementr rrAr\r|rrrrrrrrrsx  " +@(   NNb$$!NR$j  B r