o
    tBh&                     @   sL  d dl Z d dlZd dlmZ d dlmZmZ d dlZd dl	m
Z
mZmZmZm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 d
lmZ dd Zdd Zdd Zdd Z edgdddd Z!dd Z"dd Z#ej$%ddd Z&dd  Z'd!d" Z(d#d$ Z)ej*d%d& Z+d'd( Z,d)d* Z-d+d, Z.d-d. Z/d/d0 Z0d1d2 Z1dS )3    N)assert_array_almost_equal)ImageTiffTags)collectionspathpyplot
transformsrcParams)RendererAgg)Figure)imread)Path)image_comparison)IdentityTransformc                  C   s   t ddg} | d | jd t }| j||  dd |d | j||  dd |d t	t
t|d d	d
d d S )N   皙?)r   r   r         ?none)	facecolor	edgecolorr   r   r   )              ?r   r      )decimal)r   set_facecolorpatch	set_alphaioBytesIOsavefigget_facecolorseekr   tupler   )figbuf r&   p/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/matplotlib/tests/test_agg.pytest_repeated_save_with_alpha   s$   



r(   c               
   C   sh   t  } t \}}ttddgddgddgddgddggg}|| |	dd t
|  d S )Ni   
   gMbP?r   )r   r   pltsubplotsr   PathCollectionr   r   
add_artistset_xlimr    )bufffax
collectionr&   r&   r'   !test_large_single_path_collection2   s   (
r5   c                  C   sV   t d\} }d}t|}|| |||d |d  t }| j|dd d S )Nr     g?g333333?pngformat)	r,   r-   nparangesemilogxfill_betweenr   r   r    )r$   r3   stepsdatar%   r&   r&   r'   test_marker_with_nan@   s   

r@   c                  C   sR   t  } t }| }td}|d d d  d9  < || |j| dd d S )N順    r7   r8   )r   r   r   r-   r:   onesplotr    )r1   r$   r3   pointsr&   r&   r'   test_long_pathL   s   

rG   zagg_filter.pngT)remove_textc                     sr  dd d$fdd	G dd d} G dd	 d	| G fd
dd|  G  fddd| }t  \}}|jg dg ddddddddd	\}|jg dg ddddddddd	\}|d}||fD ];}| }| }	|||	\}
|
| tj| |j	dddd}|

| |
| d  |
| |
d  qc|d!d" |d!d" |jd# |jd# d S )%Nc                 S   sv   t jd| d  | |dd  | d| d  | d| d  f }t |}t j||  |dd}||d | d  S )NrB   r   r   rC   same)mode)r:   r_hanningconvolvesum)x
window_lenswyr&   r&   r'   smooth1dX   s   6
z!test_agg_filter.<locals>.smooth1dr   c                    s:   t t|dd d }t d| |} t d| |} | S )Nr   rB   r   r   )maxintr:   apply_along_axis)AsigmarP   )rT   r&   r'   smooth2d`   s   z!test_agg_filter.<locals>.smooth2dc                   @   s$   e Zd Zdd Zdd Zdd ZdS )z#test_agg_filter.<locals>.BaseFilterc                 S   s   dS )Nr   r&   selfdpir&   r&   r'   get_padh   s   z+test_agg_filter.<locals>.BaseFilter.get_padc                 S   s   t d)Nz"Should be overridden by subclasses)NotImplementedError)r\   
padded_srcr]   r&   r&   r'   process_imagek   s   z1test_agg_filter.<locals>.BaseFilter.process_imagec                 S   s@   |  |}t|||f||fdgd}| ||}|| | fS )Nr   constant)r^   r:   padra   )r\   imr]   rc   r`   	tgt_imager&   r&   r'   __call__n   s   
z,test_agg_filter.<locals>.BaseFilter.__call__N)__name__
__module____qualname__r^   ra   rf   r&   r&   r&   r'   
BaseFilterf   s    rj   c                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
z%test_agg_filter.<locals>.OffsetFilterr   c                 S   s
   || _ d S N)offsets)r\   rl   r&   r&   r'   __init__w   s   
