U
    ^»{jî4  ã                   @  s   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 d dlmZ d dl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 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&m'Z' G dd„ deƒZ(dS )é    )ÚannotationsN)ÚTYPE_CHECKINGÚAny)Ú
export_pngÚ
export_svgÚshow)Úget_screenshot_as_png)Úgridplot)ÚLabel)Ú
Category10)Úfigure)ÚFillTypeÚLineType)Úfilled_to_bokehÚlines_to_bokeh)ÚRenderer)ÚGridPlot)ÚPalette)Ú	ArrayLike)Ú	WebDriver)Ú
FillReturnÚ
LineReturnc                
   @  sJ  e Zd ZU ded< ded< ded< ded< dKdddddddœdd„Zdddœdd„Zdddœdd„ZdLdd ddd!dd"œd#d$„ZdMd(d(ddd!d)d!dd*œd+d,„ZdNd.d/ddd!d!dd0œd1d2„Z	dOd(d(d3dddd4œd5d6„Z
dPd'd7œddd8dd9œd:d;„Zd'd7œd8d<d=œd>d?„Zdd@œdAdB„ZdQddd)ddCœdDdE„ZdRd(d(d(ddddddHœdIdJ„Zd'S )SÚBokehRendererzlist[figure]Ú_figuresr   Ú_layoutr   Ú_paletteÚboolÚ	_want_svgé   ©é	   r    TFÚintztuple[float, float]ÚNone)ÚnrowsÚncolsÚfigsizeÚ
show_frameÚwant_svgÚreturnc                 C  s®   || _ td | _dtj|td� }|| }g | _| j r:dnd}t|ƒD ]<}	t|d�}
d|
j	_
d|
j_
| j |
¡ |sFd |
_d|
j_
qFt| j|d |d | |d	 | d
�| _d S )Né
   éd   )ZdtypeÚsvgZcanvas)Zoutput_backendFr   r   )r$   Ztoolbar_locationÚwidthÚheight)r   r   r   ÚnpÚasarrayr!   r   Úranger   ZxgridÚvisibleZygridÚappendZoutline_line_colorÚaxisr	   r   )Úselfr#   r$   r%   r&   r'   Z
total_sizeZnfiguresÚbackendÚ_Úfig© r8   ú\/var/www/html/bwave/python/venv/lib/python3.8/site-packages/contourpy/util/bokeh_renderer.pyÚ__init__1   s*    


  
 
þzBokehRenderer.__init__Ústr)Úcolorr(   c                 C  s4   t |tƒr0|d dkr0t|dd … ƒ}| j| }|S )Nr   ÚCr   )Ú
isinstancer;   r!   r   )r4   r<   Úindexr8   r8   r9   Ú_convert_colorN   s    
zBokehRenderer._convert_colorzfigure | intr   )Úaxr(   c                 C  s   t |tƒr| j| }|S )N)r>   r!   r   )r4   rA   r8   r8   r9   Ú_get_figureT   s    

zBokehRenderer._get_figurer   ÚC0çffffffæ?r   r   Úfloat)ÚfilledÚ	fill_typerA   r<   Úalphar(   c           	      C  sJ   |   |¡}|  |¡}t||ƒ\}}t|ƒdkrF|j|g|g||dd� dS )aë  Plot filled contours on a single plot.

        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 Bokeh Figure, optional): Which plot to use, 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
                ``Category10`` palette. Default ``"C0"``.
            alpha (float, optional): Opacity to plot with, default ``0.7``.
        r   )ÚxsÚysr<   Z
fill_alphaÚ
line_widthN)rB   r@   r   ÚlenZmulti_polygons)	r4   rF   rG   rA   r<   rH   r7   rI   rJ   r8   r8   r9   rF   Y   s
    

zBokehRenderer.filledÚblackçš™™™™™¹?Nr   z
str | None)ÚxÚyrA   r<   rH   Úpoint_colorÚquad_as_tri_alphar(   c              
   C  s€  |   |¡}|  ||¡\}}dd„ |D ƒdd„ |jD ƒ }	dd„ |D ƒdd„ |jD ƒ }
