U
    /e1                     @  s   d dl mZ d dlZeeZd dlZd dlmZ d dl	Z
ddlmZ ddlmZmZmZ ddlmZ ddlmZ d	d
lmZmZ edZdZddddddddgZd)ddZdd Zdd Zdi i fddZdd Zd d! Z d"d# Z!d$d% Z"d&d' Z#d(Z$dS )*    )annotationsN)Iterable   )	ColorSpec)ColumnarDataSourceColumnDataSourceGlyphRenderer)import_optional)	nice_join   )pop_legend_kwargupdate_legendZpandas)create_renderer
make_glyphpop_visualsnameZcoordinatesZx_range_nameZy_range_namelevelviewZvisibleZmutedc                 C  s\   ddddddddd	d
ddddddddg}| rP| j }dd |D }t|}|| S |d S d S )Nz#1f77b4z#ff7f0ez#ffbb78z#2ca02cz#98df8az#d62728z#ff9896z#9467bdz#c5b0d5z#8c564bz#c49c94z#e377c2z#f7b6d2z#7f7f7fz#bcbd22z#dbdb8dz#17becfz#9edae5c                 S  s   g | ]}|j d kr|qS )r   )Z__view_model__.0x r   </tmp/pip-unpacked-wheel-f5fndrjf/bokeh/plotting/_renderer.py
<listcomp>D   s     
 z%get_default_color.<locals>.<listcomp>r   )	rendererslen)plotcolorsr   Znum_renderersr   r   r   get_default_color5   s2            r   c                 K  sp  t |}t|}t|}|d }t| |}g }|t| |||7 }|t| |||7 }|rjttt|dd t| |d|ddid}	tdd	 |D rt| |d
|d}
nd }
tdd	 |D rt| |d|d}nd }t| |d|ddid}t	| ||}t	| ||	}t	| ||
}t	| ||}t	| ||}t
f ||p0d|p8d||pBdd|}|j| |rlt||| |S )Ndata_sourceand)Z
conjuctionZnonselection_alphag?)prefixdefaultsoverride_defaultsc                 s  s   | ]}| d V  qdS )
selection_N
startswithr   r   r   r   	<genexpr>f   s     z"create_renderer.<locals>.<genexpr>r%   )r"   r#   c                 s  s   | ]}| d V  qdS )hover_Nr&   r   r   r   r   r(   l   s     r)   Zmuted_g?auto)glyphnonselection_glyphselection_glyphhover_glyphmuted_glyph)_convert_data_sourcer   _pop_renderer_argsr   _process_sequence_literalsRuntimeError_GLYPH_SOURCE_MSGr
   anyr   r   r   appendr   )
glyphclassr   kwargsis_user_sourceZlegend_kwargZrenderer_kwssourceZglyph_visuals incompatible_literal_spec_valuesZnonselection_visualsZselection_visualsZhover_visualsZmuted_visualsr+   r,   r-   r.   r/   Zglyph_rendererr   r   r   r   O   sH    
r   c                 C  s(   |d krd S |  }|| | f |S )N)copyupdate)r7   kwsextrar   r   r   r      s
    
r    c                 C  s,  |  }|dd |dd i }|dt  |dd t t  }}t|  }tt|D ]}	t|	\}
}||	 |kr|	||	 ||	< nf||kr|| |kr|||  ||	< n@||kr|| ||	< n*|	|kr||	 ||	< n||kr|| ||	< ||krb|
| qb|D ]}|	|| d q|S )a  
    Applies basic cascading logic to deduce properties for a glyph.

    Args:
        glyphclass :
            the type of glyph being handled

        props (dict) :
            Maps properties and prefixed properties to their values.
            Keys in `props` matching `glyphclass` visual properties (those of
            'line_', 'fill_', 'hatch_' or 'text_') with added `prefix` will get
            popped, other keys will be ignored.
            Keys take the form '[{prefix}][{feature}_]{trait}'. Only {feature}
              must not contain underscores.
            Keys of the form '{prefix}{trait}' work as lower precedence aliases
              for {trait} for all {features}, as long as the glyph has no
              property called {trait}. I.e. this won't apply to "width" in a
              `rect` glyph.
            Ex: {'fill_color': 'blue', 'selection_line_width': 0.5}

        prefix (str) :
            Prefix used when accessing `props`. Ex: 'selection_'

        override_defaults (dict) :
            Explicitly provided fallback based on '{trait}', in case property
            not set in `props`.
            Ex. 'width' here may be used for 'selection_line_width'.

        defaults (dict) :
            Property fallback, in case prefixed property not in `props` or
            `override_defaults`.
            Ex. 'line_width' here may be used for 'selection_line_width'.

    Returns:
        result (dict) :
            Resulting properties for the instance (no prefixes).

    Notes:
        Feature trait 'text_color', as well as traits 'color' and 'alpha', have
        ultimate defaults in case those can't be deduced.
    Z
