o
    j6                     @  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rd 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 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                   @  s   e Zd ZU dZded< ded< ded< ded	< 	
	
			dYdZddZd[ddZd\d d!Z	"	#	$d]d^d+d,Z	"	-	.	/	"d_d`d6d7Z		"	#	8	
dadbd>d?Z
	"	-dcdddBdCZ	ded/dDdfdIdJZd/dDdgdLdMZdhdNdOZdidjdQdRZ	"	S	T	dkdldWdXZd/S )m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                 C  s   || _ td | _dtj|td }|| }g | _| j rdnd}t|D ]}	t|d}
d|
j	_
d|
j_
| j|
 |sAd |
_d|
j_
q#t| 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 r<   ^/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/contourpy/util/bokeh_renderer.py__init__2   s&   

zBokehRenderer.__init__colorstrc                 C  s4   t |tr|d dkrt|dd  }| j| }|S )Nr   Cr!   )
isinstancer@   r%   r   )r8   r?   indexr<   r<   r=   _convert_colorO   s   
zBokehRenderer._convert_coloraxfigure | intr   c                 C  s   t |tr
| j| }|S )N)rB   r%   r   )r8   rE   r<   r<   r=   _get_figureU   s   

zBokehRenderer._get_figurer   C0ffffff?filledr   	fill_typeFillType | stralphafloatc           	      C  sV   t |}| |}| |}t||\}}t|dkr)|j|g|g||d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ysr?   Z
fill_alpha
line_widthN)r   rG   rD   r   lenZmulti_polygons)	r8   rJ   rK   rE   r?   rM   r;   rO   rP   r<   r<   r=   rJ   Z   s   

zBokehRenderer.filledblack皙?Nxr   ypoint_color
str | Nonequad_as_tri_alphac              
   C  s`  |  |}| ||\}}t|t|j }	t|t|j }
||d}|j|	|
fi | |dkrd|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ttj|ddddf  ||ddddf  fddttj|ddddf  ||ddddf  fddfi | |jttj|ddddf  ||ddddf  fddttj|ddddf  ||ddddf  fddfi | |dur.|j| | |d|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_colorrM   r   g      ?Nr!   )r7   circle   )rU   rV   
fill_colorrZ   rM   markersize)	rG   _grid_as_2dlistTZ
multi_lineZravelr2   stackscatter)r8   rU   rV   rE   r?   rM   rW   rY   r;   rO   rP   kwargsZxmidZymidr<   r<   r=   gridv   s6   


XX>>>>

zBokehRenderer.grid      ?linesr   	line_typeLineType | str	linewidthc           
      C  sZ   t |}| |}| |}t||\}}	|dur+|	dusJ |j||	|||d 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)rZ   Z
line_alpharQ   )r   rG   rD   r   line)
r8   ri   rj   rE   r?   rM   rl   r;   rO   rP   r<   r<   r=   ri      s   

zBokehRenderer.linesz'ArrayLike | np.ma.MaskedArray[Any, Any]c                 C  s`   t j|}|t jju rdS | |}| |}| ||\}}|j|| || |d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\   r-   )r^   r_   r`   )r2   maZgetmaskZnomaskrG   rD   ra   re   )r8   rU   rV   rn   rE   r?   maskr;   r<   r<   r=   rq      s   

 zBokehRenderer.mask)	webdriverfilenametransparentrr   WebDriver | Nonec                C  sJ   |r| j D ]}d|_d|_q| jrt| j||d dS 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.

                .. versionadded:: 1.1.1

        Warning:
            To output to SVG file, ``want_svg=True`` must have been passed to the constructor.
        N)rs   rr   )r   Zbackground_fill_colorZborder_fill_colorr    r   r   r   )r8   rs   rt   rr   r;   r<   r<   r=   save   s   
zBokehRenderer.save
io.BytesIOc                C  s&   t | j|d}t }||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.
        )ZdriverZpng)r   r   ioBytesIOrv   )r8   rr   imagebufferr<   r<   r=   save_to_buffer  s   zBokehRenderer.save_to_bufferc                 C  s   t | j dS )z:Show plots in web browser, in usual Bokeh manner.
        N)r   r   )r8   r<   r<   r=   r     s   zBokehRenderer.showtitlec                 C  s6   |  |}||_d|j_|dur| ||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)rG   r}   alignrD   
text_color)r8   r}   rE   r?   r;   r<   r<   r=   r}     s   

zBokehRenderer.titlegreen.1ffmtquad_as_tric              
   C  sV  |  |}| |}| ||\}}t|}|j\}	}
|ddd}t|	D ](}t|
D ]!}td|||f |||f |||f | d|}|| q,q&|rt|	d D ]Q}t|
d D ]F}t	|||d ||d f }t	|||d ||d f }t	|||d ||d f }|td|||| d| q_qWd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   Z
text_alignZtext_baseline)rU   rV   textr!      Nr<   )
rG   rD   ra   r2   r3   shaper4   r
   Z
add_layoutmean)r8   rU   rV   rn   rE   r?   r   r   r;   nynxrf   jilabelxxyyzzr<   r<   r=   z_values(  s*   



4"""$zBokehRenderer.z_values)r!   r!   r"   TF)r$   r%   r&   r%   r'   r(   r)   r   r*   r   r+   r,   )r?   r@   r+   r@   )rE   rF   r+   r   )r   rH   rI   )rJ   r   rK   rL   rE   rF   r?   r@   rM   rN   r+   r,   )r   rS   rT   Nr   )rU   r   rV   r   rE   rF   r?   r@   rM   rN   rW   rX   rY   rN   r+   r,   )r   rH   rh   r!   )ri   r   rj   rk   rE   rF   r?   r@   rM   rN   rl   rN   r+   r,   )r   rS   )rU   r   rV   r   rn   ro   rE   rF   r?   r@   r+   r,   )F)rs   r@   rt   r   rr   ru   r+   r,   )rr   ru   r+   rw   )r+   r,   )r   N)r}   r@   rE   rF   r?   rX   r+   r,   )r   r   r   F)rU   r   rV   r   rn   r   rE   rF   r?   r@   r   r@   r   r   r+   r,   )__name__
__module____qualname____doc____annotations__r>   rD   rG   rJ   rg   ri   rq   rv   r|   r   r}   r   r<   r<   r<   r=   r      sX   
 

	 8'
r   ).
__future__r   rx   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   numpyr2   Zcontourpy.enum_utilr   r   Zcontourpy.util.bokeh_utilr   r   Zcontourpy.util.rendererr   Zbokeh.core.enumsr   Zbokeh.modelsr   r   Znumpy.typingr   Z#selenium.webdriver.remote.webdriverr   Z	contourpyr   r   Zcontourpy._contourpyr   r   r   r<   r<   r<   r=   <module>   s,    