t||d�}|j|	|
f|Ž |dk�rTd|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    ¡ }|jd
d„ tj|dd…dd…f  ¡ ||d	d…d	d…f  ¡ fd	d�D ƒdd„ tj|dd…dd…f  ¡ ||d	d…d	d…f  ¡ fd	d�D ƒf|Ž |jdd„ tj|dd…d	d…f  ¡ ||d	d…dd…f  ¡ fd	d�D ƒdd„ tj|dd…d	d…f  ¡ ||d	d…dd…f  ¡ fd	d�D ƒf|Ž |dk	�r||j| ¡ | ¡ |d|dd� dS )a  Plot quad grid lines on a single plot.

        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 Bokeh Figure, optional): Which plot to use, 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 ``Category10`` palette.

        Warning:
            ``quad_as_tri_alpha > 0`` plots all quads as though they are unmasked.
        c                 S  s   g | ]}|‘qS r8   r8   ©Ú.0Úrowr8   r8   r9   Ú
<listcomp>“   s     z&BokehRenderer.grid.<locals>.<listcomp>c                 S  s   g | ]}|‘qS r8   r8   rS   r8   r8   r9   rV   ”   s     )Ú
line_colorrH   r   g      Ð?Néÿÿÿÿr   c                 S  s   g | ]}|‘qS r8   r8   rS   r8   r8   r9   rV   œ   s     )r3   c                 S  s   g | ]}|‘qS r8   r8   rS   r8   r8   r9   rV   �   s     c                 S  s   g | ]}|‘qS r8   r8   rS   r8   r8   r9   rV       s     c                 S  s   g | ]}|‘qS r8   r8   rS   r8   r8   r9   rV   ¡   s     é   )rO   rP   Ú
fill_colorrW   rH   Úsize)	rB   Ú_grid_as_2dÚTÚdictÚ
multi_lineZravelr.   ÚstackÚcircle)r4   rO   rP   rA   r<   rH   rQ   rR   r7   rI   rJ   ÚkwargsZxmidZymidr8   r8   r9   Úgridt   s<    

XXDDþýDDþý
     ÿzBokehRenderer.gridç      ð?r   r   )ÚlinesÚ	line_typerA   r<   rH   Ú	linewidthr(   c           
      C  sF   |   |¡}|  |¡}t||ƒ\}}	t|ƒdkrB|j||	|||d� dS )aŒ  Plot contour lines on a single plot.

        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 Bokeh Figure, optional): Which plot to use, 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
                ``Category10`` palette. Default ``"C0"``.
            alpha (float, optional): Opacity to plot lines with, default ``1.0``.
            linewidth (float, optional): Width of lines, default ``1``.

        Note:
            Assumes all lines are open line strips not closed line loops.
        r   )rW   Z
line_alpharK   N)rB   r@   r   rL   r_   )
r4   re   rf   rA   r<   rH   rg   r7   rI   rJ   r8   r8   r9   re   §   s
    

zBokehRenderer.linesz'ArrayLike | np.ma.MaskedArray[Any, Any])rO   rP   ÚzrA   r<   r(   c                 C  s^   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 plot.

        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 Bokeh Figure, optional): Which plot to use, default ``0``.
            color (str, optional): Circle color, default ``"black"``.
        Nr)   )rZ   r[   )r.   ÚmaZgetmaskZnomaskrB   r@   r\   ra   )r4   rO   rP   rh   rA   r<   Úmaskr7   r8   r8   r9   rj   Ç   s    

zBokehRenderer.mask)Ú	webdriverzWebDriver | None)ÚfilenameÚtransparentrk   r(   c                C  sH   |r| j D ]}d|_d|_q
| jr4t| j||d� nt| j||d� dS )a´  Save plots to SVG or PNG file.

        Args:
            filename (str): Filename to save to.
            transparent (bool, optional): Whether background should be transparent, default
                ``False``.
            webdriver (WebDriver, optional): Selenium WebDriver instance to use to create the image.

        Warning:
            To output to SVG file, ``want_svg=True`` must have been passed to the constructor.
        N)rl   rk   )r   Zbackground_fill_colorZborder_fill_colorr   r   r   r   )r4   rl   rm   rk   r7   r8   r8   r9   Úsaveà   s    
