
    d-9                       U d dl mZ d dlZ ej        e          Zd dlmZmZm	Z	 d dl
ZddlmZmZmZ ddlmZmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ er@d dlm Z  d dl!m"Z" ddlm#Z#m$Z$ ddl%m&Z& e	e&ee&         f         Z'de(d<   e	e'e#e$e'f         Z)de(d<   dZ* ed           G d d                      Z+ ed           G d d                      Z, ed           G d d                      Z- ed           G d de+                      Z. ed           G d de,                      Z/ ed           G d  d!                      Z0	 	 	 	 d=ddd"d>d-Z1	 	 	 	 d=d?d/Z2 ed           G d0 d1                      Z3 ed           G d2 d3                      Z4d@d7Z5dAd9Z6dBd:Z7dCd;Z8dDd<Z9dS )E    )annotationsN)TYPE_CHECKINGSequenceUnion   )	FillProps
HatchProps	LineProps)	MultiLineMultiPolygons)ContourRendererGlyphRenderer)ColumnDataSource)linear_palette)_process_sequence_literals)	dataclassentries)	ArrayLike)	TypeAlias)PalettePaletteCollection)	ColorLiker   ContourColorContourColorOrPalette)contour_datafrom_contourT)frozenc                  (    e Zd ZU dZded<   ded<   dS )
FillCoordszR Coordinates for all filled polygons over a whole sequence of contour levels.
    zlist[list[list[np.ndarray]]]xsysN__name__
