
    \e6                       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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e           Z+dS )    )annotationsN)TYPE_CHECKINGAny)
export_png
export_svgshow)get_screenshot_as_png)gridplot)Label)
Category10)figure)FillTypeLineType)as_fill_typeas_line_type)filled_to_bokehlines_to_bokeh)Renderer)GridPlot)Palette)	ArrayLike)	WebDriver)
FillReturn
LineReturnc                      e Zd ZU dZded<   ded<   ded<   ded	<   	 	 	 	 	 dMdNdZdOdZdPdZ	 	 	 dQdRd(Z	 	 	 	 	 dSdTd2Z		 	 	 	 dUdVd9Z
	 	 dWdXd<Z	 dYd+d=dZdBZd+d=d[dDZd\dEZd]d^dGZ	 	 	 	 d_d`dLZd+S )aBokehRendereraF  Utility renderer using Bokeh 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 (assuming 100 dpi), default
            ``(9, 9)``.
        show_frame (bool, optional): Whether to show frame and axes ticks, default ``True``.
        want_svg (bool, optional): Whether output is required in SVG format or not, default
            ``False``.

    Warning:
        :class:`~contourpy.util.bokeh_renderer.BokehRenderer`, unlike
        :class:`~contourpy.util.mpl_renderer.MplRenderer`, needs to be told in advance if output to
        SVG format will be required later, otherwise it will assume PNG output.
    zlist[figure]_figuresr   _layoutr   _palettebool	_want_svg   	   r$   TFnrowsintncolsfigsizetuple[float, float]
show_framewant_svgreturnNonec                   || _         t          d         | _        dt          j        |t
                    z  }||z  }g | _        | j         rdnd}t          |          D ]Y}	t          |          }
d|
j	        _
        d|
j        _
        | j                            |
           |sd |
_        d|
j        _
        Zt          | j        |d |d         |z  |d	         |z  
          | _        d S )N
   d   )dtypesvgcanvas)output_backendFr   r"   )r'   toolbar_locationwidthheight)r!   r   r   npasarrayr&   r   ranger   xgridvisibleygridappendoutline_line_coloraxisr
   r   )selfr%   r'   r(   r*   r+   
total_sizenfiguresbackend_figs              =lib/python3.11/site-packages/contourpy/util/bokeh_renderer.py__init__zBokehRenderer.__init__2   s     ""2G37777
;>7%%xx 	) 	)A000C %CI %CIM  %%% ))-&#( MQ-5(A%1GI I I    colorstrc                    t          |t                    r0|d         dk    r$t          |dd                    }| j        |         }|S )Nr   Cr"   )
isinstancerK   r&   r   )rA   rJ   indexs      rG   _convert_colorzBokehRenderer._convert_colorO   sD    eS!! 	)eAh#ooabb	NNEM%(ErI   axfigure | intr   c                J    t          |t                    r| j        |         }|S )N)rN   r&   r   )rA   rQ   s     rG   _get_figurezBokehRenderer._get_figureU   s%    b# 	#r"B	rI   r   C0ffffff?filledr   	fill_typeFillType | stralphafloatc                    t          |          }|                     |          }|                     |          }t          ||          \  }}t	          |          dk    r|                    |g|g||d           dS 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 or str): Type of ``filled`` data as returned by
                :attr:`~contourpy.ContourGenerator.fill_type`, or a string equivalent.
            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ysrJ   
fill_alpha
line_widthN)r   rT   rP   r   lenmulti_polygons)	rA   rW   rX   rQ   rJ   rZ   rF   r]   r^   s	            rG   rW   zBokehRenderer.filledZ   s    * !++	r""##E** 33Br77Q;;2$B4u[\]]]]] ;rI   black皙?Nxr   ypoint_color
str | Nonequad_as_tri_alphac                   |                      |          }|                     ||          \  }}d |D             d |j        D             z   }	d |D             d |j        D             z   }
t          ||          } |j        |	|
fi | |dk    r2d|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                                  } |j        d t          j        |dd	dd	f                                         ||d
dd
df                                         fd
          D             d t          j        |dd	dd	f                                         ||d
dd
df                                         fd
          D             fi |  |j        d t          j        |dd	d
df                                         ||d
ddd	f                                         fd
          D             d t          j        |dd	d
df                                         ||d
ddd	f                                         fd
          D             fi | |A|                    |                                |                                |d|d           dS 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                    g | ]}|S  rl   .0rows     rG   
<listcomp>z&BokehRenderer.grid.<locals>.<listcomp>       ccrI   c                    g | ]}|S rl   rl   rm   s     rG   rp   z&BokehRenderer.grid.<locals>.<listcomp>       "6"6"633"6"6"6rI   c                    g | ]}|S rl   rl   rm   s     rG   rp   z&BokehRenderer.grid.<locals>.<listcomp>   rq   rI   c                    g | ]}|S rl   rl   rm   s     rG   rp   z&BokehRenderer.grid.<locals>.<listcomp>   rs   rI   )
line_colorrZ   r   g      ?Nr"   c                    g | ]}|S rl   rl   rm   s     rG   rp   z&BokehRenderer.grid.<locals>.<listcomp>       aaaaaarI   )r@   c                    g | ]}|S rl   rl   rm   s     rG   rp   z&BokehRenderer.grid.<locals>.<listcomp>   ry   rI   c                    g | ]}|S rl   rl   rm   s     rG   rp   z&BokehRenderer.grid.<locals>.<listcomp>   ry   rI   c                    g | ]}|S rl   rl   rm   s     rG   rp   z&BokehRenderer.grid.<locals>.<listcomp>   ry   rI      )re   rf   
fill_colorrv   rZ   size)	rT   _grid_as_2dTdict
multi_lineravelr8   stackcircle)rA   re   rf   rQ   rJ   rZ   rg   ri   rF   r]   r^   kwargsxmidymids                 rG   gridzBokehRenderer.gridv   s   : r""1%%1Q"6"6!#"6"6"66Q"6"6!#"6"6"66e444r2(((((q  !CRC"H+!""crc'
2QssABBwZ?!ABBF)KLSSUUD!CRC"H+!""crc'
2QssABBwZ?!ABBF)KLSSUUDCNaa!CRC"H+*;*;*=*=tQqrr122vY__EVEV)W^_ ` ` `aaaaa!CRC"H+*;*;*=*=tQqrr122vY__EVEV)W^_ ` ` `aaa     CNaa!CRCG**:*:*<*<dAabb#2#gJDTDTDVDV)W^_ ` ` `aaaaa!CRCG**:*:*<*<dAabb#2#gJDTDTDVDV)W^_ ` ` `aaa     "JJ''))qwwyyUtSX_`  b b b b b #"rI         ?linesr   	line_typeLineType | str	linewidthc                    t          |          }|                     |          }|                     |          }t          ||          \  }}	||                    ||	|||           dS 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 or str): Type of ``lines`` data as returned by
                :attr:`~contourpy.ContourGenerator.line_type`, or a string equivalent.
            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.
        N)rv   
line_alphar`   )r   rT   rP   r   line)
rA   r   r   rQ   rJ   rZ   r   rF   r]   r^   s
             rG   r   zBokehRenderer.lines   sx    4 !++	r""##E**y11B>HHR%IHVVVVV >rI   z'ArrayLike | np.ma.MaskedArray[Any, Any]c                >   t           j                            |          }|t           j        j        u rdS |                     |          }|                     |          }|                     ||          \  }}|                    ||         ||         |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/   )r~   r   )r8   magetmasknomaskrT   rP   r   r   )rA   re   rf   r   rQ   rJ   maskrF   s           rG   r   zBokehRenderer.mask   s    " u}}Q25<Fr""##E**1%%1

