U
    /eV$                     @  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
 ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd	lmZ dd
lm Z  ddl!m"Z" dZ#eG dd de"Z$eG dd de$Z%eG dd de$Z&G dd de&e%Z'G dd de&Z(G dd de&Z)eG dd de%Z*G dd de*Z+G dd de*Z,eG d d! d!e*Z-G d"d# d#e-Z.dS )$z Models for mapping values from one range or space to another in the client.

Mappers (as opposed to scales) are not presumed to be invertible.

    )annotationsN   )palettes)Palette)abstract)BoolColorEitherEnum	FactorSeqFloatHatchPatternTypeInstanceIntList
MarkerTypeNullableSeqStringTuple)warning)PALETTE_LENGTH_FACTORS_MISMATCH   )	Transform)
MapperColorMapperCategoricalMapperCategoricalColorMapperCategoricalMarkerMapperCategoricalPatternMapperContinuousColorMapperLinearColorMapperLogColorMapperEqHistColorMapperc                   @  s   e Zd ZdZdS )r   z Base class for mappers.

    N__name__
__module____qualname____doc__ r)   r)   8/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/models/mappers.pyr   G   s   r   c                      sP   e Zd ZdZeeddeedd Z	edddZ
dd
d fddZ  ZS )r   z) Base class for color mapper types.

    z
    A sequence of colors to use as the target palette for mapping.

    This property can also be set as a ``String``, to the name of any of the
    palettes shown in :ref:`bokeh.palettes`.
    helpc                 C  s
   t t| S )N)getattrr   )Zpalr)   r)   r*   <lambda>Y       zColorMapper.<lambda>ZgrayzD
    Color to be used if data is NaN or otherwise not mappable.
    defaultr,   NNone)returnc                   s"   |d k	r||d< t  jf | d S )Npalette)super__init__)selfr4   kwargs	__class__r)   r*   r6   _   s    zColorMapper.__init__)N)r%   r&   r'   r(   r   r   Zacceptsr
   r   r4   	nan_colorr6   __classcell__r)   r)   r9   r*   r   N   s    r   c                   @  s2   e Zd ZdZeddZedddZeeddZ	dS )	r   zK Base class for mappers that map categorical factors to other values.

    a=  
    A sequence of factors / categories that map to the some target range. For
    example the following color mapper:

    .. code-block:: python

        mapper = CategoricalColorMapper(palette=["red", "blue"], factors=["foo", "bar"])

    will map the factor ``"foo"`` to red and the factor ``"bar"`` to blue.
    r+   r   aw  
    A start index to "slice" data factors with before mapping.

    For example, if the data to color map consists of 2-level factors such
    as ``["2016", "sales"]`` and ``["2016", "marketing"]``, then setting
    ``start=1`` will perform color mapping only based on the second sub-factor
    (i.e. in this case based on the department ``"sales"`` or ``"marketing"``)
    r0   a  
    A start index to "slice" data factors with before mapping.

    For example, if the data to color map consists of 2-level factors such
    as ``["2016", "sales"]`` and ``["2017", "marketing"]``, then setting
    ``end=1`` will perform color mapping only based on the first sub-factor
    (i.e. in this case based on the year ``"2016"`` or ``"2017"``)

    If ``None`` then all sub-factors from ``start`` to the end of the
    factor will be used for color mapping.
    N)
