
    -Pho.              
       B   d Z ddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ d Zd	 Z ed
ddddd          Zd Zej        dej        dej        dej        dej        diZd#dZd$dZd Zd Zd Zd Z d Z!d Z"d Z#d%d Z$d! Z%d" Z&dS )&zk
Utility Routines for Working with Matplotlib Objects
====================================================
    N)colorConverter)Path)MarkerStyle)Affine2D)tickerc                    | t          j        |           d         dk    rdS t          j        |           d         dk    r(t          j        |           } dj        d |D              S t          j        |           }dd	                    d
 |dd         D                       z   d	z   t          |d                   z   dz   S )z8Convert matplotlib color code to hex color or RGBA colorN   r   none   z#{0:02X}{1:02X}{2:02X}c              3   :   K   | ]}t          d |z            V  dS    N)int).0cs     e/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/plotly/matplotlylib/mplexporter/utils.py	<genexpr>zexport_color.<locals>.<genexpr>   s,      0K0K!S1W0K0K0K0K0K0K    zrgba(z, c           	   3   x   K   | ]5}t          t          t          j        |d z                                V  6dS r   )strr   npround)r   vals     r   r   zexport_color.<locals>.<genexpr>!   s@      GG#Cs 3 34455GGGGGGr   ))r   to_rgbato_rgbformatjoinr   )colorrgbr   s      r   export_colorr!      s    }.u55a8A==v			&	&q	)Q	.	.#E**.'.0K0Ks0K0K0KLL"5))iiGG2A2GGGGGH !A$ii 		
r   c                 X    t          d |                                 D                       S )z5Convert a many-to-one mapping to a one-to-one mappingc              3   .   K   | ]\  }}|D ]}||fV  	d S N )r   keysr   keys       r   r   z_many_to_one.<locals>.<genexpr>*   s7      OOytS$OO3c
OOOOOOOr   )dictitems)
input_dicts    r   _many_to_oner+   (   s+    OOJ,<,<,>,>OOOOOOr   r
   z6,6z2,2z4,4,2,4))solid-)NN)dashedz--)dotted:)dashdotz-.)  Noner
   c                 h   | j                             dd          -d                    t          t          | j                            S |                                 }t                              |d          }|dk    r4t          j	        d
                    |                     t          d         }|S )ap  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   r6   get_linestyle
LINESTYLESwarningswarnr   )objls	dasharrays      r   get_dasharrayrB   8   s     |
D))5xxC..///  NN2{33	##M,,2F2JJ   #7+Ir   LMSCZFc                 \   ||                      |          } d |                     |          D             }|st          j        d          g fS t	          | \  }}t          j        t          t          j        |                     	                    dd          }|t          |          fS )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.
    Nc                 V    g | ]&\  }}|t           j        k    r|ng t          |         f'S r%   )r   	CLOSEPOLY	PATH_DICT)r   vertices	path_codes      r   
<listcomp>zSVG_path.<locals>.<listcomp>u   sF       !Xy $.00b)I:NO  r   )simplify)r      rP   )
transformediter_segmentsr   zerosziparraylist	itertoolschainreshape)path	transformrO   	vc_tuplesrL   codess         r   SVG_pathr_   ]   s    * 	** %)%7%7%7%J%J  I
  %x##y/%8D(!;<<==EEb!LLe$$r   Tc                 r   i }|                                  |d<   |d         d|d<   t          |                                           |d<   |r%t          |                                           |d<   nd|d<   |                                 |d<   t          |           |d<   |                                 |d	<   |S )
z4Get the style dictionary for matplotlib path objectsalphaNr   	edgecolor	facecolorr
   	edgewidthrA   zorder)	get_alphar!   get_edgecolorget_facecolorget_linewidthrB   