1T7AdGB
?????rI   )	webdriverfilenametransparentr   WebDriver | Nonec                   |r| j         D ]}d|_        d|_        | j        rt	          | j        ||           dS t          | j        ||           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.

                .. versionadded:: 1.1.1

        Warning:
            To output to SVG file, ``want_svg=True`` must have been passed to the constructor.
        N)r   r   )r   background_fill_colorborder_fill_colorr!   r   r   r   )rA   r   r   r   rF   s        rG   savezBokehRenderer.save   su    (  	-} - -,0)(,%%> 	Mt|h)LLLLLLt|h)LLLLLLrI   
io.BytesIOc                   t          | j        |          }t          j                    }|                    |d           |S )a  Save plots to an ``io.BytesIO`` buffer.

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

                .. versionadded:: 1.1.1

        Return:
            BytesIO: PNG image buffer.
        )driverpng)r	   r   ioBytesIOr   )rA   r   imagebuffers       rG   save_to_bufferzBokehRenderer.save_to_buffer  s<     &dl9EEE

65!!!rI   c                .    t          | j                   dS )z:Show plots in web browser, in usual Bokeh manner.
        N)r   r   )rA   s    rG   r   zBokehRenderer.show  s     	T\rI   titlec                    |                      |          }||_        d|j        _        |!|                     |          |j        _        dS 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)rT   r   alignrP   
