U
    /e "                     @  sj  d Z ddlmZ ddlZeeZddlZddlZddl	Z	ddl
mZ ddlmZ ddlZddlmZ ddlmZ d	d
lmZ ddlmZ ddlmZ ddlmZmZ ddlmZmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z&m'Z' ddl(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Z0G dd  d e Z1G d!d" d"e"Z2dS )#z5 Provide properties for various visual attrributes.

    )annotationsN)BytesIO)Path   )
deprecated)convert_datetime_type   )enums   )Auto)Property)SeqTuple)Datetime	TimeDelta)Either)Enum)Nullable)FloatInt)String)Regex)DashPatternFontSizeHatchPatternTypeImageMinMaxBounds
MarkerTypec                      sl   e Zd ZdZg dgddgddddgddddgdZg dfdd fd	d
ZddddZ fddZ  ZS )r   a   Accept line dash specifications.

    Express patterns that describe line dashes.  ``DashPattern`` values
    can be specified in a variety of ways:

    * An enum: "solid", "dashed", "dotted", "dotdash", "dashdot"
    * a tuple or list of integers in the `HTML5 Canvas dash specification style`_.
      Note that if the list of integers has an odd number of elements, then
      it is duplicated, and that duplicated list becomes the new dash list.

    To indicate that dashing is turned off (solid lines), specify the empty
    list [].

    .. _HTML5 Canvas dash specification style: http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#dash-list

       r      )ZsolidZdashedZdottedZdotdashZdashdotNNonereturnc                   s0   t tjtdttf}t j|||d d S )Nz^(\d+(\s+\d+)*)?$defaulthelp)r   r	   r   r   r   r   super__init__selfr$   r%   types	__class__ >/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/core/property/visual.pyr'   [   s    zDashPattern.__init__strc                 C  s   | j jS Nr,   __name__r)   r-   r-   r.   __str___   s    zDashPattern.__str__c                   sT   t  |}t|trLz| j| W S  tk
rH   dd | D  Y S X n|S d S )Nc                 S  s   g | ]}t |qS r-   )int).0xr-   r-   r.   
<listcomp>i   s     z)DashPattern.transform.<locals>.<listcomp>)r&   	transform
isinstancer/   _dash_patternsKeyErrorsplit)r)   valuer+   r-   r.   r9   b   s    
zDashPattern.transform)	r2   
__module____qualname____doc__r;   r'   r4   r9   __classcell__r-   r-   r+   r.   r   A   s   

r   c                      s,   e Zd ZedejZd fdd	Z  ZS )r   zO^[0-9]+(.[0-9]+)?(%|em|ex|ch|ic|rem|vw|vh|vi|vb|vmin|vmax|cm|mm|q|in|pc|pt|px)$Tc                   sd   t  || t|tr`t|dkr:|s,dnd}t|n&| j|s`|sNdn|d}t|d S )Nr    z+empty string is not a valid font size valuez is not a valid font size value)r&   validater:   r/   len
ValueError_font_size_rematchr)   r>   detailmsgr+   r-   r.   rD   q   s    

zFontSize.validate)T)	r2   r?   r@   recompileIrG   rD   rB   r-   r-   r+   r.   r   m   s   r   c                      s:   e Zd ZdZg dfdd fddZdddd	Z  ZS )
r   z Accept built-in fill hatching specifications.

    Accepts either "long" names, e.g. "horizontal-wave" or the single letter
    abbreviations, e.g. "v"

    Nr    r!   c                   s,   t tjt tjf}t j|||d d S Nr#   )r   r	   ZHatchPatternZHatchPatternAbbreviationr&   r'   r(   r+   r-   r.   r'      s    zHatchPatternType.__init__r/   c                 C  s   | j jS r0   r1   r3   r-   r-   r.   r4      s    zHatchPatternType.__str__)r2   r?   r@   rA   r'   r4   rB   r-   r-   r+   r.   r   |   s   r   c                   @  s"   e Zd ZdZdddZdd ZdS )	r   a   Accept image file types, e.g PNG, JPEG, TIFF, etc.

    This property can be configured with:

    * A ``pathlib.Path`` image file path
    * A data URL encoded image string
    * A string filename to be loaded with ``PIL.Image.open``
    * An RGB(A) NumPy array, will be converted to PNG
    * A ``PIL.Image.Image`` object

    In all cases, the image data is serialized as a Base64 encoded string.

    Tc                 C  sv   dd l }t|tttjjfr d S t||jrV|jdkrVt|j	dkrV|j	d dkrVd S |s^dn
