
    gyN                    &   d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	m
Z d dlmZ d dlZd dlmZmZ d dlmZmZ d dlmZmZ d dlmZmZ d d	lmZ er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)  G d de      Z* G d de*      Z+ G d de*      Z,y)    )annotationsN)pairwise)TYPE_CHECKINGAnycast)FillTypeLineType)convert_filledconvert_lines)as_fill_typeas_line_type)filled_to_mpl_pathslines_to_mpl_paths)Renderer)Sequence)Axes)Figure)	ArrayLikec                  t   e Zd ZU dZded<   ded<   ded<   	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Zdd
ZddZddZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ		 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 d 	 	 	 	 	 	 	 	 	 	 	 d!dZd"d#dZd$dZddZd%d&dZ	 	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZy))MplRenderera  Utility renderer using Matplotlib to render a grid of plots over the same (x, y) range.

    Args:
        nrows (int, optional): Number of rows of plots, default ``1``.
        ncols (int, optional): Number of columns of plots, default ``1``.
        figsize (tuple(float, float), optional): Figure size in inches, default ``(9, 9)``.
        show_frame (bool, optional): Whether to show frame and axes ticks, default ``True``.
        backend (str, optional): Matplotlib backend to use or ``None`` for default backend.
            Default ``None``.
        gridspec_kw (dict, optional): Gridspec keyword arguments to pass to ``plt.subplots``,
            default None.
    zSequence[Axes]_axesr   _figbool_want_tightNc                   |dd l }|j                  |       |dddd}|||d<   nddi|d<   t        j                  ||fi |\  | _        }	|	j                         | _        |s"| j                  D ]  }
|
j                  d	        d| _        y )
Nr   FT)figsizesqueezesharexshareygridspec_kwaspectequal
subplot_kwoff)	
matplotlibusepltsubplotsr   flattenr   axisr   )selfnrowsncolsr   
show_framebackendr    mplkwargsaxesaxs              X/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/contourpy/util/mpl_renderer.py__init__zMplRenderer.__init__,   s     $GGG-4,0D"B"$/F=!$,g#6F< ,,ue>v>	4\\^
jj       c                \    t        | d      r t        j                  | j                         y y )Nr   )hasattrr'   closer   r+   s    r4   __del__zMplRenderer.__del__H   s!    4 IIdii  !r6   c                    | j                   D ])  }t        |dd      s|j                  d       d|_        + | j                  r4t        | j                         dkD  r| j                  j                          y y y )N_need_autoscaleFT)tight   )r   getattrautoscale_viewr=   r   lenr   tight_layoutr+   r3   s     r4   
_autoscalezMplRenderer._autoscaleL   so     ** 	+Br,e4!!!-%*"	+ DJJ! 3II""$ !4r6   c                D    t        |t              r| j                  |   }|S N)
isinstanceintr   rD   s     r4   _get_axzMplRenderer._get_axW   s    b#BB	r6   c                    t        |      }| j                  |      }t        ||      }t        j                  ||dd|      }|j                  |       d|_        y)a  Plot filled contours on a single Axes.

        Args:
            filled (sequence of arrays): Filled contour data as returned by
                :meth:`~.ContourGenerator.filled`.
            fill_type (FillType or str): Type of :meth:`~.ContourGenerator.filled` data as returned
                by :attr:`~.ContourGenerator.fill_type`, or string equivalent
            ax (int or Maplotlib Axes, optional): Which axes to plot on, default ``0``.
            color (str, optional): Color to plot with. May be a string color or the letter ``"C"``
                followed by an integer in the range ``"C0"`` to ``"C9"`` to use a color from the
                ``tab10`` colormap. Default ``"C0"``.
            alpha (float, optional): Opacity to plot with, default ``0.7``.
        noner   
facecolors
edgecolorslwalphaTN)r   rJ   r   mcollectionsPathCollectionadd_collectionr=   )r+   filled	fill_typer3   colorrQ   paths
collections           r4   rU   zMplRenderer.filled\   sZ    * !+	\\"#FI6!00e1EK

*%!r6   c                   | j                  |      }| j                  ||      \  }}||d} |j                  |||j                  |j                  fi | |dkD  r[d|ddddf   |ddddf   z   |ddddf   z   |ddddf   z   z  }	d|ddddf   |ddddf   z   |ddddf   z   |ddddf   z   z  }
||d<    |j                  t	        j
                  |ddddf   |	|ddddf   f      j                  d      t	        j
                  |ddddf   |
