
    -e                        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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dS )*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IterableIteratorSequenceTypeVar)bouncecosinecountforcelinearrepeatsinesequenceSequence[int]returnpartial[Callable[[], None]]c                x     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

    iintr   c                h    t          |           \  }}|dz  dk    r|         S |z
  dz
           S )N   r      )divmod)r   divmodNr   s      -lib/python3.11/site-packages/bokeh/driving.pyfzbounce.<locals>.f[   s>    !Q<<S7a<<C= AcE!G$$    r   r   r   r   r   lenr   r   _advancer   r!   r   s   ` @r    r   r   L   sO     	HA% % % % % % % 58A;;////r"   r   wfloatAphioffsetc                r     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   )cosr   r*   r   c                2     | z  z             z  z   S N )r   r+   r/   r-   r,   r)   s    r    r!   zcosine.<locals>.fr   #    33qsSy>>!F**r"   r#   r   r*   r   r*   )mathr/   r   r   r'   )r)   r+   r,   r-   r!   r/   s   ```` @r    r   r   c   f     + + + + + + + + + +58A;;////r"   c                 J    t          t          t          d                     S )z@ Return a driver function that can advance a simple count.

    c                    | S r1   r2   )xs    r    <lambda>zcount.<locals>.<lambda>z   s    a r"   r#   r   r   r'   r2   r"   r    r   r   v   s!     58KK#8#89999r"   r!   Callable[[Any], None]Iterator[Any]Callable[[], None]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

    r   Nonec                 8      t                               d S r1   )next)r!   r   s   r    wrapperzforce.<locals>.wrapper   s    	$x..r"   )r   r@   r2   )r!   r   rC   s   `` r    r   r   |   s,          Nr"   mbc                Z     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
        x (float) : an offset for the linear driver

    r   r*   r   c                    | z  z   S r1   r2   )r   rE   rD   s    r    r!   zlinear.<locals>.f   s    1uqyr"   r#   r4   r;   )rD   rE   r!   s   `` r    r   r      s@          58A;;////r"   c                x     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

    r   r   r   c                    | z           S r1   r2   )r   r   r   s    r    r!   zrepeat.<locals>.f   s    !}r"   r#   r$   r%   r(   s   ` @r    r   r      sM     	HA      58A;;////r"   c                r     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   )sinr   r*   r   c                2     | z  z             z  z   S r1   r2   )r   r+   r-   r,   rK   r)   s    r    r!   zsine.<locals>.f   r3   r"   r#   r4   )r5   rK   r   r   r'   )r)   r+   r,   r-   r!   rK   s   ```` @r    r   r      r6   r"   TCallable[[int], T]Iterable[T]c              #  2   K   d}	  | |          V  |dz  })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   Tr   r2   )r!   r   s     r    r'   r'      s1       	
Aadd


	Qr"   )r   r   r   r   )r   r   r   )
r)   r*   r+   r*   r,   r*   r-   r*   r   r   )r   r   )r!   r<   r   r=   r   r>   )r   r   )rD   r*   rE   r*   r   r   )r!   rN   r   rO   )__doc__
__future__r   logging	getLogger__name__log	functoolsr   typingr   r   r   r   r	   r
   __all__r   r   r   r   r   r   r   rM   r'   r2   r"   r    <module>rZ      sr   @ # " " " " " g!!                     0 0 0 0.0 0 0 0 0&: : : :    0 0 0 0 0 0 0 0 0$0 0 0 0 06 GCLL     r"   