Ë
    {�hé.  ã                   óZ   — d Z ddlZddlZddlmZ ddlZddlmZ ddlmZ  G d„ de	«      Z
y)	z•
Matplotlib Exporter
===================
This submodule contains tools for crawling a matplotlib figure and exporting
relevant pieces to a renderer.
é    Né   )Úutils)Ú
transforms)ÚFigureCanvasAggc                   ól   — e Zd ZdZdd„Zd„ Ze	 dd„«       Zd„ Zd„ Z	d„ Z
dd	„Zdd
„Zdd„Z	 dd„Zd„ Zy)ÚExporteraý  Matplotlib Exporter

    Parameters
    ----------
    renderer : Renderer object
        The renderer object called by the exporter to create a figure
        visualization.  See mplexporter.Renderer for information on the
        methods which should be defined within the renderer.
    close_mpl : bool
        If True (default), close the matplotlib figure as it is rendered. This
        is useful for when the exporter is used within the notebook, or with
        an interactive matplotlib backend.
    c                 ó    — || _         || _        y ©N)Ú	close_mplÚrenderer)Úselfr   r   s      úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/plotly/matplotlylib/mplexporter/exporter.pyÚ__init__zExporter.__init__   s   € Ø"ˆŒØ ˆ�ó    c                 óú   — |j                   €t        |«      }|j                  t        j                  «       d|j
                  ¬«       | j                  rddlm} |j                  |«       | j                  |«       y)z¥
        Run the exporter on the given figure

        Parmeters
        ---------
        fig : matplotlib.Figure instance
            The figure to export
        NÚpng)ÚformatÚdpir   )Úcanvasr   ÚsavefigÚioÚBytesIOr   r   Úmatplotlib.pyplotÚpyplotÚcloseÚ	crawl_fig)r   Úfigr   Úplts       r   ÚrunzExporter.run#   sU   € ð �:‰:ÐÜ$ SÓ)ˆFØ�‰”B—J‘J“L¨°C·G±GˆÔ<Ø�>Š>Ý+à�I‰I�cŒNØ�‰�sÕr   Nc                 óÖ  — t        | t        j                  «      rt        j                  d«       |�|�| |z
  j                  |«      }|} d}|�jd|j                  fd|j                  fd|j                  j                  fdt        j                  «       ffD ]  \  }}| j                  |«      sŒ|| |z
  } } n |�)|r|| j                  |«      | fS || j                  |«      fS |r|| fS |S )a?  Process the transform and convert data to figure or data coordinates

        Parameters
        ----------
        transform : matplotlib Transform object
            The transform applied to the data
        ax : matplotlib Axes object (optional)
            The axes the data is associated with
        data : ndarray (optional)
            The array of data to be transformed.
        return_trans : bool (optional)
            If true, return the final transform of the data
        force_trans : matplotlib.transform instance (optional)
            If supplied, first force the data to this transform

        Returns
        -------
        code : string
            Code is either "data", "axes", "figure", or "display", indicating
            the type of coordinates output.
        transform : matplotlib transform
            the transform used to map input data to output data.
            Returned only if return_trans is True
        new_data : ndarray
            Data transformed to match the given coordinate code.
            Returned only if data is specified
        zMBlended transforms not yet supported. Zoom behavior may not work as expected.ÚdisplayÚdataÚaxesÚfigure)Ú
