
    u×g                        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
mZmZmZmZ dZddZdddZdd	Zdd
ZdddZddZdddZ ed      ZddZy)a   Provide a set of decorators useful for repeatedly updating a
a function parameter in a specified way each time the function is
called.

These decorators can be especially useful in conjunction with periodic
callbacks in a Bokeh server application.

Example:

    As an example, consider the ``bounce`` forcing function, which
    advances a sequence forwards and backwards:

    .. code-block:: python

        from bokeh.driving import bounce

        @bounce([0, 1, 2])
        def update(i):
            print(i)

    If this function is repeatedly called, it will print the following
    sequence on standard out:

    .. code-block:: none

        0 1 2 2 1 0 0 1 2 2 1 ...

    )annotationsN)partial)AnyCallableIteratorSequenceTypeVar)bouncecosinecountforcelinearrepeatsinec                ^     t               d fd}t        t        t        |            S )a   Return a driver function that can advance a "bounced" sequence
    of values.

    .. code-block:: none

        seq = [0, 1, 2, 3]

        # bounce(seq) => [0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, ...]

    Args:
        sequence (seq) : a sequence of values for the driver to bounce

    c                R    t        |       \  }}|dz  dk(  r|   S |z
  dz
     S )N   r      )divmod)idivmodNsequences      -lib/python3.12/site-packages/bokeh/driving.pyfzbounce.<locals>.fZ   s:    !Q<S7a<C= AcE!G$$    r   r   intreturnr    lenr   r   _advancer   r   r   s   ` @r   r
   r
   K   s&     	HA% 58A;//r   c                `     ddl m d fd}t        t        t	        |            S )a   Return a driver function that can advance a sequence of cosine values.

    .. code-block:: none

        value = A * cos(w*i + phi) + offset

    Args:
        w (float) : a frequency for the cosine driver
        A (float) : an amplitude for the cosine driver
        phi (float) : a phase offset to start the cosine driver with
        offset (float) : a global offset to add to the driver values

    r   )cosc                ,     | z  z         z  z   S N )r   Ar'   offsetphiws    r   r   zcosine.<locals>.fq       3qsSy>!F**r   r   r   floatr!   r1   )mathr'   r   r   r$   )r.   r+   r-   r,   r   r'   s   ```` @r   r   r   b   #     + +58A;//r   c                 8    t        t        t        d             S )z@ Return a driver function that can advance a simple count.

    c                    | S r)   r*   )xs    r   <lambda>zcount.<locals>.<lambda>y   s    ar   r   r   r   r$   r*   r   r   r   r   u   s     58K#899r   c                     d fd}|S )z Return a decorator that can "force" a function with an arbitrary
    supplied generator

    Args:
        sequence (iterable) :
            generator to drive f with

    Returns:
        decorator

    c                 (      t                     y r)   )next)r   r   s   r   wrapperzforce.<locals>.wrapper   s    	$x.r   )r!   Noner*   )r   r   r<   s   `` r   r   r   {   s    Nr   c                H     d fd}t        t        t        |            S )z Return a driver function that can advance a sequence of linear values.

    .. code-block:: none

        value = m * i + b

    Args:
        m (float) : a slope for the linear driver
        b (float) : an offset for the linear driver

    c                    | z  z   S r)   r*   )r   bms    r   r   zlinear.<locals>.f   s    1uqyr   r   r0   r8   )rA   r@   r   s   `` r   r   r      s    58A;//r   c                ^     t               d fd}t        t        t        |            S )a   Return a driver function that can advance a repeated of values.

    .. code-block:: none

        seq = [0, 1, 2, 3]

        # repeat(seq) => [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ...]

    Args:
        sequence (seq) : a sequence of values for the driver to bounce

    c                    | z     S r)   r*   )r   r   r   s    r   r   zrepeat.<locals>.f   s    !}r   r   r   r"   r%   s   ` @r   r   r      s$     	HA58A;//r   c                `     ddl m d fd}t        t        t	        |            S )a   Return a driver function that can advance a sequence of sine values.

    .. code-block:: none

        value = A * sin(w*i + phi) + offset

    Args:
        w (float) : a frequency for the sine driver
        A (float) : an amplitude for the sine driver
        phi (float) : a phase offset to start the sine driver with
        offset (float) : a global offset to add to the driver values

    r   )sinc                ,     | z  z         z  z   S r)   r*   )r   r+   r,   r-   rE   r.   s    r   r   zsine.<locals>.f   r/   r   r   r0   )r2   rE   r   r   r$   )r.   r+   r-   r,   r   rE   s   ```` @r   r   r      r3   r   Tc              #  0   K   d}	  | |       |dz  }w)z Yield a sequence generated by calling a given function with
    successively incremented integer values.

    Args:
        f (callable) :
            The function to advance

    Yields:
        f(i) where i increases each call

    r   r   r*   )r   r   s     r   r$   r$      s'      	
A
d
	Q s   )r   zSequence[int]r!   partial[Callable[[], None]])r   r   r   )
r.   r1   r+   r1   r-   r1   r,   r1   r!   rI   )r!   rI   )r   zCallable[[Any], None]r   zIterator[Any]r!   zCallable[[], None])r   r   )rA   r1   r@   r1   r!   rI   )r   zCallable[[int], T]r!   zIterator[T])__doc__
__future__r   logging	getLogger__name__log	functoolsr   typingr   r   r   r   r	   __all__r
   r   r   r   r   r   r   rG   r$   r*   r   r   <module>rS      sn   @ # g!  0.0&: 0 0$06 CLr   