text_colorZblackZhatch_colorcolorr!   g      ?N)r<   
setdefaultr   dictsetZ
propertiesfilter
_is_visual_split_feature_traitpopadd)r7   propsr"   r#   r$   Ztrait_defaultsresultZtraitsZ
prop_namesr   _traitr   r   r   r      s2    +r   c              
   C  s   |  dd d k	}|r| d }t|tszt|}W nL tk
r~ } z.dt| d| }t|t d W 5 d }~X Y nX || d< |S )Nr:   zFailed to auto-convert z' to ColumnDataSource.
 Original error: r   )	get
isinstancer   r   
ValueErrortypewith_tracebacksysexc_info)r8   r9   r:   errmsgr   r   r   r0      s    
(r0   c                   s(    fddt D } dt |d< |S )Nc                   s    i | ]}| kr|  |qS r   )rH   )r   attrr8   r   r   
<dictcomp>   s    z&_pop_renderer_args.<locals>.<dictcomp>r:   r   )RENDERER_ARGSrH   r   )r8   rK   r   rX   r   r1      s
    
r1   c                 C  st  g }|   }| D ]X\}}t|ts*qt|tr6q||kr@qt|trLqt|| trj|| |rjqt|tj	rFt|| tr*|j
dkr|jdkrn|j
dkr|jdkrnt|j
jdkr|jdkrn\|j
dks|j
jdkr|jdkr|jd dkrn,td| d	|j
 d
dtt|j dn|jdkrFtd| d|rX|| q|j||d |||< q|S )NZuint32r   Zuint8Ufr   )      zPColor columns need to be of type uint32[N], uint8[N] or uint8/float[N, {3, 4}] (z is [z, ]zColumns need to be 1D (z is not))r   )	dataspecsitemsrO   r   rC   strr   Zis_color_tuple_shapenpZndarrayZdtypendimkindshaper3   joinmapr6   rI   )r7   r8   r:   r9   r;   ra   varvalr   r   r   r2     s>    


..
r2   c                 C  s&   |  dd} t| dkr| S | dg S )zAFeature is up to first '_'. Ex. 'line_color' => ['line', 'color']rL   r   r   N)splitr   )ftr   r   r   rG   3  s    rG   c                 C  s   t | \}}|dko|dk	S )z&Whether a feature trait name is visual)linefillZhatchtextglobalN)rG   )rm   ZfeaturerM   r   r   r   rF   8  s    rF   aH  

Expected %s to reference fields in the supplied data source.

When a 'source' argument is passed to a glyph method, values that are sequences
(like lists or arrays) must come from references to data columns in the source.

For instance, as an example:

    source = ColumnDataSource(data=dict(x=a_list, y=an_array))

    p.circle(x='x', y='y', source=source, ...) # pass column names and a source

Alternatively, *all* data sequences may be provided as literals as long as a
source is *not* provided:

    p.circle(x=a_list, y=an_array, ...)  # pass actual sequences and no source

)N)%
__future__r   logging	getLogger__name__logrS   collections.abcr   Znumpyrd   Zcore.propertiesr   modelsr   r   r   Zutil.dependenciesr	   Zutil.stringr
   Z_legendsr   r   pd__all__rZ   r   r   r   r   r0   r1   r2   rG   rF   r4   r   r   r   r   <module>   s8   
   
=W1