|ddddf   f      j                  d      t	        j
                  |ddddf   |	|ddddf   f      j                  d      t	        j
                  |ddddf   |
|ddddf   f      j                  d      fi | ||j                  ||||d	d
       d|_        y)a  Plot quad grid lines on a single Axes.

        Args:
            x (array-like of shape (ny, nx) or (nx,)): The x-coordinates of the grid points.
            y (array-like of shape (ny, nx) or (ny,)): The y-coordinates of the grid points.
            ax (int or Matplotlib Axes, optional): Which Axes to plot on, default ``0``.
            color (str, optional): Color to plot grid lines, default ``"black"``.
            alpha (float, optional): Opacity to plot lines with, default ``0.1``.
            point_color (str, optional): Color to plot grid points or ``None`` if grid points
                should not be plotted, default ``None``.
            quad_as_tri_alpha (float, optional): Opacity to plot ``quad_as_tri`` grid, default 0.

        Colors may be a string color or the letter ``"C"`` followed by an integer in the range
        ``"C0"`` to ``"C9"`` to use a color from the ``tab10`` colormap.

        Warning:
            ``quad_as_tri_alpha > 0`` plots all quads as though they are unmasked.
        )rW   rQ   r   g      ?Nr?   rQ   )   r[   o)rW   rQ   markerrP   T)rJ   _grid_as_2dplotTnpstackreshaper=   )r+   xyr3   rW   rQ   point_colorquad_as_tri_alphar1   xmidymids              r4   gridzMplRenderer.gridy   s.   8 \\"1%1+05!A1acc133)&)q 3B38qSbSz1Acrc12gJ>12qr6JKD3B38qSbSz1Acrc12gJ>12qr6JKD/F7OBGG!CRC"H+tQqr12vY78@@I!CRC"H+tQqr12vY78@@I!ABG*dAcrc12gJ78@@I!ABG*dAcrc12gJ78@@I	
  "GGAq5GK!r6   c                    t        |      }| j                  |      }t        ||      }t        j                  |d|||      }|j                  |       d|_        y)aW  Plot contour lines on a single Axes.

        Args:
            lines (sequence of arrays): Contour line data as returned by
                :meth:`~.ContourGenerator.lines`.
            line_type (LineType or str): Type of :meth:`~.ContourGenerator.lines` data as returned
                by :attr:`~.ContourGenerator.line_type`, or string equivalent.
            ax (int or Matplotlib Axes, optional): Which Axes to plot on, default ``0``.
            color (str, optional): Color to plot lines. May be a string color or the letter ``"C"``
                followed by an integer in the range ``"C0"`` to ``"C9"`` to use a color from the
                ``tab10`` colormap. Default ``"C0"``.
            alpha (float, optional): Opacity to plot lines with, default ``1.0``.
            linewidth (float, optional): Width of lines, default ``1``.
        rL   rM   TN)r   rJ   r   rR   rS   rT   r=   )	r+   lines	line_typer3   rW   rQ   	linewidthrX   rY   s	            r4   rm   zMplRenderer.lines   sZ    . !+	\\""5)4!00f9ES

