
    fMh6                    *   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-dS )    )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	<   	 	 	 	 	 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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_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              ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/contourpy/util/bokeh_renderer.py__init__zBokehRenderer.__init__2   s     ""2G37777
;.2n%JUU(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#   )
isinstancerL   r'   r    )rB   rK   indexs      rH   _convert_colorzBokehRenderer._convert_colorO   sD    eS!! 	)eAh#ooabb	NNEM%(ErJ   axfigure | intr   c                J    t          |t                    r| j        |         }|S )N)rO   r'   r   )rB   rR   s     rH   _get_figurezBokehRenderer._get_figureU   s%    b# 	#r"B	rJ   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
                :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ysrK   
fill_alpha
line_widthN)r   rU   rQ   r   lenmulti_polygons)	rB   rX   rY   rR   rK   r[   rG   r^   r_   s	            rH   rX   zBokehRenderer.filledZ   s    * !++	r""##E** 33Br77Q;;2$B4u[\]]]]] ;rJ   black皙?Nxr   ypoint_color
str | Nonequad_as_tri_alphac                ,   |                      |          }|                     ||          \  }}t          |          t          |j                  z   }	t          |          t          |j                  z   }
||d} |j        |	|
fi | |dk    r>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                                  }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        t          t          j        |ddddf                                         ||ddddf                                         fd                    t          t          j        |ddddf                                         ||ddddf                                         fd                    fi |  |j        t          t          j        |ddddf                                         ||ddddf                                         fd                    t          t          j        |ddddf                                         ||ddddf                                         fd                    fi | |B|                    |                                |                                |d|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.
        )
line_colorr[   r   g      ?Nr#   )rA   circle   )rf   rg   
fill_colorrl   r[   markersize)	rU   _grid_as_2dlistT
multi_lineravelr9   stackscatter)rB   rf   rg   rR   rK   r[   rh   rj   rG   r^   r_   kwargsxmidymids                 rH   gridzBokehRenderer.gridv   sd   : r""1%%1!WWtACyy !WWtACyy  %66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RXq"crc{0022D!ABBF)//:K:KLSTUUUVVRXq"crc{0022D!ABBF)//:K:KLSTUUUVV     CNRXq"abbz//114122ss79I9I9K9KLSTUUUVVRXq"abbz//114122ss79I9I9K9KLSTUUUVV     "KK''))qwwyyUtSXa  ) ) ) ) ) #"rJ         ?linesr   	line_typeLineType | str	linewidthc                    t          |          }|                     |          }|                     |          }t          ||          \  }}	| |	J |                    ||	|||           dS dS )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)rl   
line_alphara   )r   rU   rQ   r   line)
rB   r   r   rR   rK   r[   r   rG   r^   r_   s
             rH   r   zBokehRenderer.lines   s    4 !++	r""##E**y11B>>>>HHR%IHVVVVV >rJ   z'ArrayLike | np.ma.MaskedArray[Any, Any]c                @   t           j                            |          }|t           j        j        u rdS |                     |          }|                     |          }|                     ||          \  }}|                    ||         ||         |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"``.
        Nrn   r0   )rp   rq   rr   )r9   magetmasknomaskrU   rQ   rs   ry   )rB   rf   rg   r   rR   rK   maskrG   s           rH   r   zBokehRenderer.mask   s    " u}}Q25<Fr""##E**1%%1AdGQtWxbQQQQQrJ   )	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   )rB   r   r   r   rG   s        rH   savezBokehRenderer.save   su    (  	-} - -,0)(,%%> 	Mt|h)LLLLLLt|h)LLLLLLrJ   
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   )rB   r   imagebuffers       rH   save_to_bufferzBokehRenderer.save_to_buffer  s<     &dl9EEE

65!!!rJ   c                .    t          | j                   dS )z:Show plots in web browser, in usual Bokeh manner.
        N)r   r   )rB   s    rH   r   zBokehRenderer.show  s     	T\rJ   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)rU   r   alignrQ   
text_color)rB   r   rR   rK   rG   s        rH   r   zBokehRenderer.title  sS     r""	"	#'#6#6u#=#=CI    rJ   green.1ffmtquad_as_tric                (   |                      |          }|                     |          }|                     ||          \  }}t          j        |          }|j        \  }	}
|ddd}t          |	          D ]T}t          |
          D ]B}t          d|||f         |||f         |||f         | d|}|                    |           CU|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)rf   rg   textr#      N )
rU   rQ   rs   r9   r:   shaper;   r   
add_layoutmean)rB   rf   rg   r   rR   rK   r   r   rG   nynxrz   jilabelxxyyzzs                     rH   z_valueszBokehRenderer.z_values(  s   6 r""##E**1%%1JqMMB %XPXYYr 	& 	&A2YY & &V!Q$1QT7AadGS9K9KVVvVVu%%%%&  	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rJ   )r#   r#   r$   TF)r&   r'   r(   r'   r)   r*   r+   r!   r,   r!   r-   r.   )rK   rL   r-   rL   )rR   rS   r-   r   )r   rV   rW   )rX   r   rY   rZ   rR   rS   rK   rL   r[   r\   r-   r.   )r   rd   re   Nr   )rf   r   rg   r   rR   rS   rK   rL   r[   r\   rh   ri   rj   r\   r-   r.   )r   rV   r~   r#   )r   r   r   r   rR   rS   rK   rL   r[   r\   r   r\   r-   r.   )r   rd   )rf   r   rg   r   r   r   rR   rS   rK   rL   r-   r.   )F)r   rL   r   r!   r   r   r-   r.   )r   r   r-   r   )r-   r.   )r   N)r   rL   rR   rS   rK   ri   r-   r.   )r   r   r   F)rf   r   rg   r   r   r   rR   rS   rK   rL   r   rL   r   r!   r-   r.   )__name__
__module____qualname____doc____annotations__rI   rQ   rU   rX   r}   r   r   r   r   r   r   r   r   rJ   rH   r   r      s          OOO '-I I I I I:       ^ ^ ^ ^ ^@ "&#$2) 2) 2) 2) 2)p  W  W  W  W  WN R R R R R8 "M
 '+M M M M M M< ?C          
> > > > >* !+T +T +T +T +T +T +TrJ   r   ).
__future__r   r   typingr   r   bokeh.ior   r   r   bokeh.io.exportr	   bokeh.layoutsr
   bokeh.models.annotations.labelsr   bokeh.palettesr   bokeh.plottingr   numpyr9   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   rJ   rH   <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 , , , , , , <222222%%%%%%&&&&&&&&&&&&======,,,,,,,,;;;;;;;;vT vT vT vT vTH vT vT vT vT vTrJ   