U
    ½mœd±\  ã                   @  sà   d dl mZ d dl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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  G d
d„ deƒZ!G dd„ de!ƒZ"G dd„ de!ƒZ#dS )é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚcast)ÚFillTypeÚLineType)Úfilled_to_mpl_pathsÚlines_to_mpl_pathsÚmpl_codes_to_offsets)ÚRenderer)ÚAxes)ÚFigure)Ú	ArrayLikec                
   @  s@  e Zd ZU ded< ded< ded< dGddddddddœdd„Zddœdd„Zddœdd„Zdddœdd„ZdHdd dd!d"dd#œd$d%„ZdId(d(dd!d"dd"dd)œd*d+„Z	dJd-d.dd!d"d"dd/œd0d1„Z
dKd(d(d2dd!dd3œd4d5„ZdLd!ddd7œd8d9„Zd:dœd;d<„Zddœd=d>„ZdMd!dddd?œd@dA„ZdNd(d(d(dd!d!dddDœdEdF„Zd
S )OÚMplRendererr   Ú_axesr   Ú_figÚboolÚ_want_tighté   ©é	   r   TNÚintútuple[float, float]z
str | Nonezdict[str, Any] | NoneÚNone)ÚnrowsÚncolsÚfigsizeÚ
show_frameÚbackendÚgridspec_kwÚreturnc                 C  sŽ   |d k	rdd l }| |¡ t|dddd�}|d k	r<||d< ntdd�|d< tj||f|Ž\| _}	|	 ¡ | _|s„| jD ]}
|
 d	¡ qtd| _	d S )
Nr   FT)r   ZsqueezeZsharexZshareyr   Úequal)ZaspectZ
subplot_kwÚoff)
Ú
matplotlibZuseÚdictÚpltZsubplotsr   Úflattenr   Zaxisr   )Úselfr   r   r   r   r   r   r#   ÚkwargsZaxesÚax© r*   úT/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/contourpy/util/mpl_renderer.pyÚ__init__'   s    	



zMplRenderer.__init__)r    c                 C  s   t | dƒrt | j¡ d S )Nr   )Úhasattrr%   Úcloser   ©r'   r*   r*   r+   Ú__del__B   s    
zMplRenderer.__del__c                 C  sL   | j D ]"}t|ddƒr|jdd� d|_q| jrHt| j ƒdkrH| j ¡  d S )NÚ_need_autoscaleFT)Ztightr   )r   ÚgetattrZautoscale_viewr1   r   Úlenr   Ztight_layout©r'   r)   r*   r*   r+   Ú
_autoscaleF   s    
zMplRenderer._autoscaleú
Axes | int)r)   r    c                 C  s   t |tƒr| j| }|S ©N)Ú
isinstancer   r   r4   r*   r*   r+   Ú_get_axQ   s    

zMplRenderer._get_axr   ÚC0çffffffæ?úcpy.FillReturnr   ÚstrÚfloat)ÚfilledÚ	fill_typer)   ÚcolorÚalphar    c                 C  s<   |   |¡}t||ƒ}tj||dd|d�}| |¡ d|_dS )aí  Plot filled contours on a single Axes.

        Args:
            filled (sequence of arrays): Filled contour data as returned by
                :func:`~contourpy.ContourGenerator.filled`.
            fill_type (FillType): Type of ``filled`` data, as returned by
                :attr:`~contourpy.ContourGenerator.fill_type`.
            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   ©Z
facecolorsZ
edgecolorsÚlwrB   TN)r9   r   ÚmcollectionsÚPathCollectionÚadd_collectionr1   )r'   r?   r@   r)   rA   rB   ÚpathsÚ
collectionr*   r*   r+   r?   V   s    

    ÿ
