a
    na1                     @  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g d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levelZviewZvisibleZmutedc                 C  s<   g d}| r0| j }dd |D }t|}|| S |d S d S )N)z#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   7lib/python3.9/site-packages/bokeh/plotting/_renderer.py
<listcomp>D       z%get_default_color.<locals>.<listcomp>r   )	rendererslen)plotZcolorsr   Znum_renderersr   r   r   get_default_color5   s    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   r   z"create_renderer.<locals>.<genexpr>r$   )r!   r"   c                 s  s   | ]}| d V  qdS )hover_Nr%   r   r   r   r   r'   l   r   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 u rd S |  }|| | f i |S )N)copyupdate)r6   ZkwsZ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|	\}
}||	 |v r|	||	 ||	< nf||vr|| |v r|||  ||	< n@||v r|| ||	< n*|	|v r||	 ||	< n||v r|| ||	< ||v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_colorZcolorr    g      ?N)r;   
setdefaultr   dictsetZ
propertiesfilter
_is_visual_split_feature_traitpopadd)r6   Zpropsr!   r"   r#   Ztrait_defaultsresultZtraitsZ
prop_namesr   _traitr   r   r   r      s2    +r   c              
   C  s   |  dd d u}|r| d }t|tszt|}W nN ty } z6dt| d| }t|t d W Y d }~n
d }~0 0 || d< |S )Nr9   zFailed to auto-convert z' to ColumnDataSource.
 Original error: r   )	get
isinstancer   r   
ValueErrortypewith_tracebacksysexc_info)r7   r8   r9   errmsgr   r   r   r/      s    
,r/   c                   s(    fddt D } dt |d< |S )Nc                   s    i | ]}| v r|  |qS r   )rD   )r   attrr7   r   r   
<dictcomp>   s   z&_pop_renderer_args.<locals>.<dictcomp>r9   r   )RENDERER_ARGSrD   r   )r7   rF   r   rS   r   r0      s
    
r0   c                 C  st  g }|   }| D ]X\}}t|ts*qt|tr6q||v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v 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itemsrJ   r   r?   strr   Zis_color_tuple_shapenpZndarrayZdtypendimkindshaper2   joinmapr5   rE   )r6   r7   r9   r8   r:   r\   varvalr   r   r   r1     sJ    


.
r1   c                 C  s&   |  dd} t| dkr| S | dg S )zAFeature is up to first '_'. Ex. 'line_color' => ['line', 'color']rG   r   r   N)splitr   )ftr   r   r   rC   3  s    rC   c                 C  s   t | \}}|dv o|duS )z&Whether a feature trait name is visual)lineZfillZhatchtextglobalN)rC   )rh   ZfeaturerH   r   r   r   rB   8  s    rB   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)%Z
__future__r   ZloggingZ	getLogger__name__logrN   collections.abcr   Znumpyr_   Zcore.propertiesr   Zmodelsr   r   r   Zutil.dependenciesr	   Zutil.stringr
   Z_legendsr   r   Zpd__all__rU   r   r   r   r   r/   r0   r1   rC   rB   r3   r   r   r   r   <module>   s.   

=W1