U
    /eC                     @  s  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mZmZmZmZmZ ddlmZ ddlmZ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 m!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+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 er8ddl8m9Z9 ddlm:Z: dZ;ee#e!f Z<eee< e
e=e<f f Z>ede)ee1 f Z?dddddddZ@edNddd d!dd"d#d$ZAedOddd%d!d&d"d'd$ZAedPd(dd d!d)d"d*d$ZAedQd(dd%d!d+d"d,d$ZAedRd-dd d!d.d"d/d$ZAedSd-dd%d!d0d"d1d$ZAdTd3ddd!d4d"d5d$ZAdei dd6d6fd7d8d9d:d;d!dddd<	d=d>ZBG d?d@ d@eZCdUddAd!d@dBdCdDZDdEdFdGdHdIZEdJd9ddKdLdMZFdS )Vz

    )annotationsN)
TYPE_CHECKINGAnyDictListSequenceTupleTypeUnioncastoverload)Template)Literal	TypedDict   )__version__)AUTOLOAD_JSAUTOLOAD_TAGFILEMACROSROOT_DIV)DEFAULT_TITLEDocument)Model)CSSResourcesJSResources	Resources)Theme   )Scriptbundle_for_objs_and_resources)html_page_for_render_itemsscript_for_render_items)
FromCurdocOutputDocumentFor
RenderRootstandalone_docs_json%standalone_docs_json_and_render_items)wrap_in_onload)ID)DocJson)autoload_static
components	file_html	json_itemzUnion[Model, Document]r   strzTuple[str, str])model	resourcesscript_pathreturnc              	   C  s   t | tr| g}nt | tr$| j}ntdt| t| g\}\}W 5 Q R X td|}|t	t
||g t|j  d \}}ttj||d}	tj||d}
|	|
fS )a   Return JavaScript code and a script tag that can be used to embed
    Bokeh Plots.

    The data for the plot is stored directly in the returned JavaScript code.

    Args:
        model (Model or Document) :

        resources (Resources) :

        script_path (str) :

    Returns:
        (js, tag) :
            JavaScript code to be saved at ``script_path`` and a ``<script>``
            tag to load it

    Raises:
        ValueError

    z2autoload_static expects a single Model or DocumentNr   )bundle	elementid)Zsrc_pathr5   )
isinstancer   r   roots
ValueErrorr$   r'   r    addr   r"   listZto_jsonitemsr(   r   renderr   )r0   r1   r2   models	docs_jsonrender_itemr4   _r5   Zjstag rB   :/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/embed/standalone.pyr+   Y   s     



r+   .r   boolzLiteral[True]	ThemeLike)r=   wrap_scriptwrap_plot_infothemer3   c                 C  s   d S NrB   r=   rF   rG   rH   rB   rB   rC   r,      s    r,   zLiteral[False]zTuple[str, RenderRoot]c                 C  s   d S rI   rB   rJ   rB   rB   rC   r,      s    zSequence[Model]zTuple[str, Sequence[str]]c                 C  s   d S rI   rB   rJ   rB   rB   rC   r,      s    z Tuple[str, Sequence[RenderRoot]]c                 C  s   d S rI   rB   rJ   rB   rB   rC   r,      s    zDict[str, Model]zTuple[str, Dict[str, str]]c                 C  s   d S rI   rB   rJ   rB   rB   rC   r,      s    z!Tuple[str, Dict[str, RenderRoot]]c                 C  s   d S rI   rB   rJ   rB   rB   rC   r,      s    Tz*Model | Sequence[Model] | Dict[str, Model]zTuple[str, Any]c              	     s  d}t | trd}| g} t| } d}t}t | trL| j}|  }t|  } t| |d t	| \}\}W 5 Q R X t
dd}	|	tt||g |	j|d}
dddd	d
 |rt fdd|jD }n