*%!r6   c                    t         j                  j                  |      }|t         j                  j                  u ry| j	                  |      }| j                  ||      \  }}|j                  ||   ||   d|       y)a  Plot masked out grid points as circles on a single Axes.

        Args:
            x (array-like of shape (ny, nx) or (nx,)): The x-coordinates of the grid points.
            y (array-like of shape (ny, nx) or (ny,)): The y-coordinates of the grid points.
            z (masked array of shape (ny, nx): z-values.
            ax (int or Matplotlib Axes, optional): Which Axes to plot on, default ``0``.
            color (str, optional): Circle color, default ``"black"``.
        Nr]   )c)rb   magetmasknomaskrJ   r_   r`   )r+   re   rf   zr3   rW   masks          r4   rv   zMplRenderer.mask   si    " uu}}Q255<<\\"1%1
$4#/r6   c                ^    | j                          | j                  j                  ||       y)zSave plots to SVG or PNG file.

        Args:
            filename (str): Filename to save to.
            transparent (bool, optional): Whether background should be transparent, default
                ``False``.
        )transparentN)rE   r   savefig)r+   filenamerx   s      r4   savezMplRenderer.save   s%     			(<r6   c                    | j                          t        j                         }| j                  j	                  |d       |j                  d       |S )zhSave plots to an ``io.BytesIO`` buffer.

        Return:
            BytesIO: PNG image buffer.
        png)formatr   )rE   ioBytesIOr   ry   seek)r+   bufs     r4   save_to_bufferzMplRenderer.save_to_buffer   s@     	jjl		#e,
r6   c                L    | j                          t        j                          y)zMShow plots in an interactive window, in the usual Matplotlib manner.
        N)rE   r'   showr:   s    r4   r   zMplRenderer.show   s     	
r6   c                    |r#| j                  |      j                  ||       y| j                  |      j                  |       y)a  Set the title of a single Axes.

        Args:
            title (str): Title text.
            ax (int or Matplotlib Axes, optional): Which Axes to set the title of, default ``0``.
            color (str, optional): Color to set title. May be a string color or the letter ``"C"``
                followed by an integer in the range ``"C0"`` to ``"C9"`` to use a color from the
                ``tab10`` colormap. Default is ``None`` which uses Matplotlib's default title color
                that depends on the stylesheet in use.
        )rW   N)rJ   	set_title)r+   titler3   rW   s       r4   r   zMplRenderer.title   s:     LL&&uE&:LL&&u-r6   c                   | j                  |      }| j                  ||      \  }}t        j                  |      }|j                  \  }}	t        |      D ]>  }
t        |	      D ].  }|j                  ||
|f   ||
|f   ||
|f   | ddd|d       0 @ |rt        |dz
        D ]  }
t        |	dz
        D ]  }t        j                  ||
|
dz   ||dz   f         }t        j                  ||
|
dz   ||dz   f         }t        j                  ||
|
dz   ||dz   f         }|j                  |||| ddd|d         yy)a  Show ``z`` values on a single Axes.

        Args:
            x (array-like of shape (ny, nx) or (nx,)): The x-coordinates of the grid points.
            y (array-like of shape (ny, nx) or (ny,)): The y-coordinates of the grid points.
            z (array-like of shape (ny, nx): z-values.
            ax (int or Matplotlib Axes, optional): Which Axes to plot on, default ``0``.
            color (str, optional): Color of added text. May be a string color or the letter ``"C"``
                followed by an integer in the range ``"C0"`` to ``"C9"`` to use a color from the
                ``tab10`` colormap. Default ``"green"``.
            fmt (str, optional): Format to display z-values, default ``".1f"``.
            quad_as_tri (bool, optional): Whether to show z-values at the ``quad_as_tri`` centers
                of quads.

        Warning:
            ``quad_as_tri=True`` shows z-values for all quads, even if masked.
         centerThavarW   clip_onr?      N)rJ   r_   rb   asarrayshaperangetextmean)r+   re   rf   ru   r3   rW   fmtquad_as_trinynxjixxyyzzs                  r4   z_valueszMplRenderer.z_values  s   6 \\"1%1JJqMBr 	3A2Y 3!Q$1a4Qq!tWcU FOh#T  33	3 2a4[ *r!t *A1QqS5!AaC%<1B1QqS5!AaC%<1B1QqS5!AaC%<1BGGBr3%pjh8SX$(  *	** r6   )r?   r?   	   r   TNN)r,   rI   r-   rI   r   tuple[float, float]r.   r   r/   
str | Noner    zdict[str, Any] | NonereturnNone)r   r   )r3   
Axes | intr   r   )r   C0ffffff?)rU   cpy.FillReturnrV   FillType | strr3   r   rW   strrQ   floatr   r   )r   black皙?Nr   )re   r   rf   r   r3   r   rW   r   rQ   r   rg   r   rh   r   r   r   )r   r         ?r?   )rm   cpy.LineReturnrn   LineType | strr3   r   rW   r   rQ   r   ro   r   r   r   )r   r   )re   r   rf   r   ru   z'ArrayLike | np.ma.MaskedArray[Any, Any]r3   r   rW   r   r   r   )F)rz   r   rx   r   r   r   )r   z
io.BytesIO)r   N)r   r   r3   r   rW   r   r   r   )r   greenz.1fF)re   r   rf   r   ru   r   r3   r   rW   r   r   r   r   r   r   r   )__name__
__module____qualname____doc____annotations__r5   r;   rE   rJ   rU   rk   rm   rv   r{   r   r   r   r    r6   r4   r   r      sJ    
L '-"-1     %	 
     +  
 8!	% "" "" 	"
 " " 
"B "&#$-"-" -" 	-"
 -" -"  -" !-" 
-"f "" "" 	"
 " " " 
"H 00 0 3	0
 0 0 
00	=
.* !**** ** 	**
 ** ** ** ** 
**r6   r   c                  :     e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 d fdZ xZS )MplTestRendererzTest renderer implemented using Matplotlib.

    No whitespace around plots and no spines/ticks displayed.
    Uses Agg backend, so can only save to file/buffer, cannot call ``show()``.
    c                    ddddddd}t         |   |||dd|       | j                  D ]F  }|j                  d       |j	                  d       |j                  g        |j                  g        H d| _        y )	Ng{Gz?gGz?)leftrighttopbottomwspacehspaceTAgg)r.   r/   r            F)superr5   r   set_xmarginset_ymargin
set_xticks
set_yticksr   )r+   r,   r-   r   gridspecr3   	__class__s         r4   r5   zMplTestRenderer.__init__?  s     
 	5'dEx 	 	
 ** 	BNN3NN3MM"MM"		 !r6   )r?   r?   r   )r,   rI   r-   rI   r   r   r   r   )r   r   r   r   r5   __classcell__r   s   @r4   r   r   9  sC     '-	!! ! %	!
 
! !r6   r   c                  d    e Zd ZdZ	 	 	 	 d		 	 	 	 	 	 	 	 	 d
 fdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ		 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
 xZS )MplDebugRendererzDebug renderer implemented using Matplotlib.

    Extends ``MplRenderer`` to add extra information to help in debugging such as markers, arrows,
    text, etc.
    c                *    t         |   ||||       y rG   )r   r5   )r+   r,   r-   r   r.   r   s        r4   r5   zMplDebugRenderer.__init__`  s     	w