zMplRenderer.filledÚblackçš™™™™™¹?r   )ÚxÚyr)   rA   rB   Úpoint_colorÚquad_as_tri_alphar    c                 C  sþ  |   |¡}|  ||¡\}}t||d�}|j|||j|jf|Ž |dk�rÔd|dd…dd…f |dd…dd…f  |dd…dd…f  |dd…dd…f   }	d|dd…dd…f |dd…dd…f  |dd…dd…f  |dd…dd…f   }
||d< |jt |dd…dd…f |	|dd…dd…f f¡ d¡t |dd…dd…f |
|dd…dd…f f¡ d¡t |dd…dd…f |	|dd…dd…f f¡ d¡t |dd…dd…f |
|dd…dd…f f¡ d¡f|Ž |dk	�rô|j||||d	dd
� d|_dS )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.
        )rA   rB   r   g      Ð?Néÿÿÿÿr   rB   )é   rQ   Úo)rA   rB   ÚmarkerrE   T)	r9   Ú_grid_as_2dr$   ÚplotÚTÚnpÚstackZreshaper1   )r'   rM   rN   r)   rA   rB   rO   rP   r(   ÚxmidÚymidr*   r*   r+   Úgridr   s&    

TT4444üû
zMplRenderer.gridç      ð?úcpy.LineReturnr   )ÚlinesÚ	line_typer)   rA   rB   Ú	linewidthr    c           	      C  s<   |   |¡}t||ƒ}tj|d|||d�}| |¡ d|_dS )a6  Plot contour lines on a single Axes.

        Args:
            lines (sequence of arrays): Contour line data as returned by
                :func:`~contourpy.ContourGenerator.lines`.
            line_type (LineType): Type of ``lines`` data, as returned by
                :attr:`~contourpy.ContourGenerator.line_type`.
            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``.
        rC   rD   TN)r9   r	   rF   rG   rH   r1   )	r'   r_   r`   r)   rA   rB   ra   rI   rJ   r*   r*   r+   r_   ¡   s    

    ÿ
zMplRenderer.linesz'ArrayLike | np.ma.MaskedArray[Any, Any]©rM   rN   Úzr)   rA   r    c                 C  sT   t j |¡}|t jjkrdS |  |¡}|  ||¡\}}|j|| || d|d� dS )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"``.
        NrS   )Úc)rX   ÚmaZgetmaskZnomaskr9   rU   rV   )r'   rM   rN   rc   r)   rA   Úmaskr*   r*   r+   rf   ¿   s    
zMplRenderer.maskF)ÚfilenameÚtransparentr    c                 C  s   |   ¡  | jj||d� dS )zÞSave plots to SVG or PNG file.

        Args:
            filename (str): Filename to save to.
            transparent (bool, optional): Whether background should be transparent, default
                ``False``.
        )rh   N)r5   r   Úsavefig)r'   rg   rh   r*   r*   r+   Úsave×   s    zMplRenderer.savez
io.BytesIOc                 C  s.   |   ¡  t ¡ }| jj|dd� | d¡ |S )zhSave plots to an ``io.BytesIO`` buffer.

        Return:
            BytesIO: PNG image buffer.
        Zpng)Úformatr   )r5   ÚioÚBytesIOr   ri   Úseek)r'   Úbufr*   r*   r+   Úsave_to_bufferâ   s
    
zMplRenderer.save_to_bufferc                 C  s   |   ¡  t ¡  dS )zMShow plots in an interactive window, in the usual Matplotlib manner.
        N)r5   r%   Úshowr/   r*   r*   r+   rq   î   s    zMplRenderer.show)Útitler)   rA   r    c                 C  s.   |r|   |¡j||d� n|   |¡ |¡ dS )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.
        )rA   N)r9   Ú	set_title)r'   rr   r)   rA   r*   r*   r+   rr   ô   s    zMplRenderer.titleÚgreenú.1f)rM   rN   rc   r)   rA   ÚfmtÚquad_as_trir    c                 C  s2  |   |¡}|  ||¡\}}t |¡}|j\}}	t|ƒD ]H}
t|	ƒD ]:}|j||
|f ||
|f ||
|f |› ›dd|dd� qBq6|�r.t|d ƒD ]š}
t|	d ƒD ]ˆ}t ||
|
d …||d …f ¡}t ||
|
d …||d …f ¡}t ||
|
d …||d …f ¡}|j||||› ›dd|dd� q¢q’dS )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©ZhaÚvarA   Zclip_onr   é   N)r9   rU   rX   ÚasarrayÚshapeÚrangeÚtextÚmean)r'   rM   rN   rc   r)   rA   rv   rw   ÚnyÚnxÚjÚiZxxÚyyÚzzr*   r*   r+   Úz_values  s&    