z.test_agg_filter.<locals>.OffsetFilter.__init__c                 S   s   t t| jd | S )NH   )rV   rU   rl   r[   r&   r&   r'   r^   z      z-test_agg_filter.<locals>.OffsetFilter.get_padc                 S   sH   | j \}}tj|t|d | dd}tj|t|d |  dd}|S )Nrn   r   )axisr   )rl   r:   rollrV   )r\   r`   r]   oxoya1a2r&   r&   r'   ra   }   s   
z3test_agg_filter.<locals>.OffsetFilter.process_imageN)r   rg   rh   ri   rm   r^   ra   r&   r&   r&   r'   OffsetFilteru   s    
rw   c                       s.   e Zd ZdZdddZdd Z fdd	Zd
S )z'test_agg_filter.<locals>.GaussianFilterzSimple Gaussian filter.      ?r   r   r   c                 S   s   || _ || _|| _d S rk   )rY   alphacolor)r\   rY   rz   r{   r&   r&   r'   rm      s   
z0test_agg_filter.<locals>.GaussianFilter.__init__c                 S   s   t | jd d | S Nr   rn   )rV   rY   r[   r&   r&   r'   r^      ro   z/test_agg_filter.<locals>.GaussianFilter.get_padc                    sh   t |}| j|d d d d d df<  |d d d d df | j | jd | |d d d d df< |S r|   )r:   
empty_liker{   rz   rY   )r\   r`   r]   re   rZ   r&   r'   ra      s   
z5test_agg_filter.<locals>.GaussianFilter.process_imageN)rx   ry   )rg   rh   ri   __doc__rm   r^   ra   r&   r~   r&   r'   GaussianFilter   s
    
r   c                       s,   e Zd Zd fdd	Zdd Zdd	 Zd
S )z)test_agg_filter.<locals>.DropShadowFilter333333?ry   r   c                    s    |||| _ || _d S rk   )gauss_filteroffset_filter)r\   rY   rz   r{   rl   r   rw   r&   r'   rm      s   z2test_agg_filter.<locals>.DropShadowFilter.__init__c                 S   s   t | j|| j|S rk   )rU   r   r^   r   r[   r&   r&   r'   r^      s   
z1test_agg_filter.<locals>.DropShadowFilter.get_padc                 S   s    | j ||}| j||}|S rk   )r   ra   r   )r\   r`   r]   t1t2r&   r&   r'   ra      s   z7test_agg_filter.<locals>.DropShadowFilter.process_imageN)r   ry   r   rv   r&   r   r&   r'   DropShadowFilter   s    r   )皙?rx   ?)r   r   rx   zbo-brR   r)   r*   zLine 1)mecmfclwmewmslabel)rx   g?gffffff?zro-r   g      @g      rF   )rO   rS   unitsrx   Tr   r   F)r   )r,   r-   rE   	get_xdata	get_ydataupdate_frommtransformsoffset_copyget_transformfigureset_transform
set_zorder
get_zorderset_agg_filterset_rasterizedr0   set_ylimxaxisset_visibleyaxis)rj   r   r$   r3   line1line2gausslinexxyyshadowotr&   )r   rw   rT   rZ   r'   test_agg_filterV   s<   


r   c                  C   sN   t jdd} t }tt | | W d    d S 1 s w   Y  d S )N)i,  r6   )figsize)r,   r   r   r   pytestraises
ValueErrorr    )r$   r1   r&   r&   r'   test_too_large_image   s
   "r   c                  C   sd   t d} t \}}|| t|  |j  t \}}dtd< || t|  |j  d S )N   i   agg.path.chunksize)	ranger,   r-   rE   r:   sincanvasdrawr	   )rO   r$   r3   r&   r&   r'   test_chunksize   s   