t|j}|r|d }n |dk	r|t||}nt|}|
|fS )a   Return HTML components to embed a Bokeh plot. The data for the plot is
    stored directly in the returned HTML.

    An example can be found in examples/embed/embed_multiple.py

    The returned components assume that BokehJS resources are **already loaded**.
    The html template in which they will be embedded needs to include the following
    scripts tags:

    .. code-block:: html

        <script src="https://cdn.bokeh.org/bokeh/release/bokeh-x.y.z.min.js"></script>
        <script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-x.y.z.min.js"></script>
        <script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-x.y.z.min.js"></script>
        <script src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-x.y.z.min.js"></script>
        <script src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-x.y.z.min.js"></script>

    The ``"-widgets"``, ``"-tables"``, and ``"-mathjax"`` files are only necessary
    if your document includes :ref:`Bokeh widgets <userguide_interaction_widgets>`,
    :ref:`data tables <userguide_interaction_widgets_examples_datatable>`, or
    :ref:`math text <userguide_styling_math>`, respectively.

    Args:
        models (Model|list|dict|tuple) :
            A single Model, a list/tuple of Models, or a dictionary of keys
            and Models.

        wrap_script (boolean, optional) :
            If True, the returned javascript is wrapped in a script tag.
            (default: True)

        wrap_plot_info (boolean, optional) :
            If True, returns ``<div>`` strings. Otherwise, return
            :class:`~bokeh.embed.RenderRoot` objects that can be used to build
            your own divs. (default: True)

        theme (Theme, optional) :
            Applies the specified theme when creating the components. If None,
            or not specified, and the supplied models constitute the full set
            of roots of a document, applies the theme of that document to the
            components. Otherwise applies the default theme.

    Returns:
        UTF-8 encoded *(script, div[s])* or *(raw_script, plot_info[s])*

    Examples:

        With default wrapping parameter values:

        .. code-block:: python

            components(plot)
            # => (script, plot_div)

            components((plot1, plot2))
            # => (script, (plot1_div, plot2_div))

            components({"Plot 1": plot1, "Plot 2": plot2})
            # => (script, {"Plot 1": plot1_div, "Plot 2": plot2_div})

    Examples:

        With wrapping parameters set to ``False``:

        .. code-block:: python

            components(plot, wrap_script=False, wrap_plot_info=False)
            # => (javascript, plot_root)

            components((plot1, plot2), wrap_script=False, wrap_plot_info=False)
            # => (javascript, (plot1_root, plot2_root))

            components({"Plot 1": plot1, "Plot 2": plot2}, wrap_script=False, wrap_plot_info=False)
            # => (javascript, {"Plot 1": plot1_root, "Plot 2": plot2_root})

    FTNapply_theme)rA   r%   r/   )rootr3   c                 S  s   t j| tdS )N)rM   macros)r   r<   r   )rM   rB   rB   rC   div_for_root	  s    z components.<locals>.div_for_rootc                 3  s   | ]} |V  qd S rI   rB   ).0rM   rO   rB   rC   	<genexpr>  s     zcomponents.<locals>.<genexpr>r   )r6   r   _check_models_or_docsdict	__class__keysr:   valuesr$   r'   r    r9   r   r"   scriptsr7   ziptuple)r=   rF   rG   rH   Zwas_single_objectZ
model_keys	dict_typer>   r?   r4   scriptresultsresultrB   rQ   rC   r,      s4    P




Fz"Model | Document | Sequence[Model]zAResources | Tuple[JSResources | None, CSSResources | None] | Nonez
str | NonezTemplate | strzDict[str, Any])	r=   r1   titletemplatetemplate_variablesrH   suppress_callback_warning_always_newr3   c              
   C  s   g }t | tr| g}nt | tr(| j}n| }t|||dH}	t||d\}
}t||}t|	g|}t||
||||dW  5 Q R  S Q R X dS )aY   Return an HTML document that embeds Bokeh Model or Document objects.

    The data for the plot is stored directly in the returned HTML, with
    support for customizing the JS/CSS resources independently and
    customizing the jinja2 template.

    Args:
        models (Model or Document or seq[Model]) : Bokeh object or objects to render
            typically a Model or Document

        resources (Resources or tuple(JSResources or None, CSSResources or None)) :
            A resource configuration for Bokeh JS & CSS assets.

        title (str, optional) :
            A title for the HTML document ``<title>`` tags or None. (default: None)

            If None, attempt to automatically find the Document title from the given
            plot objects.

        template (Template, optional) : HTML document template (default: FILE)
            A Jinja2 Template, see bokeh.core.templates.FILE for the required
            template parameters

        template_variables (dict, optional) : variables to be used in the Jinja2
            template. If used, the following variable names will be overwritten:
            title, bokeh_js, bokeh_css, plot_script, plot_div

        theme (Theme, optional) :
            Applies the specified theme to the created html. If ``None``, or
            not specified, and the function is passed a document or the full set
            of roots of a document, applies the theme of that document.  Otherwise
            applies the default theme.

        suppress_callback_warning (bool, optional) :
            Normally generating standalone HTML from a Bokeh Document that has
            Python callbacks will result in a warning stating that the callbacks
            cannot function. However, this warning can be suppressed by setting
            this value to True (default: False)

    Returns:
        UTF-8 encoded HTML

    )rL   Z
