
    Wh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 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& d dl'm(Z(m)Z) d dl*m+Z+m,Z,  G d de      Z-y)    )annotationsN)TYPE_CHECKINGAny)
export_png
export_svgshow)get_screenshot_as_png)gridplot)Label)
Category10)figure)as_fill_typeas_line_type)filled_to_bokehlines_to_bokeh)Renderer)OutputBackendType)GridPlot)Palette)	ArrayLike)	WebDriver)FillTypeLineType)
FillReturn
LineReturnc                     e Zd ZU dZded<   ded<   ded<   ded	<   	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 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	 	 	 	 	 	 	 d%dZddd&dZd'dZd(d)dZ	 	 	 	 d*	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZy),BokehRenderera  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:`~.BokehRenderer`, unlike :class:`~.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_svgc                   || _         t        d   | _        dt        j                  |t
              z  }||z  }g | _        | j                   rdnd}t        |      D ]f  }	t        |      }
d|
j                  _
        d|
j                  _
        | j                  j                  |
       |rOd |
_        d|
j                  _
        h t        | j                  |d |d   |z  |d	   |z  
      | _        y )N
   d   )dtypesvgcanvas)output_backendFr      )ncolstoolbar_locationwidthheight)r"   r   r    npasarrayintr   ranger   xgridvisibleygridappendoutline_line_coloraxisr
   r   )selfnrowsr+   figsize
show_framewant_svg
total_sizenfiguresbackend_figs              W/var/www/html/jupyter_env/lib/python3.12/site-packages/contourpy/util/bokeh_renderer.py__init__zBokehRenderer.__init__2   s     ""2G377
;.2nnU(x 	)A0C %CII %CIIMM  %)-&#( 	)  MMQ-5(A%1GI    c                p    t        |t              r%|d   dk(  rt        |dd        }| j                  |   }|S )Nr   Cr*   )
isinstancestrr1   r    )r9   colorindexs      rC   _convert_colorzBokehRenderer._convert_colorO   s8    eS!eAh#oab	NEMM%(ErE   c                D    t        |t              r| j                  |   }|S )N)rH   r1   r   )r9   axs     rC   _get_figurezBokehRenderer._get_figureU   s    b#r"B	rE   c                    t        |      }| j                  |      }| j                  |      }t        ||      \  }}t	        |      dkD  r|j                  |g|g||d       yy)a  Plot filled contours on a single plot.

        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 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   rO   rL   r   lenmulti_polygons)	r9   filled	fill_typerN   rJ   alpharB   rQ   rR   s	            rC   rW   zBokehRenderer.filledZ   sl    * !+	r"##E* 3Br7Q;2$B4u[\] rE   Nc                H   | j                  |      }| j                  ||      \  }}t        |      t        |j                        z   }	t        |      t        |j                        z   }
||d} |j                  |	|
fi | |dkD  rd|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|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                         } |j                  t        t        j                  |ddddf   j                         ||ddddf   j                         fd            t        t        j                  |ddddf   j                         ||ddddf   j                         fd            fi |  |j                  t        t        j                  |ddddf   j                         ||ddddf   j                         fd            t        t        j                  |ddddf   j                         ||ddddf   j                         fd            fi | |5|j                  |j                         |j                         |d|dd	
       yy)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.
        )
line_colorrY   r   g      ?Nr*   )r8   circle   )xy
fill_colorr[   rY   markersize)	rO   _grid_as_2dlistT
multi_lineravelr/   stackscatter)r9   r_   r`   rN   rJ   rY   point_colorquad_as_tri_alpharB   rQ   rR   kwargsxmidymids                 rC   gridzBokehRenderer.gridv   s   : r"1%1!WtACCy !WtACCy  %6r2((q !CRC"H+!"crc'
2QssABwZ?!ABF)KLSSUD!CRC"H+!"crc'
2QssABwZ?!ABF)KLSSUDCNNRXXq"crc{002D!ABF)//:KLSTUVRXXq"crc{002D!ABF)//:KLSTUV  CNNRXXq"abz//1412ss79I9I9KLSTUVRXXq"abz//1412ss79I9I9KLSTUV  "KK'')qwwyUtSXa  ) #rE   c                    t        |      }| j                  |      }| j                  |      }t        ||      \  }}	||	J |j	                  ||	|||       yy)a  Plot contour lines on a single plot.

        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 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)r[   
line_alpharT   )r   rO   rL   r   line)
r9   lines	line_typerN   rJ   rY   	linewidthrB   rQ   rR   s
             rC   rt   zBokehRenderer.lines   sh    4 !+	r"##E*y1B>>!>HHR%IHV rE   c                "   t         j                  j                  |      }|t         j                  j                  u ry| j	                  |      }| j                  |      }| j                  ||      \  }}|j                  ||   ||   |dd       y)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$   )ra   rb   rc   )r/   magetmasknomaskrO   rL   rd   rj   )r9   r_   r`   zrN   rJ   maskrB   s           rC   r|   zBokehRenderer.mask   s}    " uu}}Q255<<r"##E*1%1AdGQtWxbQrE   )	webdriverc                   |r| j                   D ]  }d|_        d|_         | j                  rt	        | j
                  ||       yt        | j
                  ||       y)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)filenamer}   )r   background_fill_colorborder_fill_colorr"   r   r   r   )r9   r   transparentr}   rB   s        rC   savezBokehRenderer.save   sS    ( }} -,0)(,%- >>t||h)Lt||h)LrE   c                   t        | j                  |      }t        j                         }|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   )r9   r}   imagebuffers       rC   save_to_bufferzBokehRenderer.save_to_buffer  s2     &dll9E