;r6   c                l   d||z   z  }||z
  }|t        j                  t        j                  ||            z  }t        j                  |d   |d    f      }	t        j                  ||dz  |	z
  |z  z
  ||dz  |z  z   ||dz  |	z   |z  z
  f      }
|j                  |
d d df   |
d d df   d||       y )Ng      ?r?   r   -rq   rQ   )rb   sqrtdotr   rc   r`   )r+   r3   
line_startline_endrW   rQ   
arrow_sizemidalongr   arrows              r4   _arrowzMplDebugRenderer._arrowi  s     :():%u-..

E!HuQxi0159u$j00%)J&&59u$j00
 
 	adU1a4[#eDr6   c                   t        |      }t        | 	  |||||       ||y | j                  |      }t	        ||t
        j                        }|t        | D ]  \  }}|	t        |      D ]p  \  }}||| }|j                  |d d df   |d d df   ||       |
dkD  s4t        |      }t        |dz
        D ]!  }| j                  |||   ||dz      |||
       # r  |t        | D ]  \  }}|	t        j                  |d   t              }d||dd  dz
  <   |	
|d d }d||<   |j                  |d d df   |   |d d df   |   d||       |	k|j                  |d d df      |d d df   |   d|	|        y y )	Nr   r?   r   r   r[   )dtypeFr]   )r   r   rU   rJ   r
   r   ChunkCombinedOffsetzipr   r`   rB   r   r   rb   onesr   )r+   rU   rV   r3   rW   rQ   
line_color
line_alpharg   start_point_colorr   pointsoffsetsstartendxysnr   rv   start_indicesr   s                       r4   rU   zMplDebugRenderer.filled}  s    !+	vy"eU;+"5\\"	83O3OP !#&< 
b>"*7"3 bJE3 s+CGGC1Is1a4yJjGQ!C'H!&qs bA KKCFC!Hj*V`abb
b "#&< C>wwwr{$7&+WQR[]#$0$+CRLM*/D'1a4L&q!tT(:C;V`  b %0GGF1a4L71m9TVY/z  CC #r6   c
           
     ~   t        |      }t        | 	  ||||||       |	dk(  r|y | j                  |      }t	        ||t
        j                        }
t        rt        t        j                  |
      }
|	dkD  rB|
D ]=  }t        t        |      dz
        D ]!  }| j                  |||   ||dz      |||	       # ? ||
