
    -e9                       U d Z 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mZmZ ddlmZmZ ddlmZmZmZmZmZ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  ddl!m"Z" ddlm#Z# dZ$er3e
e	e%         e	e&e%e%f                  e	e&e%e%e%f                  f         Z'de(d<   dBdCdZ)dDdEdZ*	 	 	 dFdGd*Z+	 	 	 dHdId/Z,	 	 dJdKd2Z-	 	 dJdLd4Z.	 	 	 dMdNd:Z/	 	 	 dFdGd;Z0	 	 	 dFdGd<Z1dOd>Z2dPdAZ3dS )Qz Helper functions for applying client-side computations such as
transformations to data fields or ``ColumnDataSource`` expressions.

    )annotationsN)TYPE_CHECKINGSequenceUnion   )ExprField)CumSumStack)CategoricalColorMapperCategoricalMarkerMapperCategoricalPatternMapperEqHistColorMapperLinearColorMapperLogColorMapper)DodgeJitter)	TypeAlias)	ColorLike)JitterRandomDistributionType)Range)	Transform)cumsumdodgeeqhist_cmapfactor_cmapfactor_hatchfactor_markjitterlinear_cmaplog_cmapstack	transformr   FactorsF
field_namestrinclude_zeroboolreturnr   c                >    t          t          | |                    S )a+   Create a ``DataSpec`` dict to generate a ``CumSum`` expression
    for a ``ColumnDataSource``.

    Args:
        field_name (str) : a field name to configure ``CumSum`` with

        include_zero (bool, optional) : whether to include zero in the sum
            (default: False)

    Examples:

        .. code-block:: python

            p.wedge(start_angle=cumsum('angle', include_zero=True),
                    end_angle=cumsum('angle'),
                    ...)

        will generate a ``CumSum`` expressions that sum the ``"angle"`` column
        of a data source. For the ``start_angle`` value, the cumulative sums
        will start with a zero value. For ``end_angle``, no initial zero will
        be added (i.e. the sums will start with the first angle value, and
        include the last).

    )fieldr'   )r   r
   )r%   r'   s     /lib/python3.11/site-packages/bokeh/transform.pyr   r   I   s    2 ZlCCCDDD    valuefloatrangeRange | Noner	   c                @    t          | t          ||                    S )a   Create a ``DataSpec`` dict that applies a client-side ``Dodge``
    transformation to a ``ColumnDataSource`` column.

    Args:
        field_name (str) : a field name to configure ``DataSpec`` with

        value (float) : the fixed offset to add to column data

        range (Range, optional) : a range to use for computing synthetic
            coordinates when necessary, e.g. a ``FactorRange`` when the
            column data is categorical (default: None)

    Returns:
        Field

    )r.   r0   )r	   r   )r%   r.   r0   s      r,   r   r   d   s!    " Ue<<<===r-   graypaletteSequence[ColorLike]lowhigh	low_colorColorLike | None
high_color	nan_colorr   c                H    t          | t          ||||||                    S )ag   Create a ``DataSpec`` dict that applies a client-side
    ``EqHistColorMapper`` transformation to a ``ColumnDataSource`` column.

    Args:
        field_name (str) : a field name to configure ``DataSpec`` with

        palette (seq[color]) : a list of colors to use for colormapping

        low (float) : a minimum value of the range to map into the palette.
            Values below this are clamped to ``low``.

        high (float) : a maximum value of the range to map into the palette.
            Values above this are clamped to ``high``.

        low_color (color, optional) : 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. (default: None)

        high_color (color, optional) : 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. (default: None)

        nan_color (color, optional) : a default color to use when mapping data
            from a column does not succeed (default: "gray")

    r4   r6   r7   r;   r8   r:   )r	   r   r%   r4   r6   r7   r8   r:   r;   s          r,   r   r   w   >    F !	
 	
 	

 
 