d|d}t
|d S )	Nr   Zuint8r   r   )r   r   rC   zinvalid value: zX; allowed values are string filenames, PIL.Image.Image instances, or RGB(A) NumPy arrays)numpyr:   r/   r   PILr   ndarrayZdtyperE   shaperF   )r)   r>   rJ   nprK   r-   r-   r.   rD      s    &zImage.validatec                 C  s   dd l }t||jr tj|}t|tr8|dr8|S t|trVtddd t	|}t|t	rltj
|}t|tjjrt }|jpd}||| t| d}d|  d| S td	|d S )
Nr   zdata:image/)r   r   r   zraw string pathzpathlib.PathZPNGasciiz;base64,zCould not transform )rP   r:   rR   rQ   r   Z	fromarrayr/   
startswithr   r   openr   formatsavebase64	b64encodegetvaluedecodelowerrF   )r)   r>   rT   outfmtencodedr-   r-   r.   r9      s"    


zImage.transformN)T)r2   r?   r@   rA   rD   r9   r-   r-   r-   r.   r      s   
r   c                      s6   e Zd ZdZddd fddZd fd
d	Z  ZS )r   a"   Accept (min, max) bounds tuples for use with Ranges.

    Bounds are provided as a tuple of ``(min, max)`` so regardless of whether your range is
    increasing or decreasing, the first item should be the minimum value of the range and the
    second item should be the maximum. Setting min > max will result in a ``ValueError``.

    Setting bounds to None will allow your plot to pan/zoom as far as you want. If you only
    want to constrain one end of the plot, you can set min or max to
    ``None`` e.g. ``DataRange1d(bounds=(None, 12))`` FautoNr    r!   c              
     s   t ttttttttttttttttttttttf}|rr|tttttttttttf }t j|||d d S rO   )r   r   r   r   r   r   r&   r'   )r)   Zaccept_datetimer$   r%   r*   r+   r-   r.   r'      s    zMinMaxBounds.__init__Tc                   s   t  || |d d ks&|d d kr*d S t|}t|d tjrRt|d |d< t|d tjrrt|d |d< |d |d k rd S |sdnd}t|d S )Nr   r
   rC   zNInvalid bounds: maximum smaller than minimum. Correct usage: bounds=(min, max))r&   rD   listr:   datetimer   rF   rI   r+   r-   r.   rD      s    zMinMaxBounds.validate)Frb   N)T)r2   r?   r@   rA   r'   rD   rB   r-   r-   r+   r.   r      s   
r   c                      s&   e Zd ZdZdd fddZ  ZS )r   z

    r    r!   c                   s   t  jtjf| d S r0   )r&   r'   r	   r   )r)   kwr+   r-   r.   r'      s    zMarkerType.__init__)r2   r?   r@   rA   r'   rB   r-   r-   r+   r.   r      s   r   )3rA   
__future__r   logging	getLoggerr2   logrZ   rd   rL   ior   pathlibr   Z	PIL.ImagerQ   Zutil.deprecationr   Zutil.serializationr   rC   r	   rb   r   basesr   	containerr   r   r   r   Zeitherr   enumr   Znullabler   numericr   r   Z	primitiver   stringr   __all__r   r   r   r   r   r   r-   r-   r-   r.   <module>   s:   
,44