isinstancer   ÚBlendedGenericTransformÚwarningsÚwarnÚ	transformÚ	transDataÚ	transAxesr$   ÚtransFigureÚIdentityTransformÚcontains_branch)r)   Úaxr"   Úreturn_transÚforce_transÚcodeÚcÚtranss           r   Úprocess_transformzExporter.process_transform7   s  € ô> �i¤×!CÑ!CÔDÜ�M‰Mð:ôð
 Ð"ØÐØ! KÑ/×:Ñ:¸4Ó@�Ø#ˆIàˆØˆ>à˜Ÿ™Ð&Ø˜Ÿ™Ð&Ø˜2Ÿ9™9×0Ñ0Ð1ØœJ×8Ñ8Ó:Ð;ð	ò ‘��5ð ×,Ñ,¨UÕ3Ø'(¨)°eÑ*;˜)�DÙðð ÐÙØ˜Y×0Ñ0°Ó6¸	ÐAÐAà˜Y×0Ñ0°Ó6Ð6Ð6áØ˜Y�Ð&à�r   c                 óÔ   — | j                   j                  |t        j                  |«      ¬«      5  |j                  D ]  }| j                  |«       Œ 	 ddd«       y# 1 sw Y   yxY w)z%Crawl the figure and process all axes)r   ÚpropsN)r   Údraw_figurer   Úget_figure_propertiesr#   Úcrawl_ax)r   r   r/   s      r   r   zExporter.crawl_figx   sY   € à�]‰]×&Ñ&¨3´e×6QÑ6QÐRUÓ6VÐ&ÓWñ 	"Ø—h‘hò "�Ø—‘˜bÕ!ñ"÷	"÷ 	"ñ 	"ús   ±#AÁA'c                 ón  — | j                   j                  |t        j                  |«      ¬«      5  |j                  D ]  }| j                  ||«       Œ |j                  D ]  }| j                  ||«       Œ t        |j                  j                  |j                  j                  |j                  gg d¢«      D ]B  \  }}t        |d«      sŒ|j                  «       sŒ$| j                  |||j                  |¬«       ŒD |j                   D ]9  }t#        |t$        j&                  j(                  «      sŒ(| j                  ||«       Œ; |j*                  D ]  }| j-                  ||«       Œ |j.                  D ]  }| j1                  ||«       Œ |j2                  D ]  }| j5                  ||«       Œ |j7                  «       }	|	�St        j8                  ||	«      }
| j                   j;                  |	|
¬«      5  |
d   r| j=                  ||	«       ddd«       ddd«       y# 1 sw Y   ŒxY w# 1 sw Y   yxY w)z.Crawl the axes and process all elements within)r/   r7   )ÚxlabelÚylabelÚtitleÚget_text)r1   Ú	text_typeN)Úlegendr7   Úvisible)r   Ú	draw_axesr   Úget_axes_propertiesÚlinesÚ	draw_lineÚtextsÚ	draw_textÚzipÚxaxisÚlabelÚyaxisr>   Úhasattrr?   r+   Úartistsr%   Ú
matplotlibÚtextÚTextÚpatchesÚ
draw_patchÚcollectionsÚdraw_collectionÚimagesÚ
draw_imageÚ
get_legendÚget_legend_propertiesÚdraw_legendÚcrawl_legend)r   r/   ÚlinerP   ÚttpÚartistÚpatchÚ
collectionÚimagerA   r7   s              r   r:   zExporter.crawl_ax~   sï  € à�]‰]×$Ñ$¨´%×2KÑ2KÈBÓ2OÐ$ÓPñ 	6ØŸ™ò )�Ø—‘˜r 4Õ(ð)àŸ™ò )�Ø—‘˜r 4Õ(ð)ä Ø—‘—‘ §¡§¡°·±Ð:Ú-óò V‘	��cô ˜4 Õ,°·±µØ—N‘N 2 t¸¿¹ÐQT�NÕUðVð Ÿ*™*ò /�ä˜f¤j§o¡o×&:Ñ&:Õ;Ø—N‘N 2 vÕ.ð/ð Ÿ™ò +�Ø—‘  EÕ*ð+à Ÿn™nò 5�
Ø×$Ñ$ R¨Õ4ð5àŸ™ò +�Ø—‘  EÕ*ð+ð —]‘]“_ˆFØÐ!Ü×3Ñ3°B¸Ó?�Ø—]‘]×.Ñ.°fÀEÐ.ÓJñ 6Ø˜YÒ'Ø×)Ñ)¨"¨fÔ5÷6÷3	6ð 	6÷26ð 6ú÷3	6ð 	6ús8   ±BH+ÃH+ÃAH+Ä4CH+Ç6HÈH+ÈH(	È$H+È+H4c                 ó0  — t        t        j                  |j                  d¬«      «      }|j	                  |j
                  «       |D �]£  }|j                  d|j                  «       z   «       t        |t        j                  j                  «      r"|j                  |j                  «       dz
  «       	 t        |t        j                  j                  «      r| j                  |||j                  ¬«       nôt        |t        j                  j                   «      r2|j#                  «       dk7  r½| j%                  |||j                  ¬«       nžt        |t        j&                  j(                  «      r| j+                  |||j                  ¬«       n[t        |t        j,                  j.                  «      r| j1                  |||j                  ¬«       nt3        j4                  d|z  «       �Œ¦ y	# t6        $ r t3        j4                  d|z  «       Y �ŒÌw xY w)
zE
        Recursively look through objects in legend children
        T)ÚskipContainersg    €„.Ar   ©r1   ÚNone)Úforce_pathtransz Legend element %s not impementedN)Úlistr   Úiter_all_childrenÚ_legend_boxÚappendÚlegendPatchÚ
