
    -e5                       d Z ddlmZ ddlZ ej        e          ZddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZ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Z&e G d de%                      Z'e G d de'                      Z(e G d de'                      Z) G d de)e(          Z* G d de)          Z+ G d de)          Z,e G d de(                      Z- G d de-          Z. G d d e-          Z/e G d! d"e-                      Z0 G d# d$e0          Z1e G d% d&e(                      Z2 G d' d(e2          Z3dS ))z Models for mapping values from one range or space to another in the client.

Mappers (as opposed to scales) are not presumed to be invertible.

    )annotationsN   )palettes)Palette)abstract)BoolColorEitherEnum	FactorSeqFloatHatchPatternTypeInstanceIntList
MarkerTypeNullableSeqStringTuple)errorwarning)1WEIGHTED_STACK_COLOR_MAPPER_LABEL_LENGTH_MISMATCH)PALETTE_LENGTH_FACTORS_MISMATCH   )	Transform)MapperColorMapperCategoricalMapperCategoricalColorMapperCategoricalMarkerMapperCategoricalPatternMapperContinuousColorMapperLinearColorMapperLogColorMapperEqHistColorMapperStackColorMapperWeightedStackColorMapperc                  $     e Zd ZdZd fdZ xZS )r   z Base class for mappers.

    returnNonec                :     t                      j        |i | d S Nsuper__init__selfargskwargs	__class__s      4lib/python3.11/site-packages/bokeh/models/mappers.pyr0   zMapper.__init__Q   %    $)&)))))    r*   r+   __name__
