
    g5                       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' 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)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              Z/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/contourpy/util/bokeh_renderer.py__init__zBokehRenderer.__init__1   s     ""2G377
;>>%x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strr0   r   )r8   colorindexs      rB   _convert_colorzBokehRenderer._convert_colorN   s8    eS!eAh#oab	NEMM%(ErD   c                D    t        |t              r| j                  |   }|S )N)rG   r0   r   )r8   axs     rB   _get_figurezBokehRenderer._get_figureT   s    b#r"B	rD   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ysrI   
fill_alpha
line_widthN)r   rN   rK   r   lenmulti_polygons)	r8   filled	fill_typerM   rI   alpharA   rP   rQ   s	            rB   rV   zBokehRenderer.filledY   sl    * !+	r"##E* 3Br7Q;2$B4u[\] rD   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_colorrX   r   g      ?Nr)   )r7   circle   )xy
fill_colorrZ   rX   markersize)	rN   _grid_as_2dlistT
multi_lineravelr.   stackscatter)r8   r^   r_   rM   rI   rX   point_colorquad_as_tri_alpharA   rP   rQ   kwargsxmidymids                 rB   gridzBokehRenderer.gridu   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  ) #rD   c                    t        |      }| j                  |      }| j                  |      }t        ||      \  }}	||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)rZ   
line_alpharS   )r   rN   rK   r   line)
r8   lines	line_typerM   rI   rX   	linewidthrA   rP   rQ   s
             rB   rs   zBokehRenderer.lines   s^    4 !+	r"##E*y1B>HHR%IHV rD   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#   )r`   ra   rb   )r.   magetmasknomaskrN   rK   rc   ri   )r8   r^   r_   zrM   rI   maskrA   s           rB   r{   zBokehRenderer.mask   s}    " uu}}Q255<<r"##E*1%1AdGQtWxbQrD   )	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   )r8   r~   transparentr|   rA   s        rB   savezBokehRenderer.save   sS    ( }} -,0)(,%- >>t||h)Lt||h)LrD   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   )r8   r|   imagebuffers       rB   save_to_bufferzBokehRenderer.save_to_buffer  s2     &dll9E

65!rD   c                .    t        | j                         y)z:Show plots in web browser, in usual Bokeh manner.
        N)r   r   )r8   s    rB   r   zBokehRenderer.show  s     	T\\rD   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)rN   titlealignrK   
text_color)r8   r   rM   rI   rA   s        rB   r   zBokehRenderer.title  sH     r"	"		#'#6#6u#=CII  rD   c                   | j                  |      }| j                  |      }| j                  ||      \  }}t        j                  |      }|j
                  \  }	}
|ddd}t        |	      D ]D  }t        |
      D ]4  }|j                  t        d	|||f   |||f   |||f   | dd|       6 F |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 )
rN   rK   rc   r.   r/   shaper1   
add_layoutr   mean)r8   r^   r_   rz   rM   rI   fmtquad_as_trirA   nynxrl   jixxyyzzs                    rB   z_valueszBokehRenderer.z_values&  s   6 r"##E*1%1JJqMB %XPXYr 	_A2Y _u]qAw!AqD'1QT7C5PP&/]V\]^_	_ 2a4[ Tr!t TA1QqS5!AaC%<1B1QqS5!AaC%<1B1QqS5!AaC%<1BNN5#R2RPvJ#R6#RS	TT rD   )r)   r)   )	   r   TF)r9   r0   r*   r0   r:   ztuple[float, float]r;   r    r<   r    returnNone)rI   rH   r   rH   )rM   figure | intr   r   )r   C0gffffff?)rV   r   rW   zFillType | strrM   r   rI   rH   rX   floatr   r   )r   blackg?Nr   )r^   r   r_   r   rM   r   rI   rH   rX   r   rj   
str | Nonerk   r   r   r   )r   r   g      ?r)   )rs   r   rt   zLineType | strrM   r   rI   rH   rX   r   ru   r   r   r   )r   r   )r^   r   r_   r   rz   z'ArrayLike | np.ma.MaskedArray[Any, Any]rM   r   rI   rH   r   r   )F)r~   rH   r   r    r|   WebDriver | Noner   r   )r|   r   r   z
io.BytesIO)r   r   )r   N)r   rH   rM   r   rI   r   r   r   )r   greenz.1fF)r^   r   r_   r   rz   r   rM   r   rI   rH   r   rH   r   r    r   r   )__name__
__module____qualname____doc____annotations__rC   rK   rN   rV   ro   rs   r{   r   r   r   r   r   r   rD   rB   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L 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rD   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.modelsr   r   numpy.typingr   #selenium.webdriver.remote.webdriverr   	contourpyr   r   contourpy._contourpyr   r   r   r   rD   rB   <module>r      sT    " 	 % 1 1 1 " 1 % !  : E ,%&&=,;tTH tTrD   