a
    =Df                     @  s   d Z ddlmZ ddlZe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d	d
dZd'ddddddddZddddZddddddZd(ddddddZddd	ddZd)dddddddd Zed!Zd"d#d$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sinezSequence[int]zpartial[Callable[[], None]])sequencereturnc                   s.   t  ddd fdd}ttt|d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

    intir   c                   s6   t |  \}}|d dkr"| S  | d  S d S )N   r      )divmod)r   divmodNr    Z/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/bokeh/driving.pyf[   s    zbounce.<locals>.fr   lenr   r   _advancer   r   r   r   r   r
   L   s    r
   r   float)wAphioffsetr   c                   s8   ddl m ddd fdd}ttt|d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   c                   s    |     S Nr   r   r'   r*   r)   r(   r&   r   r   r   r   s    zcosine.<locals>.fr    )mathr*   r   r   r#   r&   r'   r(   r)   r   r   r-   r   r   c   s    r   r   c                   C  s   t ttdd dS )z@ Return a driver function that can advance a simple count.

    c                 S  s   | S r+   r   )xr   r   r   <lambda>z       zcount.<locals>.<lambda>r    r   r   r#   r   r   r   r   r   v   s    r   zCallable[[Any], None]zIterator[Any]zCallable[[], None])r   r   r   c                   s   dd fd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

    Noner0   c                     s    t  d S r+   )nextr   r   r   r   r   wrapper   s    zforce.<locals>.wrapperr   )r   r   r8   r   r7   r   r   |   s    r   )mbr   c                   s&   ddd fdd}t tt|d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   c                   s   |    S r+   r   r,   r:   r9   r   r   r      s    zlinear.<locals>.fr    r4   )r9   r:   r   r   r;   r   r      s    r   c                   s.   t  ddd fdd}ttt|d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   c                   s   |    S r+   r   r,   r   r   r   r      s    zrepeat.<locals>.fr    r!   r$   r   r   r   r      s    r   c                   s8   ddl m ddd fdd}ttt|d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   c                   s    |     S r+   r   r,   r'   r)   r(   r<   r&   r   r   r      s    zsine.<locals>.fr    )r.   r<   r   r   r#   r/   r   r=   r   r      s    r   TzCallable[[int], T]zIterable[T])r   r   c                 c  s   d}| |V  |d7 }qdS )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   Nr   )r   r   r   r   r   r#      s    
r#   )r   r   r   )r   r   )r   r   r   )__doc__
__future__r   logging	getLogger__name__log	functoolsr   typingr   r   r   r   r   r	   __all__r
   r   r   r   r   r   r   r>   r#   r   r   r   r   <module>   s    
 