set_zorderÚ
get_zorderr%   rO   rR   ÚFancyBboxPatchÚPatchrS   r+   rP   rQ   r?   rH   rE   ÚLine2DrF   rT   Ú
CollectionrU   r'   r(   ÚNotImplementedError)r   r/   rA   ÚlegendElementsÚchilds        r   r[   zExporter.crawl_legend�   s™  € ô Ü×#Ñ# F×$6Ñ$6ÀtÔLó
ˆð 	×Ñ˜f×0Ñ0Ô1Ø#ó 	JˆEà×Ñ˜S 5×#3Ñ#3Ó#5Ñ5Ô6ô ˜%¤×!3Ñ!3×!BÑ!BÔCØ× Ñ  ×!1Ñ!1Ó!3°aÑ!7Ô8ðJä˜e¤Z×%7Ñ%7×%=Ñ%=Ô>Ø—O‘O B¨¸2¿<¹<�OÕHÜ ¤z§¡×';Ñ';Ô<Ø—~‘~Ó'¨6Ò1ØŸ™ r¨5¸b¿l¹l˜ÕKÜ ¤z×'7Ñ'7×'>Ñ'>Ô?Ø—N‘N 2 u¸"¿,¹,�NÕGÜ ¤z×'=Ñ'=×'HÑ'HÔIØ×(Ñ(¨¨UÀBÇLÁLÐ(ÕQä—M‘MÐ"DÀuÑ"LÔMùñ)	Jøô* 'ò JÜ—‘Ð@À5ÑH×IðJús   Â5D7G0Ç0!HÈHc                 ó†  — | j                  |j                  «       ||j                  «       |¬«      \  }}t        j                  |«      }|d   €
|d   dk(  rd}t        j
                  |«      }|d   dv s|d   d	   j                  d	k(  rd}|j                  «       }|s|r"| j                  j                  ||||||¬
«       yy)z5Process a matplotlib line and call renderer.draw_linerd   Ú	dasharrayNÚ	drawstyleÚdefaultÚmarker)re   ÚnoneNÚ
markerpathr   )r"   ÚcoordinatesÚ	linestyleÚmarkerstylerK   Úmplobj)
r5   Úget_transformÚ
get_xydatar   Úget_line_styleÚget_marker_styleÚsizeÚ	get_labelr   Údraw_marked_line)	r   r/   r\   r1   r|   r"   r}   r~   rK   s	            r   rF   zExporter.draw_line½   sÝ   € à ×2Ñ2Ø×ÑÓ  " d§o¡oÓ&7À[ð 3ó 
Ñˆ�Tô ×(Ñ(¨Ó.ˆ	Ø�[Ñ!Ð)¨i¸Ñ.DÈ	Ò.QØˆIÜ×,Ñ,¨TÓ2ˆà˜Ñ!Ð%;Ñ;Ø˜<Ñ(¨Ñ+×0Ñ0°AÒ5àˆKØ—‘Ó ˆÙ™)Ø�M‰M×*Ñ*ØØ'Ø#Ø'ØØð +õ ð $r   c                 ó  — |j                  «       }|ro|j                  «       }|j                  «       }| j                  ||||¬«      \  }}t	        j
                  |«      }	| j                  j                  |||||	|¬«       yy)z<Process a matplotlib text object and call renderer.draw_textrd   )rP   Úpositionr|   r@   Ústyler   N)r?   r€   Úget_positionr5   r   Úget_text_styler   rH   )
r   r/   rP   r1   r@   Úcontentr)   rˆ   Úcoordsr‰   s
             r   rH   zExporter.draw_textÖ   s�   € à—-‘-“/ˆÙØ×*Ñ*Ó,ˆIØ×(Ñ(Ó*ˆHØ#×5Ñ5Ø˜2˜x°[ð  6ó  ÑˆF�Hô ×(Ñ(¨Ó.ˆEØ�M‰M×#Ñ#ØØ!Ø"Ø#ØØð $õ ð r   c                 ó*  — t        j                  |j                  «       «      \  }}|j                  «       }| j	                  ||||¬«      \  }}t        j
                  ||j                  «       ¬«      }| j                  j                  |||||¬«       y)z=Process a matplotlib patch object and call renderer.draw_pathrd   )Úfill)r"   r|   Ú	pathcodesr‰   r   N)	r   ÚSVG_pathÚget_pathr€   r5   Úget_path_styleÚget_fillr   Ú	draw_path)	r   r/   r_   r1   Úverticesr�   r)   r|   r}   s	            r   rS   zExporter.draw_patché   sŽ   € ä#Ÿn™n¨U¯^©^Ó-=Ó>Ñˆ�)Ø×'Ñ'Ó)ˆ	Ø $× 6Ñ 6Ø�r˜8°ð !7ó !