D ]z  }d}t        |      }|E|j                  |d   |d   d||       d}|d   d   |d   d   k(  r|d   d   |d   d   k(  r|dz  }|j                  |||df   |||df   d||       | y y )	Nr   r?   r   )r   r   )r   r?   r]   r   r[   )r   r   rm   rJ   r   r	   Separater   r   cpyLineReturn_Separater   rB   r   r`   )r+   rm   rn   r3   rW   rQ   ro   rg   r   r   separate_linesliner   start_index	end_indexr   s                  r4   rm   zMplDebugRenderer.lines  s    !+	eYE5)D!4\\"&ui9J9JK!#"9"9>JN& Rs4y{+ RAKKDGT!A#YujQRR "& 	.I	$0GGDJT
C;LTYGZ"#KAwqzT"Xa[0T!WQZ48A;5N!Q	[2A56[=RTU=U8VX[u  .	. #r6   c                >   | j                  |      }| j                  ||      \  }}t        j                  |      }|j                  \  }}t        |      D ]E  }t        |      D ]5  }	|	||z  z   }
|j                  |||	f   |||	f   t        |
      dd|d       7 G y )Nr   r   Tr   rJ   r_   rb   r   r   r   r   r   )r+   re   rf   ru   r3   rW   r   r   r   r   quads              r4   point_numberszMplDebugRenderer.point_numbers  s     \\"1%1JJqMBr 	&A2Y &1R4x!Q$1a4#d)EQV $  &&	&r6   c                   | j                  |      }| j                  ||      \  }}t        j                  |      }|j                  \  }}t        d|      D ]  }t        d|      D ]u  }	|	||z  z   }
||dz
  |dz   |	dz
  |	dz   f   j                         }||dz
  |dz   |	dz
  |	dz   f   j                         }|j                  ||t        |
      dd|d       w  y )Nr?   r   Tr   )	rJ   r_   rb   r   r   r   r   r   r   )r+   re   rf   ru   r3   rW   r   r   r   r   r   ri   rj   s                r4   quad_numberszMplDebugRenderer.quad_numbers  s     \\"1%1JJqMBq" 	dA1b\ d1R4x1QqS!A#ac')*//11QqS!A#ac')*//1dCI(xu^bc	d	dr6   c                d   | j                  |      }| j                  ||      \  }}t        j                  |      }|j                  \  }}	t        |      D ]X  }
t        |	      D ]H  }||
|f   }|||kD  rd}n
||kD  rd}nd}|j                  ||
|f   ||
|f   t        |      dd|d       J Z y )Nr   r?   r   r   r   Tr   r   )r+   re   rf   ru   lower_levelupper_levelr3   rW   r   r   r   r   r   z_levels                 r4   z_levelszMplDebugRenderer.z_levels  s     \\"1%1JJqMBr 
	&A2Y 	&q!tW*rK/?G+%GG!Q$1a4#g,6hV[ $  &	&
	&r6   )r?   r?   r   T)
r,   rI   r-   rI   r   r   r.   r   r   r   )r3   r   r   cpy.CoordinateArrayr   r   rW   r   rQ   r   r   r   r   r   )r   C1r   r   r   r   redr   )rU   r   rV   r   r3   r   rW   r   rQ   r   r   r   r   r   rg   r   r   r   r   r   r   r   )r   r   r   r?   r   r   r   )rm   r   rn   r   r3   r   rW   r   rQ   r   ro   r   rg   r   r   r   r   r   r   r   )r   r   )re   r   rf   r   ru   r   r3   r   rW   r   r   r   )r   blue)Nr   r   )re   r   rf   r   ru   r   r   r   r   zfloat | Noner3   r   rW   r   r   r   )r   r   r   r   r5   r   rU   rm   r   r   r   r   r   s   @r4   r   r   Z  s    '-<< < %	<
 < 
<EE (E &	E
 E E E 
E0 !&3C3C "3C 	3C
 3C 3C 3C 3C 3C 3C 3C 
3Cr !&&.&. "&. 	&.
 &. &. &. &. &. &. 
&.Z && & 	&
 & & 
&. dd d 	d
 d d 
d2 %)&& & 	&
 & "& & & 
&r6   r   )-
__future__r   r   	itertoolsr   typingr   r   r   matplotlib.collectionscollectionsrR   matplotlib.pyplotpyplotr'   numpyrb   	contourpyr   r	   contourpy.convertr
   r   contourpy.enum_utilr   r   contourpy.util.mpl_utilr   r   contourpy.util.rendererr   collections.abcr   matplotlib.axesr   matplotlib.figurer   numpy.typingr   contourpy._contourpy
_contourpyr   r   r   r   r   r6   r4   <module>r     sh    " 	  + + -   ( ; : K ,($(&&[*( [*|!k !B}&{ }&r6   