r   Aggc                  C   sL   t g dg d t } t j| ddd t| }|jd dks$J d S )N)r   r   rB   )r   r   r   jpgr   )r9   r]   r]   )r   r   )r,   rE   r   r   r    r   openinfo)r%   rd   r&   r&   r'   test_jpeg_dpi   s
   
r   c                  C   s^   ddl m}  t }|  }|dd t j|dd|id t	|}|j
d dks-J d S )Nr   )PngInfoSoftwaretestr7   pnginfor9   
pil_kwargs)PIL.PngImagePluginr   r   r   add_textr,   r   r    r   r   r   )r   r%   r   rd   r&   r&   r'   test_pil_kwargs_png   s   
r   c                  C   sV   t  } ddi}t j| d|d t| }dd |j D }|d dks)J d S )Ndescriptionz
test imagetiffr   c                 S   s   i | ]\}}t j| j|qS r&   )r   TAGS_V2name).0kvr&   r&   r'   
<dictcomp>   s    z(test_pil_kwargs_tiff.<locals>.<dictcomp>ImageDescription)	r   r   r,   r   r    r   r   tag_v2items)r%   r   rd   tagsr&   r&   r'   test_pil_kwargs_tiff   s   
r   c                  C   sf   t  \} }|dgdgtddg tt | j	
  W d    d S 1 s,w   Y  d S )Nr   )r   r   )rB   r   )r,   r-   scatter	set_pathsr   r   r   r   	TypeErrorr   r   )r$   r3   r&   r&   r'   (test_draw_path_collection_error_handling   s
    "r   c            
      C   s   d} d}d| }d| }t d|| }t | | }d|d d d< t }t|||}| }|d |d tt 	||fj
}	d|	_|||	|fS )	NrA   i  r)      r   rB   r   r   )r:   linspacerD   r   r
   new_gcset_linewidthset_foregroundr   vstackTsimplify_threshold)
Nr]   rR   hrO   rS   idtragcpr&   r&   r'   chunk_limit_setup  s   

r   c                 C   sX   | \}}}}| d tjtdd |||| W d    d S 1 s%w   Y  d S )N/zhatched pathmatch)	set_hatchr   r   OverflowError	draw_pathr   r   r   r   r   r&   r&   r'   test_chunksize_hatch_fail  s
   
"r   c                 C   sP   | \}}}}t jtdd ||||d W d    d S 1 s!w   Y  d S )Nzfilled pathr   )r   r   r   )r   r   r   r   r   r&   r&   r'   test_chunksize_rgbFace_fail(  s   "r   c                 C   sT   | \}}}}d|_ tjtdd |||| W d    d S 1 s#w   Y  d S )NFzshould_simplify is Falser   )should_simplifyr   r   r   r   r   r&   r&   r'   test_chunksize_no_simplify_fail/  s
   "r   c                 C   V   | \}}}}dt d< tjtdd |||| W d    d S 1 s$w   Y  d S )Nr   r   z
Please setr   r	   r   r   r   r   r   r&   r&   r'   test_chunksize_zero6  
   "r   c                 C   r   )Ni@B r   Please reducer   r   r   r&   r&   r'   test_chunksize_too_big_to_chunk>  r   r   c                 C   r   )Ni_ r   r   r   r   r   r&   r&   r'   test_chunksize_toobig_chunksF  s
   "r   )2r   numpyr:   numpy.testingr   PILr   r   r   
matplotlibr   r   r   r,   r   r   r	   matplotlib.backends.backend_aggr
   matplotlib.figurer   matplotlib.imager   matplotlib.pathr   matplotlib.testing.decoratorsr   matplotlib.transformsr   r(   r5   r@   rG   r   r   r   markbackendr   r   r   r   fixturer   r   r   r   r   r   r   r&   r&   r&   r'   <module>   sB    

r

	
	
	