, ÿ
"""ÿzMplRenderer.z_values)r   r   r   TNN)r   r:   r;   )r   rK   rL   Nr   )r   r:   r]   r   )r   rK   )F)r   N)r   rt   ru   F)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r,   r0   r5   r9   r?   r\   r_   rf   rj   rp   rq   rr   r‡   r*   r*   r*   r+   r      sP   
      ù	   ú      ø3    ù#  ú    ør   c                      s.   e Zd ZdZd
dddddœ‡ fdd	„Z‡  ZS )ÚMplTestRendererz¾Test 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()``.
    r   r   r   r   r   )r   r   r   r    c                   sh   dddddddœ}t ƒ j|||dd|d� | jD ],}| d¡ | d¡ | g ¡ | g ¡ q0d| _d S )	Ng{®Gáz„?g®Gáz®ï?)ÚleftÚrightÚtopÚbottomZwspaceZhspaceTZAgg)r   r   r   ç        F)Úsuperr,   r   Zset_xmarginZset_ymarginZ
set_xticksZ
set_yticksr   )r'   r   r   r   Zgridspecr)   ©Ú	__class__r*   r+   r,   7  s*    ú     ÿ



zMplTestRenderer.__init__)r   r   r   )rˆ   r‰   rŠ   Ú__doc__r,   Ú__classcell__r*   r*   r“   r+   rŒ   1  s
      ürŒ   c                      s  e Zd ZdZd:dddddd	œ‡ fd
d„Zddddddddœdd„Zddddœdd„Zddddœdd„Zd;ddd%ddddddddd&œ‡ fd'd(„Zd<ddd%dddddddd*œ
‡ fd+d,„Z	d=d-d-d-d%ddd.œd/d0„Z
d>d-d-d-d%ddd.œd2d3„Zd?d-d-d-dd6d%ddd7œd8d9„Z‡  ZS )@ÚMplDebugRendererz¤Debug renderer implemented using Matplotlib.

    Extends ``MplRenderer`` to add extra information to help in debugging such as markers, arrows,
    text, etc.
    r   r   Tr   r   r   r   )r   r   r   r   r    c                   s   t ƒ  ||||¡ d S r7   )r’   r,   )r'   r   r   r   r   r“   r*   r+   r,   X  s    zMplDebugRenderer.__init__r   zcpy.CoordinateArrayr=   r>   )r)   Ú
line_startÚline_endrA   rB   Ú
arrow_sizer    c                 C  s®   d||  }|| }|t  t  ||¡¡ }t  |d |d  f¡}	t  ||d |	 |  ||d |  ||d |	 |  f¡}
|j|
d d …df |
d d …df d||d� d S )Ng      à?r   r   ú-©rd   rB   )rX   ÚsqrtÚdotr|   rY   rV   )r'   r)   r˜   r™   rA   rB   rš   ÚmidZalongrŽ   Úarrowr*   r*   r+   Ú_arrowa  s    	ýzMplDebugRenderer._arrowr<   r   z2tuple[list[cpy.PointArray], list[cpy.OffsetArray]])r?   r@   r    c                 C  st  |t jkr8trttj|ƒ}|d }dd„ |d D ƒ}�n4|t jkrztrRttj|ƒ}dd„ |d D ƒ}dd„ |d D ƒ}�nò|t jkr¨tr”ttj	|ƒ}|d }|d }�nÄ|t j
krêtrÂttj|ƒ}dd„ |d D ƒ}dd„ |d D ƒ}�n‚|t jk�r’t�rttj|ƒ}g }g }t|Ž D ]v\}}}|d k�r0�qt�rN|d k	�rJ|d k	�sNt‚|t ||dd	… ¡7 }t ||dd	… ¡}|d
d„ |D ƒ7 }�qnÚ|t jk�r\t�r°ttj|ƒ}g }g }t|Ž D ]˜\}}	}|d k�rØ�qÀt�rö|	d k	�rò|d k	�söt‚tt|ƒd ƒD ]N}
|	||
 ||
d  d … }| ||d |d	 … ¡ | ||d  ¡ �q�qÀntd|› d�ƒ‚||fS )Nr   c                 S  s   g | ]}t |ƒ‘qS r*   ©r
   ©Ú.0Úcodesr*   r*   r+   Ú
<listcomp>~  s     zKMplDebugRenderer._filled_to_lists_of_points_and_offsets.<locals>.<listcomp>r   c                 S  s   g | ]}|d k	r|‘qS r7   r*   ©r¤   Úpointsr*   r*   r+   r¦   ‚  s      c                 S  s   g | ]}|d k	rt |ƒ‘qS r7   r¢   r£   r*   r*   r+   r¦   ƒ  s      c                 S  s   g | ]}|d k	r|‘qS r7   r*   r§   r*   r*   r+   r¦   Œ  s      c                 S  s   g | ]}|d k	r|‘qS r7   r*   )r¤   Úoffsetsr*   r*   r+   r¦   �  s      rQ   c                 S  s   g | ]}t |ƒ‘qS r*   r¢   r£   r*   r*   r+   r¦   š  s     zRendering FillType ú not implemented)r   Z	OuterCoder   r   ÚcpyZFillReturn_OuterCodeÚChunkCombinedCodeZFillReturn_ChunkCombinedCodeZOuterOffsetZFillReturn_OuterOffsetÚChunkCombinedOffsetZFillReturn_ChunkCombinedOffsetZChunkCombinedCodeOffsetZ"FillReturn_ChunkCombinedCodeOffsetÚzipÚAssertionErrorrX   ÚsplitZChunkCombinedOffsetOffsetZ$FillReturn_ChunkCombinedOffsetOffsetr~   r3   ÚappendÚRuntimeError)r'   r?   r@   Ú
all_pointsÚall_offsetsr¨   r¥   Zouter_offsetsZ	all_codesr©   r„   Zoffsr*   r*   r+   Ú&_filled_to_lists_of_points_and_offsetsu  sb    





z7MplDebugRenderer._filled_to_lists_of_points_and_offsetsr^   r   zlist[cpy.PointArray])r_   r`   r    c           	   	   C  sh  |t jkr"trttj|ƒ}|}�nB|t jkrHtr<ttj|ƒ}|d }�n|t jkrÎtrbttj	|ƒ}g }t
|Ž D ]\\}}|d k	rntrŽ|d k	sŽt‚t|ƒ}tt|ƒd ƒD ]"}| ||| ||d  … ¡ q¦qnn–|t jk�rTtrêttj|ƒ}g }t
|Ž D ]Z\}}|d k	röt�r|d k	�st‚tt|ƒd ƒD ]$}| ||| ||d  … ¡ �q*qöntd|› d�ƒ‚|S )Nr   r   zRendering LineType rª   )r   ZSeparater   r   r«   ZLineReturn_SeparateZSeparateCodeZLineReturn_SeparateCoder¬   ZLineReturn_ChunkCombinedCoder®   r¯   r
   r~   r3   r±   r­   ZLineReturn_ChunkCombinedOffsetr²   )	r'   r_   r`   Ú	all_linesr¨   r¥   r©   r„   r´   r*   r*   r+   Ú_lines_to_list_of_points®  s>    


$&z)MplDebugRenderer._lines_to_list_of_pointsr   ÚC1r;   r:   ÚredrL   r6   )r?   r@   r)   rA   rB   Ú
line_colorÚ
line_alpharO   Ústart_point_colorrš   r    c                   sÔ  t ƒ  |||||¡ |d kr(|d kr(d S |  |¡}|  ||¡\}}|d k	rút||ƒD ]¤\}}t|d d… |dd … ƒD ]€\}}|||… }|j|d d …df |d d …df ||d� |
dkrvt|ƒ}t|d ƒD ]$}|  ||| ||d  |||
¡ qÐqvqT|d k	�rÐt||ƒD ]À\}}t	j
|d td�}d||dd … d < |	d k	�rZ|d d… }d||< |j|d d …df | |d d …df | d||d� |	d k	�r|j|d d …df | |d d …df | d|	|d� �qd S )	NrQ   r   r   rœ   r‘   )ZdtypeFrS   )r’   r?   r9   rµ   r®   rV   r3   r~   r¡   rX   Zonesr   )r'   r?   r@   r)   rA   rB   rº   r»   rO   r¼   rš   r³   r´   r¨   r©   ÚstartÚendZxysÚnr„   rf   Zstart_indicesr“   r*   r+   r?   Ó  sB    
"*&

    ÿ
* ÿzMplDebugRenderer.filledr]   )
r_   r`   r)   rA   rB   ra   rO   r¼   rš   r    c
              
     s>  t ƒ  ||||||¡ |	dkr*|d kr*d S |  |¡}|  ||¡}
|	dkrˆ|
D ]:}tt|ƒd ƒD ]$}|  ||| ||d  |||	¡ q`qL|d k	�r:|
D ]¢}d}t|ƒ}|d k	�r|j|d |d d||d� d}|d d |d d k�r|d d |d d k�r|d8 }|j|||…df |||…df d||d� q–d S )	Nr‘   r   r   )r   r   )r   r   rS   rœ   rQ   )r’   r_   r9   r·   r~   r3   r¡   rV   )r'   r_   r`   r)   rA   rB   ra   rO   r¼   rš   r¶   Úliner„   Ústart_indexZ	end_indexr“   r*   r+   r_     s,    
$

4" ÿzMplDebugRenderer.linesr   rb   c                 C  s†   |   |¡}|  ||¡\}}t |¡}|j\}}t|ƒD ]J}t|ƒD ]<}	|	||  }
|j|||	f |||	f t|
ƒdd|dd� qBq6d S )NrŽ   r�   Try   )r9   rU   rX   r|   r}   r~   r   r=   )r'   rM   rN   rc   r)   rA   r�   r‚   rƒ   r„   Úquadr*   r*   r+   Úpoint_numbers(  s    


$ÿzMplDebugRenderer.point_numbersÚbluec                 C  sÊ   |   |¡}|  ||¡\}}t |¡}|j\}}td|ƒD ]Œ}td|ƒD ]|}	|	||  }
||d |d …|	d |	d …f  ¡ }||d |d …|	d |	d …f  ¡ }|j||t|
ƒdd|dd� qFq8d S )Nr   rx   Try   )	r9   rU   rX   r|   r}   r~   r€   r   r=   )r'   rM   rN   rc   r)   rA   r�   r‚   rƒ   r„   rÂ   rZ   r[   r*   r*   r+   Úquad_numbers:  s    


((zMplDebugRenderer.quad_numbersNrt   zfloat | None)rM   rN   rc   Úlower_levelÚupper_levelr)   rA   r    c                 C  sª   |   |¡}|  ||¡\}}t |¡}|j\}}	t|ƒD ]n}
t|	ƒD ]`}||
|f }|d k	rh||krhd}n||krvd}nd}|j||
|f ||
|f |dd|dd� qBq6d S )Nr{   r   r   r�   r�   Try   )r9   rU   rX   r|   r}   r~   r   )r'   rM   rN   rc   rÆ   rÇ   r)   rA   r�   r‚   rƒ   r„   r†   Zz_levelr*   r*   r+   Úz_levelsM  s    



 ÿzMplDebugRenderer.z_levels)r   r   r   T)r   r¸   r;   r:   r;   r:   r¹   rL   )r   r:   r]   r   r:   r¹   rL   )r   r¹   )r   rÄ   )Nr   rt   )rˆ   r‰   rŠ   r•   r,   r¡   rµ   r·   r?   r_   rÃ   rÅ   rÈ   r–   r*   r*   r“   r+   r—   R  sH       û	9)        õ(4       ö&*  ú  ú   ør—   )$Ú
__future__r   rl   Útypingr   r   r   Zmatplotlib.collectionsÚcollectionsrF   Zmatplotlib.pyplotZpyplotr%   ÚnumpyrX   Z	contourpyr   r   Zcontourpy.util.mpl_utilr   r	   r
   Zcontourpy.util.rendererr   Zmatplotlib.axesr   Zmatplotlib.figurer   Znumpy.typingr   Zcontourpy._contourpyZ
_contourpyr«   r   rŒ   r—   r*   r*   r*   r+   Ú<module>   s$     !