U
    /e!                     @  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 ddlmZ dZG d	d
 d
eZG dd deZG dd deZG dd deZG dd de
ZG dd de
ZG dd de
ZdS )z" Provide the numeric properties.

    )annotationsN   )ParameterizedProperty)FloatInt)	Undefined)AngleByteIntervalNonNegativeIntPercentPositiveIntSizec                      s"   e Zd ZdZd fdd	Z  ZS )r   z Accept non-negative integers. Tc                   s(   t  || |dk r$td|d S )Nr   z#expected non-negative integer, got supervalidate
ValueErrorselfvaluedetail	__class__ ?/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/core/property/numeric.pyr   1   s    zNonNegativeInt.validate)T__name__
__module____qualname____doc__r   __classcell__r   r   r   r   r   .   s   r   c                      s"   e Zd ZdZd fdd	Z  ZS )r   z Accept positive integers. Tc                   s(   t  || |dkr$td|d S )Nr   zexpected positive integer, got r   r   r   r   r   r   :   s    zPositiveInt.validate)Tr   r   r   r   r   r   7   s   r   c                      sT   e Zd ZdZedfdd fddZdddd	Zed
d Zd fdd	Z	  Z
S )r
   a   Accept numeric values that are contained within a given interval.

    Args:
        interval_type (numeric property):
            numeric types for the range, e.g. ``Int``, ``Float``

        start (number) :
            A minimum allowable value for the range. Values less than
            ``start`` will result in validation errors.

        end (number) :
            A maximum allowable value for the range. Values greater than
            ``end`` will result in validation errors.

    Example:

        .. code-block:: python

            >>> class RangeModel(HasProps):
            ...     prop = Range(Float, 10, 20)
            ...

            >>> m = RangeModel()

            >>> m.prop = 10

            >>> m.prop = 20

            >>> m.prop = 15

            >>> m.prop = 2     # ValueError !!

            >>> m.prop = 22    # ValueError !!

            >>> m.prop = "foo" # ValueError !!

    NNonereturnc                   sD   |  || _| j| | j| || _|| _t j||d d S )Ndefaulthelp)Z_validate_type_paraminterval_typer   startendr   __init__)r   r'   r(   r)   r%   r&   r   r   r   r*   g   s    zInterval.__init__strc                 C  s*   | j j}| d| j d| jd| jdS )N(, ))r   r   r'   r(   r)   )r   
class_namer   r   r   __str__p   s    zInterval.__str__c                 C  s   | j gS )N)r'   )r   r   r   r   type_paramst   s    zInterval.type_paramsTc                   sd   t  || | j|r.|| jkr.|| jks`|s6dn d| j d| j d| j d|}t|d S )N zexpected a value of type z in range [r-   z], got )r   r   r'   Zis_validr(   r)   r   r   r   r   msgr   r   r   r   x   s     *zInterval.validate)T)r   r   r   r   r   r*   r0   propertyr1   r   r    r   r   r   r   r
   A   s   %	
r
   c                      s(   e Zd ZdZddd fddZ  ZS )	r	   a]   Accept integral byte values (0-255).

    Example:

        .. code-block:: python

            >>> class ByteModel(HasProps):
            ...     prop = Byte(default=0)
            ...

            >>> m = ByteModel()

            >>> m.prop = 255

            >>> m.prop = 256  # ValueError !!

            >>> m.prop = 10.3 # ValueError !!

    r   Nr!   r"   c                   s   t  jtdd||d d S )Nr      r$   )r   r*   r   )r   r%   r&   r   r   r   r*      s    zByte.__init__)r   N)r   r   r   r   r*   r    r   r   r   r   r	      s   r	   c                      s"   e Zd ZdZd fdd	Z  ZS )r   a   Accept non-negative numeric values.

    Args:
        default (float, optional) :
            A default value for attributes created from this property to have.

        help (str or None, optional) :
            A documentation string for this property. It will be automatically
            used by the :ref:`bokeh.sphinxext.bokeh_prop` extension when
            generating Spinx documentation. (default: None)

        serialized (bool, optional) :
            Whether attributes created from this property should be included
            in serialization (default: True)

        readonly (bool, optional) :
            Whether attributes created from this property are read-only.
            (default: False)

    Example:

        .. code-block:: python

            >>> class SizeModel(HasProps):
            ...     prop = Size()
            ...

            >>> m = SizeModel()

            >>> m.prop = 0

            >>> m.prop = 10e6

            >>> m.prop = -10   # ValueError !!

            >>> m.prop = "foo" # ValueError !!

    Tc                   s4   t  || |dk r0|sdnd|}t|d S )Nr   r2   z$expected a non-negative number, got r   r3   r   r   r   r      s    zSize.validate)Tr   r   r   r   r   r      s   &r   c                      s"   e Zd ZdZd fdd	Z  ZS )r   a   Accept floating point percentage values.

    ``Percent`` can be useful and semantically meaningful for specifying
    things like alpha values and extents.

    Args:
        default (float, optional) :
            A default value for attributes created from this property to have.

        help (str or None, optional) :
            A documentation string for this property. It will be automatically
            used by the :ref:`bokeh.sphinxext.bokeh_prop` extension when
            generating Spinx documentation. (default: None)

        serialized (bool, optional) :
            Whether attributes created from this property should be included
            in serialization (default: True)

        readonly (bool, optional) :
            Whether attributes created from this property are read-only.
            (default: False)

    Example:

        .. code-block:: python

            >>> class PercentModel(HasProps):
            ...     prop = Percent()
            ...

            >>> m = PercentModel()

            >>> m.prop = 0.0

            >>> m.prop = 0.2

            >>> m.prop = 1.0

            >>> m.prop = -2  # ValueError !!

            >>> m.prop = 5   # ValueError !!

    Tc                   sH   t  || d|  kr"dkr*n nd S |s2dnd|}t|d S )Ng        g      ?r2   z&expected a value in range [0, 1], got r   r3   r   r   r   r      s
    zPercent.validate)Tr   r   r   r   r   r      s   +r   c                   @  s   e Zd ZdZdS )r   a]   Accept floating point angle values.

    ``Angle`` is equivalent to :class:`~bokeh.core.properties.Float` but is
    provided for cases when it is more semantically meaningful.

    Args:
        default (float, optional) :
            A default value for attributes created from this property to have.

        help (str or None, optional) :
            A documentation string for this property. It will be automatically
            used by the :ref:`bokeh.sphinxext.bokeh_prop` extension when
            generating Spinx documentation. (default: None)

        serialized (bool, optional) :
            Whether attributes created from this property should be included
            in serialization (default: True)

        readonly (bool, optional) :
            Whether attributes created from this property are read-only.
            (default: False)

    N)r   r   r   r   r   r   r   r   r      s   r   )r   
__future__r   logging	getLoggerr   logbasesr   Z	primitiver   r   Z
singletonsr   __all__r   r   r
   r	   r   r   r   r   r   r   r   <module>   s   
	
>.5