text_color)rA   r   rQ   rJ   rF   s        rG   r   zBokehRenderer.title  sS     r""	"	#'#6#6u#=#=CI    rI   green.1ffmtquad_as_tric                <   |                      |          }|                     |          }|                     ||          \  }}t          j        |          }|j        \  }	}
t          |dd          }t          |	          D ]R}t          |
          D ]@}|                    t          d|||f         |||f         |||f         | d|           AS|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                   }|                    t          d|||| d|           dS 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.
        r   middle)r   
text_aligntext_baseline)re   rf   textr"      Nrl   )rT   rP   r   r8   r9   shaper   r:   
add_layoutr   mean)rA   re   rf   r   rQ   rJ   r   r   rF   nynxr   jixxyyzzs                    rG   z_valueszBokehRenderer.z_values&  s   6 r""##E**1%%1JqMMB88TTTr 	_ 	_A2YY _ _u]qAw!AqD'1QT7C@R@R]]V\]]^^^^_ 	T2a4[[ T Tr!t T TA1QqS5!AaC%<11B1QqS5!AaC%<11B1QqS5!AaC%<11BNN5#R2R--#R#R6#R#RSSSS	T	T 	TT TrI   )r"   r"   r#   TF)r%   r&   r'   r&   r(   r)   r*   r    r+   r    r,   r-   )rJ   rK   r,   rK   )rQ   rR   r,   r   )r   rU   rV   )rW   r   rX   rY   rQ   rR   rJ   rK   rZ   r[   r,   r-   )r   rc   rd   Nr   )re   r   rf   r   rQ   rR   rJ   rK   rZ   r[   rg   rh   ri   r[   r,   r-   )r   rU   r   r"   )r   r   r   r   rQ   rR   rJ   rK   rZ   r[   r   r[   r,   r-   )r   rc   )re   r   rf   r   r   r   rQ   rR   rJ   rK   r,   r-   )F)r   rK   r   r    r   r   r,   r-   )r   r   r,   r   )r,   r-   )r   N)r   rK   rQ   rR   rJ   rh   r,   r-   )r   r   r   F)re   r   rf   r   r   r   rQ   rR   rJ   rK   r   rK   r   r    r,   r-   )__name__
__module____qualname____doc____annotations__rH   rP   rT   rW   r   r   r   r   r   r   r   r   rl   rI   rG   r   r      s           OOO '-I I I I I:       ^ ^ ^ ^ ^@ "&#$1b 1b 1b 1b 1bn W W W W WL @ @ @ @ @8 "M
 '+M M M M M M< ?C          
> > > > >* !*T *T *T *T *T *T *TrI   r   ),
__future__r   r   typingr   r   bokeh.ior   r   r   bokeh.io.exportr	   bokeh.layoutsr
   bokeh.models.annotations.labelsr   bokeh.palettesr   bokeh.plottingr   numpyr8   	contourpyr   r   contourpy.enum_utilr   r   contourpy.util.bokeh_utilr   r   contourpy.util.rendererr   bokeh.modelsr   r   numpy.typingr   #selenium.webdriver.remote.webdriverr   contourpy._contourpyr   r   r   rl   rI   rG   <module>r      s   " " " " " " 				 % % % % % % % % 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " " " " " " 1 1 1 1 1 1 % % % % % % ! ! ! ! ! !     ( ( ( ( ( ( ( ( : : : : : : : : E E E E E E E E , , , , , , <%%%%%%&&&&&&&&&&&&======;;;;;;;;tT tT tT tT tTH tT tT tT tT tTrI   