__module____qualname____doc____annotations__     6lib/python3.11/site-packages/bokeh/plotting/contour.pyr   r   :   s4          $$$$$$$$$$r)   r   c                  (    e Zd ZU dZded<   ded<   dS )
LineCoordszP Coordinates for all contour lines over a whole sequence of contour levels.
    zlist[np.ndarray]r    r!   Nr"   r(   r)   r*   r,   r,   A   s4          r)   r,   c                  (    e Zd ZU dZded<   ded<   dS )ContourCoordszP Combined filled and line contours over a whole sequence of contour levels.
    zFillCoords | Nonefill_coordszLineCoords | Noneline_coordsNr"   r(   r)   r*   r.   r.   H   s4          """"""""""r)   r.   c                  .    e Zd ZU dZded<   ded<   d ZdS )FillDatazY Complete geometry data for filled polygons over a whole sequence of contour levels.
    r   lower_levelsupper_levelsc                :    t          t          |                     S Ndictr   selfs    r*   asdictzFillData.asdictV       GDMM"""r)   Nr#   r$   r%   r&   r'   r;   r(   r)   r*   r2   r2   O   sG          # # # # #r)   r2   c                  $    e Zd ZU dZded<   d ZdS )LineDatazW Complete geometry data for contour lines over a whole sequence of contour levels.
    r   levelsc                :    t          t          |                     S r6   r7   r9   s    r*   r;   zLineData.asdict`   r<   r)   Nr=   r(   r)   r*   r?   r?   Z   s;          # # # # #r)   r?   c                  (    e Zd ZU dZded<   ded<   dS )ContourDataa   Complete geometry data for filled polygons and/or contour lines over a
    whole sequence of contour levels.

    :func:`~bokeh.plotting.contour.contour_data` returns an object of
    this class that can then be passed to :func:`bokeh.models.ContourRenderer.set_data`.
    zFillData | None	fill_datazLineData | None	line_dataNr"   r(   r)   r*   rC   rC   d   6           r)   rC   )	want_fill	want_linexArrayLike | Noneyz$ArrayLike | np.ma.MaskedArray | Noner@   rG   boolrH   returnc                  t          |          }t          |          dk     rd}|s|st          d          t          | |||||          }d}|j        r4|j        }t          |j        |j        |dd         |dd                   }d}	|j        r#|j        }
t          |
j        |
j        |          }	t          ||	          S )	z Return the contour data of filled and/or line contours that can be
    passed to :func:`bokeh.models.ContourRenderer.set_data`
    r   Fz/Neither fill nor line requested in contour_dataN   )r    r!   r3   r4   )r    r!   r@   )_validate_levelslen
ValueError_contour_coordsr/   r2   r    r!   r0   r?   rC   )rI   rK   rL   r@   rG   rH   coordsrD   r/   rE   r0   s              r*   r   r   o   s     f%%F
6{{Q	 LY LJKKKQ1fiCCFI v(;>PVWZXZWZP[jpqrqsqsjtuuu	I R(;>&QQQ	y),,,r)   r   c                   t          |          }t          |          dk     rd}t          |          }|                    dd          du}|rtt          |d         |          |d<   t	                      }t          t          ||d           i }	t          j                    D ]}
|	                    |
d          }|||	|
<    n|	                    dd           |                    dd          du}|rBt          |d         |dz
            |d<   t	                      }t          t          ||d           n|	                    dd           |                                t          j                    z
  t          j                    z
  }|r%t          dd                    |                     t!          | |||||	          }t#          t%          t                      t	                      
          t%          t                      t	                      
          t'          |                    }|                    |           |j        r|j        j        }|                                D ]\  }
}t3          ||
|           |j        j        }|j                                        D ]\  }
}|                    ||
           d|_        d|_        |j        rx|j         j        }|	                                D ]\  }
}t3          ||
|           |j         j        }|j                                        D ]\  }
}|                    ||
           |S )an	   Creates a :class:`bokeh.models.ContourRenderer` containing filled
    polygons and/or contour lines.

    Usually it is preferable to call :func:`~bokeh.plotting.figure.contour`
    instead of this function.

    Filled contour polygons are calculated if ``fill_color`` is set,
    contour lines if ``line_color`` is set.

    Args:
        x (array-like[float] of shape (ny, nx) or (nx,), optional) :
            The x-coordinates of the ``z`` values. May be 2D with the same
            shape as ``z.shape``, or 1D with length ``nx = z.shape[1]``.
            If not specified are assumed to be ``np.arange(nx)``. Must be
            ordered monotonically.

        y (array-like[float] of shape (ny, nx) or (ny,), optional) :
            The y-coordinates of the ``z`` values. May be 2D with the same
            shape as ``z.shape``, or 1D with length ``ny = z.shape[0]``.
            If not specified are assumed to be ``np.arange(ny)``. Must be
            ordered monotonically.

        z (array-like[float] of shape (ny, nx)) :
            A 2D NumPy array of gridded values to calculate the contours
            of.  May be a masked array, and any invalid values (``np.inf``
            or ``np.nan``) will also be masked out.

        levels (array-like[float]) :
            The z-levels to calculate the contours at, must be increasing.
            Contour lines are calculated at each level and filled contours
            are calculated between each adjacent pair of levels so the
            number of sets of contour lines is ``len(levels)`` and the
            number of sets of filled contour polygons is ``len(levels)-1``.

        **visuals: |fill properties|, |hatch properties| and |line properties|
            Fill and hatch properties are used for filled contours, line
            properties for line contours. If using vectorized properties
            then the correct number must be used, ``len(levels)`` for line
            properties and ``len(levels)-1`` for fill and hatch properties.

            ``fill_color`` and ``line_color`` are more flexible in that
            they will accept longer sequences and interpolate them to the
            required number using :func:`~bokeh.palettes.linear_palette`,
            and also accept palette collections (dictionaries mapping from
            integer length to color sequence) such as
            `bokeh.palettes.Cividis`.

    r   F
line_colorN
fill_colorrR   z-Unknown keyword arguments in 'from_contour': z, )rI   rK   rL   r@   rG   rH   )glyphdata_source)fill_rendererline_rendererr@   r   )!rS   rT   get_colorr   r   r   r
   
propertiespopr   keysr   r	   rU   joinr   r   r   listset_datarD   r]   r[   itemssetattrr\   dataadd
line_alpha
line_widthrE   r^   )rI   rK   rL   r@   visualsrG   nlevelsrH   line_cdsline_visualsnamepropfill_cdsunknownnew_contour_datacontour_rendererr[   valuecdss                      r*   r   r      sg   n f%%F
6{{Q	&kkGL$//t;I ( &w|'<g F F#%%"9gxGGG (** 	* 	*D;;tT**D%)T"	*
 	L$'''L$//t;I ( &w|'<gai H H#%%"='8UKKKKL$''' llnny3555
8M8O8OOG _]SZI[I[]]^^^#a1&Iajkkk '#-//GWGYGYZZZ#)++CSCUCUVVVF||   .///! 
 .4"==?? 	( 	(KD%E4'''',8#=..00 	! 	!KD%GGE4    ! ! .4'--// 	( 	(KD%E4'''',8#=..00 	! 	!KD%GGE4    r)   c                  (    e Zd ZU dZded<   ded<   dS )SingleFillCoordsa*   Coordinates for filled contour polygons between a lower and upper level.

    The first list contains a list for each polygon. The second list contains
    a separate NumPy array for each boundary of that polygon; the first array
    is always the outer boundary, subsequent arrays are holes.
    zlist[list[np.ndarray]]r    r!   Nr"   r(   r)   r*   rz   rz     rF   r)   rz   c                  (    e Zd ZU dZded<   ded<   dS )SingleLineCoordsz Coordinates for contour lines at a single contour level.

    The x and y coordinates are stored in a single NumPy array each, with a
    np.nan separating each line.
    z
np.ndarrayr    r!   Nr"   r(   r)   r*   r|   r|     s.          
 NNNNNNNNr)   r|   colornintc                   t          | t                    r=|                     |d           } | rt          |           |k    rt	          d|           t          | t
                    rat          | t          t          f          sEt          |           |k     rt	          d          t          |           |k    rt          | |          } | S )Nz)Dict of colors does not contain a key of zInsufficient number of colors)	
isinstancer8   r_   rT   rU   r   bytesstrr   )r}   r~   s     r*   r`   r`   &  s    % N		!T"" 	NE

aLLLMMM%"" -:eeS\+J+J -u::>><===ZZ!^^"5!,,ELr)   r   c                   |s|st          d          ddlm}m}m}  || |||j        |j                  }	d}
|rg }g }t          t          |          dz
            D ]j}|		                    ||         ||dz                      }t          |          }|                    |j                   |                    |j                   kt          ||          }
d}|rqg }g }|D ]Z}|	                    |          }t!          |          }|                    |j                   |                    |j                   [t#          ||          }t%          |
|          S )zD
    Return the (xs, ys) coords of filled and/or line contours.
    z2Neither fill nor line requested in _contour_coordsr   )FillTypeLineTypecontour_generator)	line_type	fill_typeNrR   )RuntimeError	contourpyr   r   r   ChunkCombinedOffsetOuterOffsetrangerT   filled_filled_to_coordsappendr    r!   r   lines_lines_to_coordsr,   r.   )rI   rK   rL   r@   rG   rH   r   r   r   cont_genr/   all_xsall_ysir   rW   r0   levelr   s                      r*   rV   rV   5  s     QY QOPPP??????????  AqH4P\d\pqqqHK 1s6{{1}%% 	% 	%A__VAYqs<<F&v..FMM&)$$$MM&)$$$$ 00K 1 	% 	%ENN5))E%e,,FMM&)$$$MM&)$$$$ 00k222r)   c                ,   g }g }t          |  D ]u\  t                    dz
  }|                    fdt          |          D                        |                    fdt          |          D                        vt	          ||          S )NrR   c                F    g | ]}|         |d z            df         S )rR   r   r(   .0r   offsetspointss     r*   
<listcomp>z%_filled_to_coords.<locals>.<listcomp>h  4    HHH!6'!*WQqS\1145HHHr)   c                F    g | ]}|         |d z            d f         S )rR   r(   r   s     r*   r   z%_filled_to_coords.<locals>.<listcomp>i  r   r)   )ziprT   r   r   rz   )r   r    r!   r~   r   r   s       @@r*   r   r   ^  s    
 
B	B< J JLL1
		HHHHHuQxxHHHIII
		HHHHHuQxxHHHIIIIB###r)   c                V   | d         d         }|$t          j        d          }t          ||          S | d         d         }t          |          }t          |          dz
  }t          j        ||z   dz
            }t          j        ||z   dz
            }t	          |          D ]s}||         }	||dz            }
|dk    r*t           j        ||	|z   dz
  <   t           j        ||	|z   dz
  <   ||	|
df         ||	|z   |
|z   <   ||	|
df         ||	|z   |
|z   <   tt          ||          S )Nr   rR   )npemptyr|   rT   r   nan)r   r   r   r   npointsnlinesr    r!   r   startends              r*   r   r   l  s@   
 1Xa[F~u---AhqkG&kkG\\AF	'F"1$	%	%B	'F"1$	%	%B6]] 1 1
aclq55FBuQwqyMFBuQwqyM"59a<0573q5="59a<0573q5=B###r)   c                    t          j        |           } | j        dk    st          |           dk    rt	          d          t          |           dk    r9t          j        |                                           dk    rt	          d          | S )Nr   zNo contour levels specifiedrR   g        z!Contour levels must be increasing)r   asarrayndimrT   rU   diffmin)r@   s    r*   rS   rS     s~    ZF{a3v;;!++6777
6{{Q276??..00C77<===Mr)   )NNNN)rI   rJ   rK   rJ   rL   rM   r@   rJ   rG   rN   rH   rN   rO   rC   )
rI   rJ   rK   rJ   rL   rM   r@   rJ   rO   r   )r}   r   r~   r   rO   r   )rI   rJ   rK   rJ   rL   rM   r@   r   rG   rN   rH   rN   rO   r.   )rO   rz   )rO   r|   )r@   rJ   ):
__future__r   logging	getLoggerr#   logtypingr   r   r   numpyr   core.property_mixinsr   r	   r
   models.glyphsr   r   models.renderersr   r   models.sourcesr   palettesr   plotting._rendererr   util.dataclassesr   r   numpy.typingr   typing_extensionsr   r   r   	transformr   r   r'   r   __all__r   r,   r.   r2   r?   rC   r   r   rz   r|   r`   rV   r   r   rS   r(   r)   r*   <module>r      s   # " " " " " " g!! 2 1 1 1 1 1 1 1 1 1     D C C C C C C C C C 4 4 4 4 4 4 4 4 = = = = = = = = - - - - - - % % % % % % ; ; ; ; ; ; 1 1 1 1 1 1 1 1 e&&&&&&++++++55555555%%%%%%#Ix	/B$BCLCCCC',\7DUWc-c'ddddd $% % % % % % % % $        $# # # # # # # # $# # # # #z # # # $# # # # #z # # # $        .2#	- - - - - - -D .2#	{ { { { {B $        $          '3 '3 '3 '3R$ $ $ $$ $ $ $4     r)   