
    6Dh.                     Z    S r SSKrSSKrSSKJr  SSKrSSKJr  SSKJr   " S S\	5      r
g)	z
Matplotlib Exporter
===================
This submodule contains tools for crawling a matplotlib figure and exporting
relevant pieces to a renderer.
    N   )utils)
transforms)FigureCanvasAggc                       \ rS rSrSrSS jrS r\ SS j5       rS r	S r
S	 rSS
 jrSS jrSS jr SS jrS rSrg)Exporter   a  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                     X l         Xl        g N	close_mplrenderer)selfr   r   s      Z/var/www/html/env/lib/python3.13/site-packages/plotly/matplotlylib/mplexporter/exporter.py__init__Exporter.__init__    s    "     c                    UR                   c  [        U5      nUR                  [        R                  " 5       SUR
                  S9  U R                  (       a  SSKJn  UR                  U5        U R                  U5        g)zu
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   runExporter.run$   sU     ::$S)FBJJLCGG<>>+IIcNsr   Nc                     [        U [        R                  5      (       a  [        R                  " S5        Ub  Ub  X-
  R                  U5      nUn SnUbo  SUR                  4SUR                  4SUR                  R                  4S[        R                  " 5       44 H"  u  pgU R                  U5      (       d  M  X`U-
  p  O   Ub,  U(       a  XPR                  U5      U 4$ XPR                  U5      4$ U(       a  XP4$ U$ )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_transformExporter.process_transform8   s   > i!C!CDDMM:
 "!/::4@#I>&&299001J88:;	 ,,U33'(e*;) 006	AA00666&r   c                     U R                   R                  U[        R                  " U5      S9   UR                   H  nU R                  U5        M     SSS5        g! , (       d  f       g= f)z%Crawl the figure and process all axes)r    propsN)r   draw_figurer   get_figure_propertiesr'   crawl_ax)r   r    r3   s      r   r   Exporter.crawl_figy   sL    ]]&&3e6Q6QRU6V&Whhb!  XWWs   %A
A+c           	         U R                   R                  U[        R                  " U5      S9   UR                   H  nU R                  X5        M     UR                   H  nU R                  X5        M     [        UR                  R                  UR                  R                  UR                  // SQ5       HJ  u  p4[        US5      (       d  M  UR                  5       (       d  M/  U R                  XUR                  US9  ML     UR                    H?  n[#        U[$        R&                  R(                  5      (       d  M.  U R                  X5        MA     UR*                   H  nU R-                  X5        M     UR.                   H  nU R1                  X5        M     UR2                   H  nU R5                  X5        M     UR7                  5       n	U	bS  [        R8                  " X5      n
U R                   R;                  XS9   U
S   (       a  U R=                  X5        SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)z.Crawl the axes and process all elements within)r3   r<   )xlabelylabeltitleget_text)r5   	text_typeN)legendr<   visible)r   	draw_axesr   get_axes_propertieslines	draw_linetexts	draw_textzipxaxislabelyaxisrD   hasattrrE   r/   artistsr)   
matplotlibtextTextpatches
draw_patchcollectionsdraw_collectionimages
draw_image
get_legendget_legend_propertiesdraw_legendcrawl_legend)r   r3   linerV   ttpartistpatch
collectionimagerG   r<   s              r   r?   Exporter.crawl_ax   s   ]]$$%2K2KB2O$Pr( !r( ! :-	 4,,NN2QTNU **fjoo&:&:;;NN2. % * $ nn
$$R4 -* # ]]_F!33B?]]..f.JY'))"5 K3 QP2 KJ3 QPs8   B II*AICIH3"I3
I	=I
Ic                 `   [        [        R                  " UR                  SS95      nUR	                  UR
                  5        U GH  nUR                  SUR                  5       -   5        [        U[        R                  R                  5      (       a"  UR                  UR                  5       S-
  5         [        U[        R                  R                  5      (       a  U R                  XUR                  S9  M  [        U[        R                  R                   5      (       a4  UR#                  5       S:w  a  U R%                  XUR                  S9  GM  GM  [        U[        R&                  R(                  5      (       a  U R+                  XUR                  S9  GMZ  [        U[        R,                  R.                  5      (       a  U R1                  XUR                  S9  GM  [2        R4                  " SU-  5        GM     g	! [6         a    [2        R4                  " SU-  5         GM  f = f)
z5
Recursively look through objects in legend children
T)skipContainersg    .Ar   r5   None)force_pathtransz Legend element %s not impementedN)listr   iter_all_children_legend_boxappendlegendPatch
set_zorder
get_zorderr)   rU   rX   FancyBboxPatchPatchrY   r/   rV   rW   rE   rN   rK   Line2DrL   rZ   
Collectionr[   r+   r,   NotImplementedError)r   r3   rG   legendElementschilds        r   ra   Exporter.crawl_legend   s    ##F$6$6tL
 	f001#ES5#3#3#556 %!3!3!B!BCC  !1!1!3a!78JeZ%7%7%=%=>>OOB2<<OHz';';<<~~'61rbllK 2z'7'7'>'>??NN2",,NGz'='='H'HII((BLL(QMM"Du"LM) $* ' J@5HIIJs.   8AH=AHAH AH&H#H-,H-c           	         U R                  UR                  5       XR                  5       US9u  pE[        R                  " U5      nUS   c  US   S:X  a  Sn[        R
                  " U5      nUS   S;   d  US   S	   R                  S	:X  a  SnUR                  5       nU(       d  U(       a  U R                  R                  UUUUUUS
9  gg)z5Process a matplotlib line and call renderer.draw_linerk   	dasharrayN	drawstyledefaultmarker)rl   noneN
markerpathr   )r&   coordinates	linestylemarkerstylerQ   mplobj)
r9   get_transform
get_xydatar   get_line_styleget_marker_stylesize	get_labelr   draw_marked_line)	r   r3   rb   r5   r   r&   r   r   rQ   s	            r   rL   Exporter.draw_line   s     22 "oo&7[ 3 
 ((.	[!)i.D	.QI,,T2!%;;<(+00A5K )MM**'#' +  $r   c           	          UR                  5       nU(       ag  UR                  5       nUR                  5       nU R                  XaXsS9u  p[        R
                  " U5      n	U R                  R                  UUUUU	US9  gg)z<Process a matplotlib text object and call renderer.draw_textrk   )rV   positionr   rF   styler   N)rE   r   get_positionr9   r   get_text_styler   rN   )
r   r3   rV   r5   rF   contentr-   r   coordsr   s
             r   rN   Exporter.draw_text   s    --/**,I((*H#55x  6  F ((.EMM##!"# $  r   c                    [         R                  " UR                  5       5      u  pEUR                  5       nU R	                  XaXCS9u  pt[         R
                  " X"R                  5       S9nU R                  R                  UUUUUS9  g)z=Process a matplotlib patch object and call renderer.draw_pathrk   )fill)r&   r   	pathcodesr   r   N)	r   SVG_pathget_pathr   r9   get_path_styleget_fillr   	draw_path)	r   r3   re   r5   verticesr   r-   r   r   s	            r   rY   Exporter.draw_patch   s    #nnU^^-=>'')	 $ 6 68 !7 !
 ((^^5EF	# 	  	
r   c                    UR                  5       u  pVpxU R                  XaXtS9u  pU R                  XQUS9n
U Vs/ s H  n[        R                  " U5      PM     nnU Vs/ s H  nU R                  XQUS   US9S   US   4PM!     nnUR	                  5       n U Vs/ s H  oR                  5       PM     nnUR                  5       UR                  5       UR                  5       UR                  UR                  5       S.nSSS.n[        US5      (       a  UUR                  5          OSnU R                  R                  UU
UUU	UUUS	9  g
s  snf s  snf s  snf ! [         a     Nf = f)zAProcess a matplotlib collection and call renderer.draw_collectionrk   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_pointsr9   r   r   get_transforms
get_matrixAttributeErrorget_linewidthsget_facecolorsget_edgecolors_alphart   rS   r   r   draw_path_collection)r   r3   rf   rm   force_offsettransr-   transOffsetr   r   offset_coordspath_coordspathprocessed_pathsr   tr   offset_dictr   s                     r   r[   Exporter.draw_collection   s    4>3M3M3O0!%!7!7W "8 "
 ,,Y,X<ABED5>>$/EB (
 ( &&47 '  Q	 ( 	 
 %335	 8GG!||~OG $224#224#224&& ++-
  (7; z#899 
6689 	 	**!(+,% 	+ 		
K C
 H 		s/    E &EE E6E E 
E*)E*c                     U R                   R                  [        R                  " U5      UR	                  5       SUR                  5       UR                  5       S.US9  g)z>Process a matplotlib image object and call renderer.draw_imager&   )r   r   )imdataextentr   r   r   N)r   r]   r   image_to_base64
get_extent	get_alphart   )r   r3   rg   s      r   r]   Exporter.draw_image5  sQ      ((/##%!OO-9I9I9KL 	! 	
r   r   )T)NNFNr   )NN)__name__
__module____qualname____firstlineno____doc__r   r"   staticmethodr9   r   r?   ra   rL   rN   rY   r[   r]   __static_attributes__ r   r   r   r      s[    !( GK> >@"6>J@2&
" GK9
v
r   r   )r   r+   r    r   rU   r   matplotlib.backends.backend_aggr   objectr   r   r   r   <module>r      s,     	   ! ;l
v l
r   