
    6Dho.              
       r   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJr  S rS	 r\" S
SSSSS.5      rS r\R*                  S\R,                  S\R.                  S\R0                  S\R2                  S0rS!S jrS"S jrS rS rS rS r S r!S r"S r#S#S jr$S r%S  r&g)$zk
Utility Routines for Working with Matplotlib Objects
====================================================
    N)colorConverter)Path)MarkerStyle)Affine2D)tickerc                 h   U b  [         R                  " U 5      S   S:X  a  g[         R                  " U 5      S   S:X  a,  [         R                  " U 5      nSR                  " S U 5       6 $ [         R                  " U 5      nSS	R	                  S
 USS  5       5      -   S	-   [        US   5      -   S-   $ )z8Convert matplotlib color code to hex color or RGBA colorN   r   none   z#{0:02X}{1:02X}{2:02X}c              3   >   #    U  H  n[        S U-  5      v   M     g7f   N)int).0cs     W/var/www/html/env/lib/python3.13/site-packages/plotly/matplotlylib/mplexporter/utils.py	<genexpr>export_color.<locals>.<genexpr>   s     0Ks!S1Wss   zrgba(z, c           	   3   x   #    U  H0  n[        [        [        R                  " US -  5      5      5      v   M2     g7fr   )strr   npround)r   vals     r   r   r   !   s*     G#Cs 3455s   8:))r   to_rgbato_rgbformatjoinr   )colorrgbr   s      r   export_colorr!      s    }..u5a8A=				&q	)Q	.##E*'..0Ks0KLL""5)iiG2AGGH !A$i 		
    c                 B    [        S U R                  5        5       5      $ )z5Convert a many-to-one mapping to a one-to-one mappingc              3   @   #    U  H  u  pU  H  o3U4v   M
     M     g 7fN )r   keysr   keys       r   r   _many_to_one.<locals>.<genexpr>*   s     O,>yt$3c
$
,>   )dictitems)
input_dicts    r   _many_to_oner.   (   s    OJ,<,<,>OOOr"   r
   z6,6z2,2z4,4,2,4))solid-)NN)dashedz--)dotted:)dashdotz-.)  Noner
   c                 F   U R                   R                  SS5      b)  SR                  [        [        U R
                  5      5      $ U R                  5       n[        R                  US5      nUS:X  a.  [        R                  " SR                  U5      5        [        S   nU$ )aH  Get an SVG dash array for the given matplotlib linestyle

Parameters
----------
obj : matplotlib object
    The matplotlib line or path object, which must have a get_linestyle()
    method which returns a valid matplotlib line code

Returns
-------
dasharray : string
    The HTML/SVG dasharray code associated with the object.
_dashSeqN,z	not foundz:line style '{0}' not understood: defaulting to solid line.r/   )__dict__getr   mapr   r9   get_linestyle
LINESTYLESwarningswarnr   )objls	dasharrays      r   get_dasharrayrE   8   s     ||
D)5xxC.// NN2{3	#MM,,2F2J #7+Ir"   LMSCZc                    Ub  U R                  U5      n U R                  US9 VVs/ s H&  u  p4U[        R                  :w  a  UO/ [        U   4PM(     nnnU(       d  [
        R                  " S5      / 4$ [        U6 u  p6[
        R                  " [        [        R                  " U6 5      5      R                  SS5      nU[        U5      4$ s  snnf )a  Construct the vertices and SVG codes for the path

Parameters
----------
path : matplotlib.Path object

transform : matplotlib transform (optional)
    if specified, the path will be transformed before computing the output.

Returns
-------
vertices : array
    The shape (M, 2) array of vertices of the Path. Note that some Path
    codes require multiple vertices, so the length of these vertices may
    be longer than the list of path codes.
path_codes : list
    A length N list of single-character path codes, N <= M. Each code is
    a single character, in ['L','M','S','C','Z']. See the standard SVG
    path specification for a description of these.
)simplify)r      rM   )transformediter_segmentsr   	CLOSEPOLY	PATH_DICTr   zerosziparraylist	itertoolschainreshape)path	transformrL   vertices	path_code	vc_tuplescodess          r   SVG_pathr`   ]   s    * 	* &*%7%7%7%J%J!X $..0b)I:NO%J  
 xx##y/88D(!;<=EEb!Le$$s   -Cc                 8   0 nU R                  5       US'   US   c  SUS'   [        U R                  5       5      US'   U(       a  [        U R                  5       5      US'   OSUS'   U R	                  5       US'   [        U 5      US'   U R                  5       US'   U$ )	z4Get the style dictionary for matplotlib path objectsalphar   	edgecolor	facecolorr
   	edgewidthrD   zorder)	get_alphar!   get_edgecolorget_facecolorget_linewidthrE   
get_zorder)rZ   fillstyles      r   get_path_stylern      s    E^^%E'NW~g%d&8&8&:;E+)$*<*<*>?k#k++-E+&t,E+oo'E(OLr"   c                    0 nU R                  5       US'   US   c  SUS'   [        U R                  5       5      US'   U R                  5       US'   [	        U 5      US'   U R                  5       US'   U R                  5       US'   U$ )z4Get the style dictionary for matplotlib line objectsrb   r   r   	linewidthrD   rf   	drawstyle)rg   r!   	get_colorrj   rE   rk   get_drawstyle)linerm   s     r   get_line_styleru      s    E^^%E'NW~g!$.."23E'N++-E+&t,E+oo'E(O++-E+Lr"   c                    0 nU R                  5       US'   US   c  SUS'   [        U R                  5       5      US'   [        U R                  5       5      US'   U R	                  5       US'   U R                  5       US'   [        U R                  5       5      nU R                  5       nUR                  5       [        5       R                  X3* 5      -   n[        UR                  5       U5      US'   X1S'   U R                  5       US	'   U$ )
z6Get the style dictionary for matplotlib marker objectsrb   r   rd   rc   re   marker
markerpath
markersizerf   )rg   r!   get_markerfacecolorget_markeredgecolorget_markeredgewidth
get_markerr   get_markersizeget_transformr   scaler`   get_pathrk   )rt   rm   markerstylery   markertransforms        r   get_marker_styler      s    E^^%E'NW~g%d&>&>&@AE+%d&>&>&@AE+113E+oo'E(Odoo/0K$$&J!//1HJ4D4DK5 O #;#7#7#9?KE,$,oo'E(OLr"   c                 Z   0 nU R                  5       US'   US   c  SUS'   U R                  5       US'   [        U R                  5       5      US'   U R	                  5       US'   U R                  5       US'   U R                  US'   U R                  5       US'   U R                  5       US	'   U$ )
z.Return the text style dict for a text instancerb   r   fontsizer   halignvalignmalignrotationrf   )	rg   get_sizer!   rr   get_horizontalalignmentget_verticalalignment_multialignmentget_rotationrk   )textrm   s     r   get_text_styler      s    E^^%E'NW~gE*!$.."23E'N224E(O002E(O**E(O))+E*oo'E(OLr"   c                    0 nU R                   R                  SS5      n[        U [        R                  R
                  5      (       a  U(       a  SUS'   O\SUS'   OV[        U [        R                  R                  5      (       a  U(       a  SUS'   O SUS'   O[        SR                  U 5      5      eU R                  5       n[        U" 5       5      US	'   [        U[        R                  5      (       a  [        U" 5       5      US
'   OSUS
'   U R                  5       n[        U[        R                  5      (       a  SUS'   O[        U[        R                   5      (       a  [        UR"                  5      US'   O[        U[        R$                  5      (       a4  [        UR&                  R(                  S   R+                  5       5      US'   O0[-        S U R/                  5        5       5      (       d  SUS'   OSUS'   U R1                  5       US'   U R/                  5       nU(       a  US   R3                  5       US'   OSUS'   [5        U 5      US'   U R7                  5       US'   U$ )z=Return the property dictionary for a matplotlib.Axis instancelabel1OnTbottompositiontopleftrightz{0} should be an Axis instancenticks
tickvaluesNr5   
tickformatr   c              3   @   #    U  H  oR                  5       v   M     g 7fr%   )get_visible)r   labels     r   r   &get_axis_properties.<locals>.<genexpr>   s     H2G""$$2Gr*   r   r   gridvisible)_major_tick_kwr<   
isinstance
matplotlibaxisXAxisYAxis
ValueErrorr   get_major_locatorlenr   FixedLocatorrV   get_major_formatterNullFormatterFixedFormatterseqFuncFormatterfuncargsvaluesanyget_ticklabels	get_scaleget_fontsizeget_grid_styler   )r   propsr   locator	formatterlabelss         r   get_axis_propertiesr      s	   E""&&z48H$
--.. (E* %E*	D*////	0	0 &E* 'E*9@@FGG $$&G')nE(O'6..//"79ol"l ((*I)V1122 l	Iv44	5	5"9==1l	Iv33	4	4"9>>#6#6q#9#@#@#BClH$2E2E2GHHH l"l ^^%E'N   "F"1I224j j #4(E&M '')E)Lr"   c                     U R                  5       nU R                  S   (       aW  [        U5      S:  aH  [        US   R	                  5       5      nUS   R                  5       n[        US   5      n[        SX$US9$ SS0$ )NgridOnr   T)r   r   rD   rb   F)get_gridlinesr   r   r!   rr   rg   rE   r+   )r   	gridlinesr   rb   rD   s        r   r   r     sz    ""$I8$Y!);Yq\3356!&&(!)A,/	4uOO%  r"   c                 Z    U R                  5       U R                  5       U R                  S.$ )N)figwidth	figheightdpi)get_figwidthget_figheightr   )figs    r   get_figure_propertiesr     s+    $$&&&(ww r"   c                    [        U R                  R                  5       5      U R                  R                  5       U R	                  5       R
                  U R                  5       U R                  U R                  5       U R                  R                  5       [        U R                  5      [        U R                  5      /S.nS GH  n[        XS-   5      n[        U SR                  U5      5      " 5       nUn[        UR                   ["        R$                  R&                  5      (       Ga9  Sn SS KnSSKJn  Ub  [        UR                   W5      (       a  U V	s/ s H%  oR1                  [3        U	5      UR4                  S9PM'     n
n	U
 V	s/ s HK  n	U	R6                  U	R8                  S	-
  U	R:                  U	R<                  U	R>                  U	R@                  S4PMM     nn	O["        R$                  RC                  U5       V	s/ s HX  n	U	R6                  U	R8                  S	-
  U	R:                  U	R<                  U	R>                  U	R@                  U	RD                  S
-  4PMZ     nn	OURG                  5       nUS;  a(  [I        SR                  URG                  5       5      5      eXaUS-   '   XQUS-   '   XAUS-   '   GM     U$ ! [.         a    S n GNf = fs  sn	f s  sn	f s  sn	f )N)axesbgaxesbgalphaboundsdynamicaxisonframe_onpatch_visibleaxes)xyr   z
get_{0}limdater   )PeriodConverter)ordinalfreqr   gMbP?)r   linearlogzUnknown axis scale: {0}r   limdomain)%r!   patchri   rg   get_positionr   get_navigater   get_frame_onr   r   xaxisyaxisgetattrr   r   	converterr   datesDateConverterpandaspandas.tseries.converterr   ImportErrorPeriodr   r   yearmonthdayhourminutesecondnum2datemicrosecondr   r   )axr   axnamer   r   r   r   pdr   d_datess              r   get_axes_propertiesr     sv   rxx5578xx))+//#**??$))OO%--/$RXX.0CBHH0MN	E rF?+\0089;dnnj&6&6&D&DEEE#D ~*T^^_"M"MMSTV))CF)CVT $# VVQWWq[!%%188QO#   (--66v> ? !, ?   NN$E119@@AQRSS"'fw #fun#)fx O R LA   U
s&   0
K ,KAKAK KKc              #      #    [        U S5      (       aV  [        U R                  5       5      S:  a9  U R                  5        H$  nU(       d  Uv   [        X!5       H  nUv   M	     M&     gU v   g7f)z
Returns an iterator over all childen and nested children using
obj's get_children() method

if skipContainers is true, only childless objects are returned.
get_childrenr   N)hasattrr   r   iter_all_children)rB   skipContainerschild
grandchilds       r   r   r   N  sa      sN##C,<,<,>(?!(C%%'E!/F
   G	 ( 	s   A-A/c                 P    U R                  5       u  p#UR                  5       nX#US.$ )N)handlesr   r   )get_legend_handles_labelsr   )r   legendr  r   r   s        r   get_legend_propertiesr  `  s+    224OG  "GWEEr"   c                 n   U R                   n[        R                  " 5       nUR                  5       nUR                  U R	                  5       5        U R                  U5        UR                  U5        UR                  S5        [        R                  " UR                  5       5      R                  S5      $ )z
Convert a matplotlib image to a base64 png representation

Parameters
----------
image : matplotlib image object
    The image to be converted.

Returns
-------
image_base64 : string
    The UTF8-encoded base64 string representation of the png image.
r   zutf-8)r   ioBytesIOr   
get_extent	write_pngseekbase64	b64encodereaddecode)imager   binary_bufferr   s       r   image_to_base64r  f  s     
BJJLM '')CGGE	OOM"GGCLqM..0188AAr"   )NF)T)F)'__doc__rW   r  r  numpyr   r@   r   matplotlib.colorsr   matplotlib.pathr   matplotlib.markersr   matplotlib.transformsr   r   r!   r.   r?   rE   LINETOMOVETOCURVE3CURVE4rQ   rR   r`   rn   ru   r   r   r   r   r   r   r   r  r  r&   r"   r   <module>r     s   
  	     ,   * * 
$P
 &,$#'
: 	KKKKKKKKNNC	#%L". 7t!5p$FBr"   