get_zorder)r[   fillstyles      r   get_path_stylerm      s    E^^%%E'NW~g%d&8&8&:&:;;E+ $)$*<*<*>*>??k#k++--E+&t,,E+oo''E(OLr   c                 H   i }|                                  |d<   |d         d|d<   t          |                                           |d<   |                                 |d<   t	          |           |d<   |                                 |d<   |                                 |d<   |S )	z4Get the style dictionary for matplotlib line objectsra   Nr   r   	linewidthrA   re   	drawstyle)rf   r!   	get_colorri   rB   rj   get_drawstyle)linerl   s     r   get_line_stylert      s    E^^%%E'NW~g!$.."2"233E'N++--E+&t,,E+oo''E(O++--E+Lr   c                    i }|                                  |d<   |d         d|d<   t          |                                           |d<   t          |                                           |d<   |                                 |d<   |                                 |d<   t          |                                           }|                                 }|                                t                      
                    ||           z   }t          |                                |          |d<   ||d	<   |                                 |d
<   |S )z6Get the style dictionary for matplotlib marker objectsra   Nr   rc   rb   rd   marker
markerpath
markersizere   )rf   r!   get_markerfacecolorget_markeredgecolorget_markeredgewidth
get_markerr   get_markersizeget_transformr   scaler_   get_pathrj   )rs   rl   markerstylerx   markertransforms        r   get_marker_styler      s1   E^^%%E'NW~g%d&>&>&@&@AAE+%d&>&>&@&@AAE+1133E+oo''E(Odoo//00K$$&&J!//11HJJ4D4DZK5 5 O #;#7#7#9#9?KKE,$E,oo''E(OLr   c                    i }|                                  |d<   |d         d|d<   |                                 |d<   t          |                                           |d<   |                                 |d<   |                                 |d<   | j        |d<   |                                 |d	<   |                                 |d
<   |S )z.Return the text style dict for a text instancera   Nr   fontsizer   halignvalignmalignrotationre   )	rf   get_sizer!   rq   get_horizontalalignmentget_verticalalignment_multialignmentget_rotationrj   )textrl   s     r   get_text_styler      s    E^^%%E'NW~gE*!$.."2"233E'N2244E(O0022E(O*E(O))++E*oo''E(OLr   c                    i }| j                             dd          }t          | t          j        j                  r|rd|d<   nUd|d<   nOt          | t          j        j                  r|rd|d<   n(d|d<   n"t          d                    |                     | 	                                }t           |                      |d	<   t          |t          j                  rt           |                      |d
<   nd|d
<   |                                 }t          |t          j                  rd|d<   nt          |t          j                  rt          |j                  |d<   nt          |t          j                  r5t          |j        j        d                                                   |d<   n6t-          d |                                 D                       sd|d<   nd|d<   |                                 |d<   |                                 }|r|d                                         |d<   nd|d<   t5          |           |d<   |                                 |d<   |S )z=Return the property dictionary for a matplotlib.Axis instancelabel1OnTbottompositiontopleftrightz{0} should be an Axis instancenticks
tickvaluesNr2   
tickformatr   c              3   >   K   | ]}|                                 V  d S r$   )get_visible)r   labels     r   r   z&get_axis_properties.<locals>.<genexpr>   s.      HH""$$HHHHHHr   r   r   gridvisible)_major_tick_kwr9   
isinstance
matplotlibaxisXAxisYAxis
ValueErrorr   get_major_locatorlenr   FixedLocatorrW   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      sz   E"&&z488H$
-.. H 	& (E* %E*	D*//	0	0 H 	( &E* 'E*9@@FFGGG $$&&G''))nnE(O'6.// #"7799ool"l ((**I)V122 	# l	Iv4	5	5 #"9=11l	Iv3	4	4 #"9>#6q#9#@#@#B#BCClHH$2E2E2G2GHHHHH # l"l ^^%%E'N   ""F !"1I2244j j #4((E&M ''))E)Lr   c                 D   |                                  }| j        d         r|t          |          dk    rit          |d                                                   }|d                                         }t          |d                   }t          d|||          S ddiS )NgridOnr   T)r   r   rA   ra   F)get_gridlinesr   r   r!   rq   rf   rB   r(   )r   	gridlinesr   ra   rA   s        r   r   r     s    ""$$I8$ !Y!););Yq\335566!&&((!)A,//	4u	OOOO%  r   c                 `    |                                  |                                 | j        dS )N)figwidth	figheightdpi)get_figwidthget_figheightr   )figs    r   get_figure_propertiesr     s4    $$&&&&((w  r   c                 (  	 t          | j                                                  | j                                        |                                 j        |                                 | j        |                                 | j        	                                t          | j                  t          | j                  gd}dD ]H}t          | |dz              t          | d                    |                                }|}t          j        t"          j        j                  r}d}	 dd l	ddlm} n# t.          $ r d 	Y nw xY w	1t          j        |          r	fd|D             }d	 |D             }n>d
 t"          j                            |          D             }n                                }|dvr4t5          d                                                                        |||dz   <   |||dz   <   |||dz   <   J|S )N)axesbgaxesbgalphaboundsdynamicaxisonframe_onpatch_visibleaxes)xyr   z
get_{0}limdater   )PeriodConverterc                 b    g | ]+}                     t          |          j                   ,S ))ordinalfreq)Periodr   r   )r   dr   pds     r   rN   z'get_axes_properties.<locals>.<listcomp>/  s1    TTT"))CFF)CCTTTr   c           	      b    g | ],}|j         |j        d z
  |j        |j        |j        |j        df-S )r   r   )yearmonthdayhourminutesecondr   r   s     r   rN   z'get_axes_properties.<locals>.<listcomp>0  sG        VQWq[!%18QO  r   c           
      r    g | ]4}|j         |j        d z
  |j        |j        |j        |j        |j        dz  f5S )r   gMbP?)r   r   r   r   r   r   microsecondr   s     r   rN   z'get_axes_properties.<locals>.<listcomp>5  sX         !,  r   )r   linearlogzUnknown axis scale: {0}r   limdomain)r!   patchrh   rf   get_positionr   get_navigater   get_frame_onr   r   xaxisyaxisgetattrr   r   	converterr   datesDateConverterpandaspandas.tseries.converterr   ImportErrornum2dater   r   )
