U
    /e"                     @  s   U d Z ddlmZ ddlZeeZddlmZm	Z	m
Z
mZmZ ddlZddlmZ ddlmZmZ ertddlmZ i Zd	ed
< dZG dd dZdS )z\ Provide a ``Theme`` class for specifying new default values for Bokeh
|Model| properties.

    )annotationsN)TYPE_CHECKINGAnyDictTypeoverload   )HasProps)PathLikeUnknown)ModelDict[str, Unknown]_empty_dict)Themec                   @  s   e Zd ZU dZded< ded< ded< ded< ded	< ed
ddddZedddddZd"ddddddZddddddZdddddZdddd d!Z	dS )#r   a   Provide new default values for Bokeh models.

    Bokeh Model properties all have some built-in default value. If a property
    has not been explicitly set (e.g. ``m.foo = 10``), accessing the
    property will return the default value. It may be useful for users to be
    able to specify a different set of default values than the built-in
    default. The ``Theme`` class allows collections of custom default values
    to be easily applied to Bokeh documents.

    The ``Theme`` class can be constructed either from a YAML file or from a
    JSON dict (but not both). Examples of both formats are shown below.

    The plotting API's defaults override some theme properties. Namely:
    `fill_alpha`, `fill_color`, `line_alpha`, `line_color`, `text_alpha` and
    `text_color`. Those properties should therefore be set explicitly when
    using the plotting API.

    Args:
        filename (str, optional) : path to a YAML theme file
        json (str, optional) : a JSON dictionary specifying theme values

    Raises:
        ValueError
            If neither ``filename`` or ``json`` is supplied.

    Examples:

        Themes are specified by providing a top-level key ``attrs`` which
        has blocks for Model types to be themed. Each block has keys and
        values that specify the new property defaults for that type.

        Take note of the fact that YAML interprets the value `None` as
        a string, which is not usually what you want. To give `None` as a
        value in YAML, use `!!null`. To give 'None' as a value in json,
        use `null`.

       Here is an example theme in YAML format that sets various visual
       properties for all figures, grids, and titles:

        .. code-block:: yaml

            attrs:
                Figure:
                    background_fill_color: '#2F2F2F'
                    border_fill_color: '#2F2F2F'
                    outline_line_color: '#444444'
                Axis:
                    axis_line_color: !!null
                Grid:
                    grid_line_dash: [6, 4]
                    grid_line_alpha: .3
                Title:
                    text_color: "white"

        Here is the same theme, in JSON format:

        .. code-block:: python

            {
            'attrs' : {
                'Figure' : {
                    'background_fill_color': '#2F2F2F',
                    'border_fill_color': '#2F2F2F',
                    'outline_line_color': '#444444',
                },
                'Axis': {
                    'axis_line_color': null,
                },
                'Grid': {
                    'grid_line_dash': [6, 4]',
                    'grid_line_alpha': .3,
                },
                'Title': {
                    'text_color': 'white'
                }
            }

    zDict[str, Dict[str, Unknown]]_by_class_cacher   _line_defaults_fill_defaults_text_defaultszDict[str, Any]_jsonr
   None)filenamereturnc                 C  s   d S N )selfr   r   r   6/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/themes/theme.py__init__   s    zTheme.__init__)jsonr   c                 C  s   d S r   r   )r   r   r   r   r   r      s    NzPathLike | NonezDict[str, Any] | None)r   r   r   c              	   C  s  |d k	r|d k	rt d|d k	rJt|}t|}|d kr@i }W 5 Q R X |d krZt d|| _d| jkrti | jd< t| jd tst d| jd | jd  D ]&\}}t|tst d| d|q| jdt	| _
| jdt	| _| jd	t	| _i | _d S )
Nz=Theme should be constructed from a file or from json not bothz.Theme requires json or a filename to constructattrszFtheme problem: attrs field should be a dictionary of class names, not ztheme problem: attrs.z+ should be a dictionary of properties, not Zline_defaultsZfill_defaultsZtext_defaults)
ValueErroropenyamlZ	safe_loadr   
isinstancedictitemsgetr   r   r   r   r   )r   r   r   fkeyvaluer   r   r   r      s*    




zType[HasProps])clspropsr   c                 C  s\   ddl m} t||rXt|dr,|| j t|drB|| j t|drX|| j d S )Nr   )GlyphZ
line_alphaZ
fill_alphaZ
text_alpha)Zmodels.glyphsr+   
issubclasshasattrupdater   r   r   )r   r)   r*   r+   r   r   r   _add_glyph_defaults   s    



zTheme._add_glyph_defaultszType[Model])r)   r   c                 C  s   |j | jkrx| jd }i }|jdd d D ]0}t|ts:q*| || |||j t	 q*t
|dkrlt	}|| j|j < | j|j  S )Nr   r   )__name__r   r   __mro__r,   r	   r/   r.   r%   r   len)r   r)   r   Zcombinedbaser   r   r   
_for_class   s    

zTheme._for_classr   )modelr   c                 C  s*   | | |j ttdkr&tddS )z Apply this theme to a model.

        .. warning::
            Typically, don't call this method directly. Instead, set the theme
            on the |Document| the model is a part of.

        r   z!Somebody put stuff in _empty_dictN)Zapply_themer6   	__class__r4   r   RuntimeError)r   r7   r   r   r   apply_to_model   s    zTheme.apply_to_model)NN)
r2   
__module____qualname____doc____annotations__r   r   r/   r6   r:   r   r   r   r   r   C   s   
O#
r   )r=   
__future__r   logging	getLoggerr2   logtypingr   r   r   r   r   r!   Zcore.has_propsr	   Z
core.typesr
   r   r7   r   r   r>   __all__r   r   r   r   r   <module>   s   
		