a
    @Df                  	   @  s2  d Z ddlmZ ddlZeeZddlmZ ddl	m
Z
mZ e
rNddlmZ ddlmZ dd	l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dlmZ ddlmZmZm Z  e
rddl!m"Z" ddlm#Z# ddl$m%Z% dZ&dddddZ'di fddddddddd d!Z(d&d"ddddd#d$d%Z)dS )'z: Generate various HTML elements from Bokeh render items.

    )annotationsN)escape)TYPE_CHECKINGAny)Template   )serialize_json)DOC_JSFILEMACROSPLOT_DIVget_env)DEFAULT_TITLE)settings) make_globally_unique_css_safe_id   )
RenderItem)wrap_in_onloadwrap_in_safelywrap_in_script_tag)ID)DocJson)Bundle)div_for_render_itemhtml_page_for_render_itemsscript_for_render_itemsr   str)itemreturnc                 C  s   t j| tdS )z Render an HTML div for a Bokeh render item.

    Args:
        item (RenderItem):
            the item to create a div for

    Returns:
        str

    )docmacros)r   renderr   )r    r"   a/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/bokeh/embed/elements.pyr   E   s    r   zBundle | tuple[str, str]zdict[ID, DocJson]zlist[RenderItem]z
str | NonezTemplate | str | Nonezdict[str, Any])bundle	docs_jsonrender_itemstitletemplatetemplate_variablesr   c                 C  s   |du rt }| \}}t }tt|dd}	t|	d|}	tt||}
| }|t||||	|
 |t	t
d t|dkr|d d |d	< |d	 j|d
< ddd |D |d< |du rt	}nt|trt d| }||}|S )a   Render an HTML page from a template and Bokeh render items.

    Args:
        bundle (tuple):
            A tuple containing (bokeh_js, bokeh_css).

        docs_json (JSON-like):
            Serialized Bokeh Document.

        render_items (RenderItems):
            Specific items to render from the document and where.

        title (str or None):
            A title for the HTML page. If None, DEFAULT_TITLE is used.

        template (str or Template or None, optional):
            A Template to be used for the HTML page. If None, FILE is used.

        template_variables (dict, optional):
            Any Additional variables to pass to the template.

    Returns:
        str

    NFquotezapplication/json)r'   bokeh_js	bokeh_cssZplot_scriptdocsbaser    r   r.   r   r   roots
c                 s  s   | ]}t |V  qd S )N)r   .0r   r"   r"   r#   	<genexpr>       z-html_page_for_render_items.<locals>.<genexpr>Zplot_divz{% extends base %}
)r   r   r   r   r   r   copyupdatedictr
   r   lenr0   join
isinstancer   r   Zfrom_stringr!   )r$   r%   r&   r'   r(   r)   r,   r-   Zjson_idjsonscriptcontexthtmlr"   r"   r#   r   R   s6    !


r   zID | dict[ID, DocJson])docs_json_or_idr&   app_pathabsolute_urlr   c                 C  s   t | trd|  d}n<t| dd}t|dd}|dd}|dd	}d| d }tj|td
d |D dd||d}tjst	|}t
|S )a8   Render an script for Bokeh render items.
    Args:
        docs_json_or_id:
            can be None

        render_items (RenderItems) :
            Specific items to render from the document and where

        app_path (str, optional) :

        absolute_url (Theme, optional) :

    Returns:
        str
    zdocument.getElementById('z').textContentF)prettyr*   'z&#x27;\z\\c                 S  s   g | ]}|  qS r"   )to_jsonr2   r"   r"   r#   
<listcomp>   r5   z+script_for_render_items.<locals>.<listcomp>)r%   r&   rA   rB   )r;   r   r   r   replacer	   r!   r   devr   r   )r@   r&   rA   rB   r%   Zjsr"   r"   r#   r      s     
r   )NN)*__doc__
__future__r   logging	getLogger__name__logr?   r   typingr   r   Zjinja2r   Zcore.json_encoderr   Zcore.templatesr	   r
   r   r   r   Zdocument.documentr   r   Zutil.serializationr   utilr   wrappersr   r   r   Z
core.typesr   r   r$   r   __all__r   r   r   r"   r"   r"   r#   <module>   s2   
H 