axr   axnamer   r   r   r   _datesr   r   s
           @@r   get_axes_propertiesr     sL   rx557788x))++//##*??$$)OO%%--//$RX..0CBH0M0MN	 	E  '* '*r6F?++9\008899;;dnj&6&DEE 	%E####DDDDDDD    ~*T^_"M"M~TTTTTVTTT #  
  (-66v>>   NN$$E1119@@AQAQRRSSS"'fw #fun#)fx  Ls   2
D==EEc              #      K   t          | d          r[t          |                                           dk    r6|                                 D ]}|s|V  t          ||          D ]}|V   dS | V  dS )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)r?   skipContainerschild
grandchilds       r   r   r   N  s       sN## C,<,<,>,>(?(?!(C(C%%'' 	! 	!E! /~FF ! !
     !		! 	! 					r   c                 d    |                                  \  }}|                                }|||dS )N)handlesr   r   )get_legend_handles_labelsr   )r   legendr  r   r   s        r   get_legend_propertiesr  `  s8    2244OGV  ""G&WEEEr   c                    | j         }t          j                    }|                                }|                    |                                            |                     |           |                    |           |                    d           t          j        |	                                          
                    d          S )a$  
    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JLLM ''))CGGE	OOM"""GGCLLLqM..001188AAAr   )NF)T)F)'__doc__rX   r  r  numpyr   r=   r   matplotlib.colorsr   matplotlib.pathr   matplotlib.markersr   matplotlib.transformsr   r   r!   r+   r<   rB   LINETOMOVETOCURVE3CURVE4rJ   rK   r_   rm   rt   r   r   r   r   r   r   r   r  r  r%   r   r   <module>r     s
   
     				           , , , , , ,             * * * * * * * * * * * *      
 
 
$P P P
 \&,$#'  
  : 	KKKKNC	#% #% #% #%L   "    .   7 7 7t! ! !  5 5 5p   $F F FB B B B Br   