r%   r&   r'   r(   r   factorsr   startr   endr)   r)   r)   r*   r   d   s   
	r   c                   @  s    e Zd ZdZeedd ZdS )r   z Map categorical factors to colors.

    Values that are passed to this mapper that are not in the factors list
    will be mapped to ``nan_color``.

    c                 C  s@   | j }| j}t|t|k r<|t|d  }| d| j S d S )Nz! will be assigned to `nan_color` )r4   r=   lenr;   )r7   r4   r=   Zextra_factorsr)   r)   r*   _check_palette_length   s
    z,CategoricalColorMapper._check_palette_lengthN)r%   r&   r'   r(   r   r   rA   r)   r)   r)   r*   r      s   r   c                   @  s(   e Zd ZdZeeddZedddZdS )r   a1   Map categorical factors to marker types.

    Values that are passed to this mapper that are not in the factors list
    will be mapped to ``default_value``.

    .. note::
        This mappers is primarily only useful with the ``Scatter`` marker
        glyph that be parameterized by marker type.

    F
    A sequence of marker types to use as the target for mapping.
    r+   Zcirclez\
    A marker type to use in case an unrecognized factor is passed in to be
    mapped.
    r0   N)r%   r&   r'   r(   r   r   markersdefault_valuer)   r)   r)   r*   r      s   r   c                   @  s(   e Zd ZdZeeddZedddZdS )r   z Map categorical factors to hatch fill patterns.

    Values that are passed to this mapper that are not in the factors list
    will be mapped to ``default_value``.

    Added in version 1.1.1

    rB   r+    z^
    A hatch pattern to use in case an unrecognized factor is passed in to be
    mapped.
    r0   N)r%   r&   r'   r(   r   r   patternsrD   r)   r)   r)   r*   r      s   	r   c                   @  sb   e Zd ZdZeeedeeeeg ddZ	e
eddZe
eddZe
eddZe
ed	dZd
S )r    z4 Base class for continuous color mapper types.

    z$bokeh.models.renderers.GlyphRendererz
    A collection of glyph renderers to pool data from for establishing data metrics.
    If empty, mapped data will be used instead.
    r0   z
    The minimum value of the range to map into the palette. Values below
    this are clamped to ``low``. If ``None``, the value is inferred from data.
    r+   z
    The maximum value of the range to map into the palette. Values above
    this are clamped to ``high``. If ``None``, the value is inferred from data.
    z
    Color to be used if data is lower than ``low`` value. If None,
    values lower than ``low`` are mapped to the first color in the palette.
    z
    Color to be used if data is higher than ``high`` value. If None,
    values higher than ``high`` are mapped to the last color in the palette.
    N)r%   r&   r'   r(   r   r   r   r	   r   domainr   r   lowhighr   Z	low_colorZ
high_colorr)   r)   r)   r*   r       s   "r    c                   @  s   e Zd ZdZdS )r!   a   Map numbers in a range [*low*, *high*] linearly into a sequence of
    colors (a palette).

    For example, if the range is [0, 99] and the palette is
    ``['red', 'green', 'blue']``, the values would be mapped as follows::

             x < 0  : 'red'     # values < low are clamped
        0 <= x < 33 : 'red'
       33 <= x < 66 : 'green'
       66 <= x < 99 : 'blue'
       99 <= x      : 'blue'    # values > high are clamped

    Nr$   r)   r)   r)   r*   r!      s   r!   c                   @  s   e Zd ZdZdS )r"   a   Map numbers in a range [*low*, *high*] into a sequence of colors
    (a palette) on a natural logarithm scale.

    For example, if the range is [0, 25] and the palette is
    ``['red', 'green', 'blue']``, the values would be mapped as follows::

                x < 0     : 'red'     # values < low are clamped
       0     <= x < 2.72  : 'red'     # math.e ** 1
       2.72  <= x < 7.39  : 'green'   # math.e ** 2
       7.39  <= x < 20.09 : 'blue'    # math.e ** 3
       20.09 <= x         : 'blue'    # values > high are clamped

    .. warning::
        The ``LogColorMapper`` only works for images with scalar values that are
        non-negative.

    Nr$   r)   r)   r)   r*   r"      s   r"   c                   @  s   e Zd ZdS )ScanningColorMapperN)r%   r&   r'   r)   r)   r)   r*   rJ     s   rJ   c                   @  s$   e Zd ZedddZedddZdS )r#   i   zNumber of histogram binsr0   Fz
    If there are only a few discrete levels in the values that are color
    mapped then ``rescale_discrete_levels=True`` decreases the lower limit of
    the span so that the values are rendered towards the top end of the
    palette.
    N)r%   r&   r'   r   Zbinsr   Zrescale_discrete_levelsr)   r)   r)   r*   r#     s   r#   )/r(   
__future__r   logging	getLoggerr%   log r   Z
core.enumsr   Zcore.has_propsr   Zcore.propertiesr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   Zcore.validationr   Zcore.validation.warningsr   Z
transformsr   __all__r   r   r   r   r   r   r    r!   r"   rJ   r#   r)   r)   r)   r*   <module>   s6   	
D&