zBokehRenderer.savez
io.BytesIO)rk   r(   c                C  s&   t | j|d�}t ¡ }| |d¡ |S )zÜSave plots to an ``io.BytesIO`` buffer.

        Args:
            webdriver (WebDriver, optional): Selenium WebDriver instance to use to create the image.

        Return:
            BytesIO: PNG image buffer.
        )ZdriverZpng)r   r   ÚioÚBytesIOrn   )r4   rk   ÚimageÚbufferr8   r8   r9   Úsave_to_bufferü   s    	zBokehRenderer.save_to_buffer)r(   c                 C  s   t | jƒ dS )z:Show plots in web browser, in usual Bokeh manner.
        N)r   r   )r4   r8   r8   r9   r   
  s    zBokehRenderer.show)ÚtitlerA   r<   r(   c                 C  s2   |   |¡}||_d|j_|dk	r.|  |¡|j_dS )aÌ  Set the title of a single plot.

        Args:
            title (str): Title text.
            ax (int or Bokeh Figure, optional): Which plot 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
                ``Category10`` palette. Default ``None`` which is ``black``.
        ÚcenterN)rB   rt   Úalignr@   Ú
text_color)r4   rt   rA   r<   r7   r8   r8   r9   rt     s
    

zBokehRenderer.titleÚgreenú.1f)rO   rP   rh   rA   r<   ÚfmtÚquad_as_trir(   c                 C  sR  |   |¡}|  |¡}|  ||¡\}}t |¡}|j\}	}
t|ddd�}t|	ƒD ]L}t|
ƒD ]>}| t	f |||f |||f |||f |› ›dœ|—Ž¡ qZqN|�rNt|	d ƒD ]ž}t|
d ƒD ]Œ}t 
|||d …||d …f ¡}t 
|||d …||d …f ¡}t 
|||d …||d …f ¡}| t	f ||||› ›dœ|—Ž¡ q¾q®dS )a­  Show ``z`` values on a single plot.

        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 Bokeh Figure, optional): Which plot to use, 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
                ``Category10`` palette. 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`` centres
                of quads.

        Warning:
            ``quad_as_tri=True`` shows z-values for all quads, even if masked.
        ru   Úmiddle)rw   Z
text_alignZtext_baseline)rO   rP   Útextr   é   N)rB   r@   r\   r.   r/   Úshaper^   r0   Z
add_layoutr
   Zmean)r4   rO   rP   rh   rA   r<   rz   r{   r7   ÚnyÚnxrb   ÚjÚiZxxÚyyÚzzr8   r8   r9   Úz_values  s     



>"""zBokehRenderer.z_values)r   r   r   TF)r   rC   rD   )r   rM   rN   Nr   )r   rC   rd   r   )r   rM   )F)r   N)r   rx   ry   F)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r:   r@   rB   rF   rc   re   rj   rn   rs   r   rt   r†   r8   r8   r8   r9   r      sT   
     ú	   ú     ø7    ù%  ú ýû    ør   ))Ú
__future__r   ro   Útypingr   r   Zbokeh.ior   r   r   Zbokeh.io.exportr   Zbokeh.layoutsr	   Zbokeh.models.annotations.labelsr
   Zbokeh.palettesr   Zbokeh.plottingr   Únumpyr.   Z	contourpyr   r   Zcontourpy.util.bokeh_utilr   r   Zcontourpy.util.rendererr   Zbokeh.modelsr   r   Znumpy.typingr   Z#selenium.webdriver.remote.webdriverr   Zcontourpy._contourpyr   r   r   r8   r8   r8   r9   Ú<module>   s&   