
    "	f3                        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$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)FillTypeLineType)filled_to_bokehlines_to_bokeh)Renderer)GridPlot)Palette)	ArrayLike)
FillReturn
LineReturnc                  n   e Zd ZU 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Zd$dZd%dZd&d'dZ	 	 	 	 d(	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)dZy)*BokehRendererzlist[figure]_figuresr   _layoutr   _palettebool	_want_svgc                   || _         t        d   | _        dt        j                  |      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   svgcanvas)output_backendFr      )ncolstoolbar_locationwidthheight)r   r   r   npasarrayr   ranger   xgridvisibleygridappendoutline_line_coloraxisr
   r   )selfnrowsr&   figsize
show_framewant_svg
total_sizenfiguresbackend_figs              ?/usr/lib/python3/dist-packages/contourpy/util/bokeh_renderer.py__init__zBokehRenderer.__init__0   s     ""2G,,
;>>%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strintr   )r3   colorindexs      r=   _convert_colorzBokehRenderer._convert_colorM   s8    eS!eAh#oab	NEMM%(Er?   c                D    t        |t              r| j                  |   }|S )N)rB   rD   r   )r3   axs     r=   _get_figurezBokehRenderer._get_figureS   s    b#r"B	r?   c                    | 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
                :func:`~contourpy.ContourGenerator.filled`.
            fill_type (FillType): Type of ``filled`` data, as returned by
                :attr:`~contourpy.ContourGenerator.fill_type`.
            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ysrE   
fill_alpha
line_widthN)rJ   rG   r   lenmulti_polygons)	r3   filled	fill_typerI   rE   alphar<   rL   rM   s	            r=   rR   zBokehRenderer.filledX   sb    * r"##E* 3Br7Q;2$B4u[\] r?   Nc                   | j                  |      }| j                  ||      \  }}|D 	cg c]  }	|	 c}	|j                  D 	cg c]  }	|	 c}	z   }
|D 	cg c]  }	|	 c}	|j                  D 	cg c]  }	|	 c}	z   }t        ||      } |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        j                  |ddddf   j                         ||ddddf   j                         fd      D 	cg c]  }	|	 c}	t        j                  |ddddf   j                         ||ddddf   j                         fd      D 	cg c]  }	|	 c}	fi |  |j                  t        j                  |ddddf   j                         ||ddddf   j                         fd      D 	cg c]  }	|	 c}	t        j                  |ddddf   j                         ||ddddf   j                         fd      D 	cg c]  }	|	 c}	fi | |4|j                  |j                         |j                         |d|d	       yyc c}	w c c}	w c c}	w c c}	w c c}	w c c}	w c c}	w c c}	w )
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_colorrT   r   g      ?Nr%   )r2      )xy
fill_colorrV   rT   size)	rJ   _grid_as_2dTdict
multi_lineravelr*   stackcircle)r3   rY   rZ   rI   rE   rT   point_colorquad_as_tri_alphar<   rowrL   rM   kwargsxmidymids                  r=   gridzBokehRenderer.grids   s   : r"1%1cc!##"633"66cc!##"633"66e4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 "!CRC"H+*;*;*=tQqr12vY__EV)W^_ `aa "!CRC"H+*;*;*=tQqr12vY__EV)W^_ `aa  CNN "!CRCG**:*:*<dAab#2#gJDTDTDV)W^_ `aa "!CRCG**:*:*<dAab#2#gJDTDTDV)W^_ `aa  "JJ'')qwwyUtSX_`  b #!  "6"6 ba bas/   	K	K	K/	K":	K'	K,
6	K1	K6
c                    | j                  |      }| j                  |      }t        ||      \  }}	t        |      dkD  r|j	                  ||	|||       yy)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): Type of ``lines`` data, as returned by
                :attr:`~contourpy.ContourGenerator.line_type`.
            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.
        r   )rV   