Ñˆ�Xô ×(Ñ(¨°U·^±^Ó5EÔFˆ	Ø�‰×ÑØØ#ØØØð 	 õ 	
r   c           
      óâ  — |j                  «       \  }}}}| j                  ||||¬«      \  }	}| j                  |||¬«      }
|D �cg c]  }t        j                  |«      ‘Œ }}|D �cg c]"  }| j                  |||d   |¬«      d   |d   f‘Œ$ }}|j	                  «       }	 |D �cg c]  }|j                  «       ‘Œ }}|j                  «       |j                  «       |j                  «       |j                  |j                  «       dœ}dddœ}t        |d«      r||j                  «          nd}| j                  j                  ||
|||	|||¬	«       y
c c}w c c}w c c}w # t        $ r Y Œ®w xY w)zAProcess a matplotlib collection and call renderer.draw_collectionrd   r   r   )Ú	linewidthÚ	facecolorÚ	edgecolorÚalphaÚzorderÚbeforeÚafter)r"   ÚscreenÚget_offset_position)ÚpathsÚpath_coordinatesÚpath_transformsÚoffsetsÚoffset_coordinatesÚoffset_orderÚstylesr   N)Ú_prepare_pointsr5   r   r‘   Úget_transformsÚ
get_matrixÚAttributeErrorÚget_linewidthsÚget_facecolorsÚget_edgecolorsÚ_alpharm   rM   r    r   Údraw_path_collection)r   r/   r`   rf   Úforce_offsettransr)   ÚtransOffsetr¤   r¡   Úoffset_coordsÚpath_coordsÚpathÚprocessed_pathsr£   Útr§   Úoffset_dictr¦   s                     r   rU   zExporter.draw_collectionù   sÄ  € ð 4>×3MÑ3MÓ3OÑ0ˆ�K ¨%à!%×!7Ñ!7Ø˜˜WÐ2Cð "8ó "
Ñˆ�wð ×,Ñ,¨Y¸ÈÐ,ÓXˆà<AÖB°Dœ5Ÿ>™>¨$Õ/ÐBˆÐBð (ö
ð ð ×&Ñ&Ø˜r 4¨¡7¸ð 'ó àñð �Q‘ò	ð
ˆð 
ð %×3Ñ3Ó5ˆð	ð 8GÖG°!˜qŸ|™|�~ÐGˆOÐGð $×2Ñ2Ó4Ø#×2Ñ2Ó4Ø#×2Ñ2Ó4Ø×&Ñ&Ø ×+Ñ+Ó-ñ
ˆð  (°7Ñ;ˆô �zÐ#8Ô9ð ˜
×6Ñ6Ó8Ò9àð 	ð 	�‰×*Ñ*Ø!Ø(Ø+ØØ,Ø%ØØð 	+õ 		
ùòK Cùò
ùò HøÜò 	áð	ús0   ÁEÁ('EÂ"E" Â&EÂ=E" ÅE" Å"	E.Å-E.c                 óÄ   — | j                   j                  t        j                  |«      |j	                  «       d|j                  «       |j                  «       dœ|¬«       y)z>Process a matplotlib image object and call renderer.draw_imager"   )r›   rœ   )ÚimdataÚextentr|   r‰   r   N)r   rW   r   Úimage_to_base64Ú
get_extentÚ	get_alpharm   )r   r/   ra   s      r   rW   zExporter.draw_image4  sQ   € à�‰× Ñ Ü×(Ñ(¨Ó/Ø×#Ñ#Ó%ØØ!ŸO™OÓ-¸×9IÑ9IÓ9KÑLØð 	!õ 	
r   )T)NNFNr
   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ústaticmethodr5   r   r:   r[   rF   rH   rS   rU   rW   © r   r   r   r      s[   „ ñó!òð( àGKò>ó ð>ò@"ò6ò>Jó@ó2ó&
ð" GKó9
óv
r   r   )rÂ   r'   r   Ú r   rO   r   Úmatplotlib.backends.backend_aggr   Úobjectr   rÄ   r   r   ú<module>rÈ      s,   ðñó Û 	Ý ã Ý !Ý ;ôl
ˆvõ l
r   