always_new)rb   )r_   r`   ra   N)	r6   r   r   r7   r$   r'   _title_from_modelsr    r!   )r=   r1   r_   r`   ra   rH   rb   rc   Z
models_seqdocr>   Zrender_itemsr4   rB   rB   rC   r-     s    4



 r-   c                   @  s.   e Zd ZU ded< ded< ded< ded< d	S )
StandaloneEmbedJson	ID | None	target_idr)   root_idr*   re   r/   versionN)__name__
__module____qualname____annotations__rB   rB   rB   rC   rf   `  s   
rf   rg   )r0   targetrH   r3   c              	   C  sZ   t | g|d}d|_t| g}W 5 Q R X t| d }|d d d }t|||tdS )a   Return a JSON block that can be used to embed standalone Bokeh content.

    Args:
        model (Model) :
            The Bokeh object to embed

        target (string, optional)
            A div id to embed the model into. If None, the target id must
            be supplied in the JavaScript call.

        theme (Theme, optional) :
            Applies the specified theme to the created html. If ``None``, or
            not specified, and the function is passed a document or the full set
            of roots of a document, applies the theme of that document.  Otherwise
            applies the default theme.

    Returns:
        JSON-like

    This function returns a JSON block that can be consumed by the BokehJS
    function ``Bokeh.embed.embed_item``. As an example, a Flask endpoint for
    ``/plot`` might return the following content to embed a Bokeh plot into
    a div with id *"myplot"*:

    .. code-block:: python

        @app.route('/plot')
        def plot():
            p = make_plot('petal_width', 'petal_length')
            return json.dumps(json_item(p, "myplot"))

    Then a web page can retrieve this JSON and embed the plot by calling
    ``Bokeh.embed.embed_item``:

    .. code-block:: html

        <script>
        fetch('/plot')
            .then(function(response) { return response.json(); })
            .then(function(item) { Bokeh.embed.embed_item(item); })
        </script>

    Alternatively, if is more convenient to supply the target div id directly
    in the page source, that is also possible. If `target_id` is omitted in the
    call to this function:

    .. code-block:: python

        return json.dumps(json_item(p))

    Then the value passed to ``embed_item`` is used:

    .. code-block:: javascript

        Bokeh.embed.embed_item(item, "myplot");

    rK    r   r7   Zroot_ids)rh   ri   re   rj   )r$   r_   r&   r:   rW   rf   r   )r0   ro   rH   re   r>   Zdoc_jsonri   rB   rB   rC   r.   f  s    :r.   z%Union[ModelLike, ModelLikeCollection]ModelLikeCollection)r=   r3   c                 C  s   d}t | ttfr| g} t | tr8tdd | D r8d}t | trrtdd |  D rrtdd |  D rrd}|s~td| S )z

    Fc                 s  s   | ]}t |ttfV  qd S rI   r6   r   r   rP   xrB   rB   rC   rR     s     z(_check_models_or_docs.<locals>.<genexpr>Tc                 s  s   | ]}t |tV  qd S rI   )r6   r/   rs   rB   rB   rC   rR     s     c                 s  s   | ]}t |ttfV  qd S rI   rr   rs   rB   rB   rC   rR     s     zwInput must be a Model, a Document, a Sequence of Models and Document, or a dictionary from string to Model and Document)	r6   r   r   r   allrT   rV   rW   r8   )r=   Zinput_type_validrB   rB   rC   rS     s     
rS   z Sequence[Union[Model, Document]])r=   r_   r3   c                 C  sX   |d k	r|S | D ]}t |tr|j  S qttt | D ]}|jd k	r8|jj  S q8tS rI   )r6   r   r_   r   r   r   documentr   )r=   r_   prB   rB   rC   rd     s    

rd   )...)...)...)...)...)...)TTN)NN)G__doc__
__future__r   logging	getLoggerrk   logtypingr   r   r   r   r   r   r	   r
   r   r   Zjinja2r   Ztyping_extensionsr   r   rp   r   Zcore.templatesr   r   r   r   r   Zdocument.documentr   r   r0   r   r1   r   r   r   Zthemesr   r4   r   r    elementsr!   r"   utilr#   r$   r%   r&   r'   wrappersr(   Z
core.typesr)   r*   __all__Z	ModelLiker/   rq   rE   r+   r,   r-   rf   r.   rS   rd   rB   rB   rB   rC   <module>   s   
02                       CP