line_alpharO   N)rJ   rG   r   rP   r`   )
r3   lines	line_typerI   rE   rT   	linewidthr<   rL   rM   s
             r=   rm   zBokehRenderer.lines   s[    4 r"##E*y1Br7Q;NN2reR[N\ r?   c                    t         j                  j                  |      }|t         j                  j                  u ry| j	                  |      }| j                  |      }| j                  ||      \  }}|j                  ||   ||   |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\   )r*   magetmasknomaskrJ   rG   r]   rc   )r3   rY   rZ   zrI   rE   maskr<   s           r=   ru   zBokehRenderer.mask   s{    " uu}}Q255<<r"##E*1%1

1T7AdGB
?r?   c                    |r| j                   D ]  }d|_        d|_         | j                  rt	        | j
                  |       yt        | j
                  |       y)aO  Save plots to SVG or PNG file.

        Args:
            filename (str): Filename to save to.
            transparent (bool, optional): Whether background should be transparent, default
                ``False``.

        Warning:
            To output to SVG file, ``want_svg=True`` must have been passed to the constructor.
        N)filename)r   background_fill_colorborder_fill_colorr   r   r   r   )r3   rw   transparentr<   s       r=   savezBokehRenderer.save   sO     }} -,0)(,%- >>t||h7t||h7r?   c                |    t        | j                        }t        j                         }|j	                  |d       |S )zhSave plots to an ``io.BytesIO`` buffer.

        Return:
            BytesIO: PNG image buffer.
        png)r	   r   ioBytesIOr{   )r3   imagebuffers      r=   save_to_bufferzBokehRenderer.save_to_buffer   s0     &dll3

65!r?   c                .    t        | j                         y)z:Show plots in web browser, in usual Bokeh manner.
        N)r   r   )r3   s    r=   r   zBokehRenderer.show   s     	T\\r?   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)rJ   titlealignrG   
text_color)r3   r   rI   rE   r<   s        r=   r   zBokehRenderer.title  sH     r"	"		#'#6#6u#=CII  r?   c                   | j                  |      }| j                  |      }| j                  ||      \  }}t        j                  |      }|j
                  \  }	}
t        |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 )rY   rZ   textr%      N )rJ   rG   r]   r*   r+   shaper_   r,   
add_layoutr   mean)r3   rY   rZ   rt   rI   rE   fmtquad_as_trir<   nynxrg   jixxyyzzs                    r=   z_valueszBokehRenderer.z_values  s   6 r"##E*1%1JJqMB88T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 r?   )r%   r%   )	   r   TF)r4   rD   r&   rD   r5   ztuple[int, int]r6   r   r7   r   returnNone)rE   rC   r   rC   )rI   figure | intr   r   )r   C0gffffff?)rR   r   rS   r   rI   r   rE   rC   rT   floatr   r   )r   blackg?Nr   )rY   r   rZ   r   rI   r   rE   rC   rT   r   rd   
str | Nonere   r   r   r   )r   r   g      ?r%   )rm   r   rn   r   rI   r   rE   rC   rT   r   ro   r   r   r   )r   r   )rY   r   rZ   r   rt   z'ArrayLike | np.ma.MaskedArray[Any, Any]rI   r   rE   rC   r   r   )F)rw   rC   rz   r   r   r   )r   z
io.BytesIO)r   r   )r   N)r   rC   rI   r   rE   r   r   r   )r   greenz.1fF)rY   r   rZ   r   rt   r   rI   r   rE   rC   r   rC   r   r   r   r   )__name__
__module____qualname____annotations__r>   rG   rJ   rR   rj   rm   ru   r{   r   r   r   r   r   r?   r=   r   r      sj   O$ #)II I !	I
 I I 
I: ^^ ^ 	^
 ^ ^ 
^> "&#$1b1b 1b 	1b
 1b 1b  1b !1b 
1bn ]] ] 	]
 ] ] ] 
]J @@ @ 3	@
 @ @ 
@28*	
>* !*T*T *T 	*T
 *T *T *T *T 
*Tr?   r   )'
__future__r   r~   typingr   r   bokeh.ior   r   r   bokeh.io.exportr	   bokeh.layoutsr
   bokeh.models.annotations.labelsr   bokeh.palettesr   bokeh.plottingr   numpyr*   	contourpyr   r   contourpy.util.bokeh_utilr   r   contourpy.util.rendererr   bokeh.modelsr   r   numpy.typingr   contourpy._contourpyr   r   r   r   r?   r=   <module>r      sN    " 	 % 1 1 1 " 1 % !  ( E ,%&&;dTH dTr?   