
    -e<                       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rBd dlm Z 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-                      Z0 ed           G d  d!                      Z1	 	 	 	 dBddd"dCd-Z2	 	 	 	 dBdDd/Z3 ed           G d0 d1                      Z4 ed           G d2 d3                      Z5dEd7Z6dFd9Z7dGd:Z8dHd;Z9dId?Z:dJdAZ;dS )K    )annotationsN)TYPE_CHECKINGSequenceUnion   )	FillProps
HatchProps	LineProps)	MultiLineMultiPolygons)ContourRendererGlyphRenderer)ColumnDataSource)interp_palette)_process_sequence_literals)	dataclassentries)	ArrayLikeNDArray)	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+   r3   r3   O   sG          # # # # #r*   r3   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 r7   r8   r:   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+   rD   rD   d   6           r*   rD   )	want_fill	want_linexArrayLike | Noneyz$ArrayLike | np.ma.MaskedArray | NonerA   rH   boolrI   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"   r4   r5   )r!   r"   rA   )_validate_levelslen
ValueError_contour_coordsr0   r3   r!   r"   r1   r@   rD   )rJ   rL   rM   rA   rH   rI   coordsrE   r0   rF   r1   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<   d|v rt          |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_colorrS   hatch_colorz-Unknown keyword arguments in 'from_contour': z, )rJ   rL   rM   rA   rH   rI   )glyphdata_source)fill_rendererline_rendererrA   r   )!rT   rU   get_colorr   r   r   r
   
propertiespopr   keysr   r	   rV   joinr   r   r   listset_datarE   r_   r]   itemssetattrr^   dataadd
line_alpha
line_widthrF   r`   )rJ   rL   rM   rA   visualsrH   nlevelsrI   line_cdsline_visualsnamepropfill_cdsunknownnew_contour_datacontour_rendererr]   valuecdss                      r+   r   r      s   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G##%+GM,BGAI%N%NGM"#%%"='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+   r|   r|     rG   r*   r|   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t          | |          S t          | t                    r?t          | t          t
          f          s#t          |           |k    rt          | |          S | S r7   )
isinstancer9   _palette_from_collectionr   bytesstrrU   r   )r   r   s     r+   rb   rb   (  sp    % 2'q111%"" (:eeS\+J+J (sSXzz]^eQ'''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_typeNrS   )RuntimeError	contourpyr   r   r   ChunkCombinedOffsetOuterOffsetrangerU   filled_filled_to_coordsappendr!   r"   r    lines_lines_to_coordsr-   r/   )rJ   rL   rM   rA   rH   rI   r   r   r   cont_genr0   all_xsall_ysir   rX   r1   levelr   s                      r+   rW   rW   2  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 )NrS   c                F    g | ]}|         |d z            df         S )rS   r   r)   .0r   offsetspointss     r+   
<listcomp>z%_filled_to_coords.<locals>.<listcomp>e  4    HHH!6'!*WQqS\1145HHHr*   c                F    g | ]}|         |d z            d f         S )rS   r)   r   s     r+   r   z%_filled_to_coords.<locals>.<listcomp>f  r   r*   )ziprU   r   r   r|   )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   rS   )npemptyr~   rU   r   nan)r   r   r   r   npointsnlinesr!   r"   r   startends              r+   r   r   i  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*   
collectionr   r   c                   t          |           dk     rt          d          |                     |d           }||S t          |                                           }t          |t                    r||k    rt          | |         |          S t          |                                           }t          |t                    r||k     rt          | |         |          S t          d| d          )NrS   zPaletteCollection is emptyz3Unable to extract or interpolate palette of length z from PaletteCollection)	rU   rV   ra   maxre   r   r   r   min)r   r   palettemax_keymin_keys        r+   r   r     s     :5666nnQ%%G*//##$$G'3 6AKKj11555*//##$$G'3 6AKKj11555
e1eee
f
ffr*   NDArray[float]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 specifiedrS   g        z!Contour levels must be increasing)r   asarrayndimrU   rV   diffr   )rA   s    r+   rT   rT     s~    ZF{a3v;;!++6777
6{{Q276??..00C77<===Mr*   )NNNN)rJ   rK   rL   rK   rM   rN   rA   rK   rH   rO   rI   rO   rP   rD   )
rJ   rK   rL   rK   rM   rN   rA   rK   rP   r   )r   r   r   r   rP   r   )rJ   rK   rL   rK   rM   rN   rA   r   rH   rO   rI   rO   rP   r/   )rP   r|   )rP   r~   )r   r   r   r   rP   r   )rA   rK   rP   r   )<
__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   r   typing_extensionsr   r   r   	transformr   r   r(   r   __all__r    r-   r/   r3   r@   rD   r   r   r|   r~   rb   rW   r   r   r   rT   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#	} } } } }F $        $          '3 '3 '3 '3R$ $ $ $$ $ $ $4g g g g.     r*   