B
    @\                 @   s   d Z ddlmZmZmZmZ ddlZeeZ	ddl
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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 ...

    )absolute_importdivisionprint_functionunicode_literalsN)partial)bouncecosinecountforcelinearrepeatsinec                s&   t   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

    c                s6   t |  \}}|d dkr"| S  | d  S d S )N   r      )divmod)iZdivmod)Nsequence ,lib/python3.7/site-packages/bokeh/driving.pyfX   s    zbounce.<locals>.f)r   )lenr   r
   _advance)r   r   r   )r   r   r   r   I   s    r   r   c                s0   ddl m  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   )cosc                s    |     S )Nr   )r   )Ar   offsetphiwr   r   r   o   s    zcosine.<locals>.f)r   )mathr   r   r
   r   )r   r   r   r   r   r   )r   r   r   r   r   r   r   `   s    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 )Nr   )xr   r   r   <lambda>w   s    zcount.<locals>.<lambda>)r   )r   r
   r   r   r   r   r   r	   s   s    r	   c                s    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

    c                  s    t  d S )N)nextr   )r   r   r   r   wrapper   s    zforce.<locals>.wrapperr   )r   r   r#   r   )r   r   r   r
   y   s    r
   c                s    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

    c                s   |    S )Nr   )r   )bmr   r   r      s    zlinear.<locals>.f)r   )r   r
   r   )r%   r$   r   r   )r$   r%   r   r      s    r   c                s&   t   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

    c                s   |    S )Nr   )r   )r   r   r   r   r      s    zrepeat.<locals>.f)r   )r   r   r
   r   )r   r   r   )r   r   r   r      s    r   c                s0   ddl m  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   )sinc                s    |     S )Nr   )r   )r   r   r   r&   r   r   r   r      s    zsine.<locals>.f)r   )r   r&   r   r
   r   )r   r   r   r   r   r   )r   r   r   r&   r   r   r      s    r   c             c   s    d}x| |V  |d7 }qW 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__Z
__future__r   r   r   r   ZloggingZ	getLogger__name__log	functoolsr   __all__r   r   r	   r
   r   r   r   r   r   r   r   r   <module>"   s   