__module____qualname____doc__r0   __classcell__r5   s   @r6   r   r   J   sG         
* * * * * * * * * *r8   r   c                       e Zd ZdZd fdZ eed                               ee	          d           Z
 edd	
          Z xZS )r   z) Base class for color mapper types.

    r*   r+   c                v    t          |          dk    r|d         |d<    t                      j        di | d S )Nr   r   palette )lenr/   r0   r1   s      r6   r0   zColorMapper.__init__[   sC    t99>> $QF9""6"""""r8   z
    A sequence of colors to use as the target palette for mapping.

    This property can also be set as a ``String``, to the name of any of the
    palettes shown in :ref:`bokeh.palettes`.
    helpc                ,    t          t          |           S r-   )getattrr   )pals    r6   <lambda>zColorMapper.<lambda>e   s    GHc,B,B r8   grayzD
    Color to be used if data is NaN or otherwise not mappable.
    defaultrG   r9   )r;   r<   r=   r>   r0   r   r	   acceptsr   r   rC   	nan_colorr?   r@   s   @r6   r   r   U   s         # # # # # #
 c%  	 	 	
 
g B B	C	C  f , 	 	 	IIIIIr8   r   c                  p     e Zd ZdZd fdZ ed          Z edd	          Z e	ed
          Z
 xZS )r   zK Base class for mappers that map categorical factors to other values.

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   zCategoricalMapper.__init__s   r7   r8   a=  
    A sequence of factors / categories that map to the some target range. For
    example the following color mapper:

    .. code-block:: python

        mapper = CategoricalColorMapper(palette=["red", "blue"], factors=["foo", "bar"])

    will map the factor ``"foo"`` to red and the factor ``"bar"`` to blue.
    rF   r   aw  
    A start index to "slice" data factors with before mapping.

    For example, if the data to color map consists of 2-level factors such
    as ``["2016", "sales"]`` and ``["2016", "marketing"]``, then setting
    ``start=1`` will perform color mapping only based on the second sub-factor
    (i.e. in this case based on the department ``"sales"`` or ``"marketing"``)
    rM   a  
    A start index to "slice" data factors with before mapping.

    For example, if the data to color map consists of 2-level factors such
    as ``["2016", "sales"]`` and ``["2017", "marketing"]``, then setting
    ``end=1`` will perform color mapping only based on the first sub-factor
    (i.e. in this case based on the year ``"2016"`` or ``"2017"``)

    If ``None`` then all sub-factors from ``start`` to the end of the
    factor will be used for color mapping.
    r9   )r;   r<   r=   r>   r0   r   factorsr   startr   endr?   r@   s   @r6   r   r   l   s         
* * * * * * i 	 		 		 		G C ! 	 	 	E (3 
 
	 
	 
	CCCCCr8   r   c                  L     e Zd ZdZd fdZ ee          d             Z xZS )r    z Map categorical factors to colors.

    Values that are passed to this mapper that are not in the factors list
    will be mapped to ``nan_color``.

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   zCategoricalColorMapper.__init__   r7   r8   c                    | j         }| j        }t          |          t          |          k     r#|t          |          d          }| d| j         S d S )Nz! will be assigned to `nan_color` )rC   rS   rE   rP   )r2   rC   rS   extra_factorss       r6   _check_palette_lengthz,CategoricalColorMapper._check_palette_length   sY    ,,w<<#g,,&&#CLLMM2M#VVdnVVV '&r8   r9   )	r;   r<   r=   r>   r0   r   r   rZ   r?   r@   s   @r6   r    r       su         * * * * * * W,--W W .-W W W W Wr8   r    c                  X     e Zd ZdZd
 fdZ eed          Z edd	          Z xZ	S )r!   a1   Map categorical factors to marker types.

    Values that are passed to this mapper that are not in the factors list
    will be mapped to ``default_value``.

    .. note::
        This mappers is primarily only useful with the ``Scatter`` marker
        glyph that be parameterized by marker type.

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   z CategoricalMarkerMapper.__init__   r7   r8   F
    A sequence of marker types to use as the target for mapping.
    rF   circlez\
    A marker type to use in case an unrecognized factor is passed in to be
    mapped.
    rM   r9   )
r;   r<   r=   r>   r0   r   r   markersdefault_valuer?   r@   s   @r6   r!   r!      sy        	 	* * * * * * c* $ 	 	 	G Jx 7 	 	 	MMMMMr8   r!   c                  X     e Zd ZdZd
 fdZ eed          Z edd	          Z xZ	S )r"   z Map categorical factors to hatch fill patterns.

    Values that are passed to this mapper that are not in the factors list
    will be mapped to ``default_value``.

    Added in version 1.1.1

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   z!CategoricalPatternMapper.__init__   r7   r8   r]   rF    z^
    A hatch pattern to use in case an unrecognized factor is passed in to be
    mapped.
    rM   r9   )
r;   r<   r=   r>   r0   r   r   patternsr`   r?   r@   s   @r6   r"   r"      s{         * * * * * * s# + 	 	 	H %$S 8 	 	 	MMMMMr8   r"   c                       e Zd ZdZd fdZ e e ed           ee	 ee	                              g d          Z
 eed	          Z eed
	          Z eed	          Z eed	          Z xZS )r#   z4 Base class for continuous color mapper types.

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   zContinuousColorMapper.__init__   r7   r8   z$bokeh.models.renderers.GlyphRendererz
    A collection of glyph renderers to pool data from for establishing data metrics.
    If empty, mapped data will be used instead.
    rM   z
    The minimum value of the range to map into the palette. Values below
    this are clamped to ``low``. If ``None``, the value is inferred from data.
    rF   z
    The maximum value of the range to map into the palette. Values above
    this are clamped to ``high``. If ``None``, the value is inferred from data.
    z
    Color to be used if data is lower than ``low`` value. If None,
    values lower than ``low`` are mapped to the first color in the palette.
    z
    Color to be used if data is higher than ``high`` value. If None,
    values higher than ``high`` are mapped to the last color in the palette.
    r9   )r;   r<   r=   r>   r0   r   r   r   r
   r   domainr   r   lowhighr	   	low_color
high_colorr?   r@   s   @r6   r#   r#      s        
* * * * * * T%%!GHH&&QWY]Y]^dYeYeJfJfggqs { 	 	 	F
 (5   	 	 	C
 8E ! 	 	 	D
  & 	 	 	I
 % ' 	 	 	JJJJJr8   r#   c                  $     e Zd ZdZd fdZ xZS )r$   a   Map numbers in a range [*low*, *high*] linearly into a sequence of
    colors (a palette).

    For example, if the range is [0, 99] and the palette is
    ``['red', 'green', 'blue']``, the values would be mapped as follows::

             x < 0  : 'red'     # values < low are clamped
        0 <= x < 33 : 'red'
       33 <= x < 66 : 'green'
       66 <= x < 99 : 'blue'
       99 <= x      : 'blue'    # values > high are clamped

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   zLinearColorMapper.__init__  r7   r8   r9   r:   r@   s   @r6   r$   r$      sG         * * * * * * * * * *r8   r$   c                  $     e Zd ZdZd fdZ xZS )r%   a   Map numbers in a range [*low*, *high*] into a sequence of colors
    (a palette) on a natural logarithm scale.

    For example, if the range is [0, 25] and the palette is
    ``['red', 'green', 'blue']``, the values would be mapped as follows::

                x < 0     : 'red'     # values < low are clamped
       0     <= x < 2.72  : 'red'     # math.e ** 1
       2.72  <= x < 7.39  : 'green'   # math.e ** 2
       7.39  <= x < 20.09 : 'blue'    # math.e ** 3
       20.09 <= x         : 'blue'    # values > high are clamped

    .. warning::
        The ``LogColorMapper`` only works for images with scalar values that are
        non-negative.

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   zLogColorMapper.__init__%  r7   r8   r9   r:   r@   s   @r6   r%   r%     sG         &* * * * * * * * * *r8   r%   c                        e Zd Zd fdZ xZS )ScanningColorMapperr*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   zScanningColorMapper.__init__,  r7   r8   r9   )r;   r<   r=   r0   r?   r@   s   @r6   rq   rq   (  s=        * * * * * * * * * *r8   rq   c                  X     e Zd ZdZd
 fdZ edd          Z edd	          Z xZ	S )r&   z

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   zEqHistColorMapper.__init__6  r7   r8   i   zNumber of histogram binsrM   Fz
    If there are only a few discrete levels in the values that are color
    mapped then ``rescale_discrete_levels=True`` decreases the lower limit of
    the span so that the values are rendered towards the top end of the
    palette.
    r9   )
r;   r<   r=   r>   r0   r   binsr   rescale_discrete_levelsr?   r@   s   @r6   r&   r&   0  st         
* * * * * * 3w%?@@@D"d5 8 	 	 	r8   r&   c                  $     e Zd ZdZd fdZ xZS )r'   z Abstract base class for color mappers that operate on ``ImageStack``
    glyphs.

    These map 3D data arrays of shape ``(ny, nx, nstack)`` to 2D RGBA images
    of shape ``(ny, nx)``.

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   zStackColorMapper.__init__M  r7   r8   r9   r:   r@   s   @r6   r'   r'   B  sG         * * * * * * * * * *r8   r'   c                       e Zd ZdZd
 fdZ eed          Z ee	d          Z
 e ee          d          Z ee          d	             Z xZS )r(   a8   Maps 3D data arrays of shape ``(ny, nx, nstack)`` to 2D RGBA images
    of shape ``(ny, nx)`` using a palette of length ``nstack``.

    The mapping occurs in two stages. Firstly the RGB values are calculated
    using a weighted sum of the palette colors in the ``nstack`` direction.
    Then the alpha values are calculated using the ``alpha_mapper`` applied to
    the sum of the array in the ``nstack`` direction.

    The RGB values calculated by the ``alpha_mapper`` are ignored by the color
    mapping but are used in any ``ColorBar`` that is displayed.

    r*   r+   c                :     t                      j        |i | d S r-   r.   r1   s      r6   r0   z!WeightedStackColorMapper.__init___  r7   r8   zM
    Color mapper used to calculate the alpha values of the mapped data.
    rF   a  
    Baseline value used for the weights when calculating the weighted sum of
    palette colors. If ``None`` then the minimum of the supplied data is used
    meaning that values at this minimum have a weight of zero and do not
    contribute to the weighted sum. As a special case, if all data for a
    particular output pixel are at the color baseline then the color is an
    evenly weighted average of the colors corresponding to all such values,
    to avoid the color being undefined.
    aQ  
    An optional sequence of strings to use as labels for the ``nstack`` stacks.
    If set, the number of labels should match the number of stacks and hence
    also the number of palette colors.

    The labels are used in hover tooltips for ``ImageStack`` glyphs that use a
    ``WeightedStackColorMapper`` as their color mapper.
    c                   | j         {t          | j                   }t          | j                  }||k    r| j         d |         | _         | d| dS ||k     r-t          | j                   dg||z
  z  z   | _         | d| dS d S d S )Nz != z , removing unwanted stack_labels z, padding with empty strings)stack_labelsrE   rC   list)r2   nlabelnpalettes      r6   _check_label_lengthz,WeightedStackColorMapper._check_label_lengthy  s    (*++F4<((H  $($5ixi$@! PPhPPPP(""$():$;$;rdHvDU>V$V! LLhLLLL )( #"r8   r9   )r;   r<   r=   r>   r0   r   r#   alpha_mapperr   r   color_baseliner   r   r}   r   r   r   r?   r@   s   @r6   r(   r(   P  s         * * * * * * 81 9 	 	 	L Xe + 	 	 	N 8CCKK / 	 	 	L U<==	M 	M >=	M 	M 	M 	M 	Mr8   r(   )4r>   
__future__r   logging	getLoggerr;   logr|   r   
core.enumsr   core.has_propsr   core.propertiesr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   core.validationr   r   core.validation.errorsr   core.validation.warningsr   
transformsr   __all__r   r   r   r    r!   r"   r#   r$   r%   rq   r&   r'   r(   rD   r8   r6   <module>r      s	    # " " " " " g!!                   % % % % % %                                 " - , , , , , , , V V V V V V F F F F F F ! ! ! ! ! !& 
* * * * *Y * * 
* 
	 	 	 	 	& 	 	 
	, 
'	 '	 '	 '	 '	 '	 '	 
'	TW W W W W. W W W(	 	 	 	 	/ 	 	 	2	 	 	 	 	0 	 	 	. 
 	  	  	  	  	K  	  	 
 	D* * * * *- * * *&* * * * ** * * *. 
* * * * */ * * 
*	 	 	 	 	+ 	 	 	$ 
* * * * *{ * * 
*3M 3M 3M 3M 3M/ 3M 3M 3M 3M 3Mr8   