65!rE   c                .    t        | j                         y)z:Show plots in web browser, in usual Bokeh manner.
        N)r   r   )r9   s    rC   r   zBokehRenderer.show  s     	T\\rE   c                    | j                  |      }||_        d|j                  _        |!| j                  |      |j                  _        yy)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)rO   titlealignrL   
text_color)r9   r   rN   rJ   rB   s        rC   r   zBokehRenderer.title  sH     r"	"		#'#6#6u#=CII  rE   c                   | j                  |      }| j                  |      }| j                  ||      \  }}t        j                  |      }|j
                  \  }	}
|ddd}t        |	      D ]F  }t        |
      D ]6  }t        d	|||f   |||f   |||f   | dd|}|j                  |       8 H |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                  t        d	|||| dd|         yy)
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 )r_   r`   textr*      N )
rO   rL   rd   r/   r0   shaper2   r   
add_layoutmean)r9   r_   r`   r{   rN   rJ   fmtquad_as_trirB   nynxrm   jilabelxxyyzzs                     rC   z_valueszBokehRenderer.z_values(  s   6 r"##E*1%1JJqMB %XPXYr 	&A2Y &V!Q$1QT7AadGSE6?VvVu%&	& 2a4[ Tr!t TA1QqS5!AaC%<1B1QqS5!AaC%<1B1QqS5!AaC%<1BNN5#R2RPvJ#R6#RS	TT rE   )r*   r*   )	   r   TF)r:   r1   r+   r1   r;   ztuple[float, float]r<   r!   r=   r!   returnNone)rJ   rI   r   rI   )rN   figure | intr   r   )r   C0gffffff?)rW   r   rX   zFillType | strrN   r   rJ   rI   rY   floatr   r   )r   blackg?Nr   )r_   r   r`   r   rN   r   rJ   rI   rY   r   rk   
str | Nonerl   r   r   r   )r   r   g      ?r*   )rt   r   ru   zLineType | strrN   r   rJ   rI   rY   r   rv   r   r   r   )r   r   )r_   r   r`   r   r{   z'ArrayLike | np.ma.MaskedArray[Any, Any]rN   r   rJ   rI   r   r   )F)r   rI   r   r!   r}   WebDriver | Noner   r   )r}   r   r   z
io.BytesIO)r   r   )r   N)r   rI   rN   r   rJ   r   r   r   )r   greenz.1fF)r_   r   r`   r   r{   r   rN   r   rJ   rI   r   rI   r   r!   r   r   )__name__
__module____qualname____doc____annotations__rD   rL   rO   rW   rp   rt   r|   r   r   r   r   r   r   rE   rC   r   r      s    O '-II I %	I
 I I 
I: ^^ "^ 	^
 ^ ^ 
^@ "&#$2)2) 2) 	2)
 2) 2)  2) !2) 
2)p  W W " W 	 W
  W  W  W 
 WN RR R 3	R
 R R 
R8 "M
 '+MM M
 $M 
M< ?C  
>* !+T+T +T 	+T
 +T +T +T +T 
+TrE   r   ).
__future__r   r   typingr   r   bokeh.ior   r   r   bokeh.io.exportr	   bokeh.layoutsr
   bokeh.models.annotations.labelsr   bokeh.palettesr   bokeh.plottingr   numpyr/   contourpy.enum_utilr   r   contourpy.util.bokeh_utilr   r   contourpy.util.rendererr   bokeh.core.enumsr   bokeh.modelsr   r   numpy.typingr   #selenium.webdriver.remote.webdriverr   	contourpyr   r   contourpy._contourpyr   r   r   r   rE   rC   <module>r      sW    " 	 % 1 1 1 " 1 % !  : E ,2%&&=,;vTH vTrE   