r-   factorsstartendfloat | Nonec           
     F    t          | t          |||||                    S )aT   Create a ``DataSpec`` dict that applies a client-side
    ``CategoricalColorMapper`` transformation to a ``ColumnDataSource``
    column.

    Args:
        field_name (str) : a field name to configure ``DataSpec`` with

        palette (seq[color]) : a list of colors to use for colormapping

        factors (seq) : a sequence of categorical factors corresponding to
            the palette

        start (int, optional) : a start slice index to apply when the column
            data has factors with multiple levels. (default: 0)

        end (int, optional) : an end slice index to apply when the column
            data has factors with multiple levels. (default: None)

        nan_color (color, optional) : a default color to use when mapping data
            from a column does not succeed (default: "gray")

    Returns:
        Field

    )r4   r@   rA   rB   r;   )r	   r   )r%   r4   r@   rA   rB   r;   s         r,   r   r      s;    B 	
 	
 	
	 	 	r-   patternsSequence[str]c           	     D    t          | t          ||||                    S )a   Create a ``DataSpec`` dict that applies a client-side
    ``CategoricalPatternMapper`` transformation to a ``ColumnDataSource``
    column.

    Args:
        field_name (str) : a field name to configure ``DataSpec`` with

        patterns (seq[string]) : a list of hatch patterns to use to map to

        factors (seq) : a sequences of categorical factors corresponding to
            the palette

        start (int, optional) : a start slice index to apply when the column
            data has factors with multiple levels. (default: 0)

        end (int, optional) : an end slice index to apply when the column
            data has factors with multiple levels. (default: None)

    Returns:
        Field

    Added in version 1.1.1

    )rE   r@   rA   rB   )r	   r   )r%   rE   r@   rA   rB   s        r,   r   r      s7    >  		
 	
 	
  r-   markersc           	     D    t          | t          ||||                    S )aG   Create a ``DataSpec`` dict that applies a client-side
    ``CategoricalMarkerMapper`` transformation to a ``ColumnDataSource``
    column.

    .. note::
        This transform is primarily only useful with ``scatter``, which
        can be parameterized by glyph type.

    Args:
        field_name (str) : a field name to configure ``DataSpec`` with

        markers (seq[string]) : a list of markers to use to map to

        factors (seq) : a sequences of categorical factors corresponding to
            the palette

        start (int, optional) : a start slice index to apply when the column
            data has factors with multiple levels. (default: 0)

        end (int, optional) : an end slice index to apply when the column
            data has factors with multiple levels. (default: None)

    Returns:
        Field

    )rH   r@   rA   rB   )r	   r   )r%   rH   r@   rA   rB   s        r,   r   r      s8    B 		
 	
 	
  r-   uniformwidthmeandistributionr   c           	     D    t          | t          ||||                    S )a   Create a ``DataSpec`` dict that applies a client-side ``Jitter``
    transformation to a ``ColumnDataSource`` column.

    Args:
        field_name (str) : a field name to configure ``DataSpec`` with

        width (float) : the width of the random distribution to apply

        mean (float, optional) : an offset to apply (default: 0)

        distribution (str, optional) : ``"uniform"`` or ``"normal"``
            (default: ``"uniform"``)

        range (Range, optional) : a range to use for computing synthetic
            coordinates when necessary, e.g. a ``FactorRange`` when the
            column data is categorical (default: None)

    Returns:
        Field

    )rL   rK   rM   r0   )r	   r   )r%   rK   rL   rM   r0   s        r,   r   r   &  s7    8 %		
 	
 	
  r-   c                H    t          | t          ||||||                    S )ag   Create a ``DataSpec`` dict that applies a client-side
    ``LinearColorMapper`` transformation to a ``ColumnDataSource`` column.

    Args:
        field_name (str) : a field name to configure ``DataSpec`` with

        palette (seq[color]) : a list of colors to use for colormapping

        low (float) : a minimum value of the range to map into the palette.
            Values below this are clamped to ``low``.

        high (float) : a maximum value of the range to map into the palette.
            Values above this are clamped to ``high``.

        low_color (color, optional) : 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. (default: None)

        high_color (color, optional) : 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. (default: None)

        nan_color (color, optional) : a default color to use when mapping data
            from a column does not succeed (default: "gray")

    r=   )r	   r   r>   s          r,   r    r    L  r?   r-   c                H    t          | t          ||||||                    S )ad   Create a ``DataSpec`` dict that applies a client-side ``LogColorMapper``
    transformation to a ``ColumnDataSource`` column.

    Args:
        field_name (str) : a field name to configure ``DataSpec`` with

        palette (seq[color]) : a list of colors to use for colormapping

        low (float) : a minimum value of the range to map into the palette.
            Values below this are clamped to ``low``.

        high (float) : a maximum value of the range to map into the palette.
            Values above this are clamped to ``high``.

        low_color (color, optional) : 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. (default: None)

        high_color (color, optional) : 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. (default: None)

        nan_color (color, optional) : a default color to use when mapping data
            from a column does not succeed (default: "gray")

    r=   )r	   r   r>   s          r,   r!   r!   {  s>    F !	
 	
 	

 
 
r-   fieldsc                 <    t          t          |                     S )a   Create a Create a ``DataSpec`` dict to generate a ``Stack`` expression
    for a ``ColumnDataSource``.

    Examples:

        .. code-block:: python

            p.vbar(bottom=stack("sales", "marketing"), ...

        will generate a ``Stack`` that sums the ``"sales"`` and ``"marketing"``
        columns of a data source, and use those values as the ``top``
        coordinate for a ``VBar``.

    rQ   )r   r   rS   s    r,   r"   r"     s      V$$$%%%r-   r#   r   c                "    t          | |          S )a.   Create a ``DataSpec`` dict that applies an arbitrary client-side
    ``Transform`` to a ``ColumnDataSource`` column.

    Args:
        field_name (str) : A field name to configure ``DataSpec`` with

        transform (Transform) : A transforms to apply to that field

    Returns:
        Field

    )r	   )r%   r#   s     r,   r#   r#     s     Y'''r-   )F)r%   r&   r'   r(   r)   r   )N)r%   r&   r.   r/   r0   r1   r)   r	   )NNr3   )r%   r&   r4   r5   r6   r/   r7   r/   r8   r9   r:   r9   r;   r   r)   r	   )r   Nr3   )r%   r&   r4   r5   r@   r$   rA   r/   rB   rC   r;   r   r)   r	   )r   N)r%   r&   rE   rF   r@   r$   rA   r/   rB   rC   r)   r	   )r%   r&   rH   rF   r@   r$   rA   r/   rB   rC   r)   r	   )r   rJ   N)r%   r&   rK   r/   rL   r/   rM   r   r0   r1   r)   r	   )rQ   r&   r)   r   )r%   r&   r#   r   r)   r	   )4__doc__
__future__r   logging	getLogger__name__logtypingr   r   r   core.property.vectorizationr   r	   models.expressionsr
   r   models.mappersr   r   r   r   r   r   models.transformsr   r   typing_extensionsr   colorsr   
core.enumsr   models.rangesr   r   __all__r&   tupler$   __annotations__r   r   r   r   r   r   r   r    r!   r"   r#    r-   r,   <module>rh      s     # " " " " " g!! 2 1 1 1 1 1 1 1 1 1 5 4 4 4 4 4 4 4 - - - - - - - -                - , , , , , , , -++++++!!!!!!888888$$$$$$,,,,,,$  ix}huS#X.GRWX[]`beXeRfIgghGhhhhE E E E E6> > > > >0 #'#'!- - - - -f !* * * * *` ' ' ' ' 'Z ) ) ) ) )\ 1:$ $ $ $ $V #'#'!- - - - -h #'#'!- - - - -^& & & &$( ( ( ( ( (r-   