
    -eE                       U d Z ddlmZ ddlZ ej        e          Zddl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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 ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ erddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddlm6Z6 dZ7eeef         Z8de9d<   eee8         e:e;e8f         f         Z<de9d<   ede!e=e)         f         Z>de9d<   dSd"Z?e	 	 dTdUd+            Z@e	 	 dTdVd.            Z@e	 	 dTdWd1            Z@e	 	 dTdXd3            Z@e	 	 dTdYd6            Z@e	 	 dTdZd8            Z@	 	 d[d\d<Z@	 	 d]ei dd=d=d>d^dIZA G dJ dKe          ZBd]d_dNZCd`dPZDdadRZEdS )bz

    )annotationsN)TYPE_CHECKINGAnyLiteralSequence	TypedDictUnioncastoverload   )__version__)AUTOLOAD_JSAUTOLOAD_TAGFILEMACROSROOT_DIV)DEFAULT_TITLEDocument)Model)	ResourcesResourcesLike)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)Template)	TypeAlias)ID)DocJson)autoload_static
components	file_html	json_itemr%   	ModelLikeModelLikeCollection	ThemeLikemodelModel | Document	resourcesr   script_pathstrreturntuple[str, str]c                   t          | t                    r| g}n,t          | t                    r| j        }nt	          d          t          |          5  t          | g          \  }\  }ddd           n# 1 swxY w Y   t          d|          }|                    t          t          ||g                               t          t          |j                                                                                            \  }}t          t!          j        ||                    }	t%          j        ||          }
|	|
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 DocumentN)bundle	elementid)src_pathr8   )
isinstancer   r   roots
ValueErrorr   r"   r   addr   r   nextiterto_jsonitemsr#   r   renderr   )r/   r1   r2   models	docs_jsonrender_itemr7   _r8   jstags              6lib/python3.11/site-packages/bokeh/embed/standalone.pyr(   r(   V   s   4 % O	UH	%	% OMNNN	6	"	" T T%JE7%S%S"M[T T T T T T T T T T T T T T T +4;;F
JJv-i+GGHHIII${088::@@BBCCDDNQ		*&INNN	O	OB

  C
 s7Ns   A77A;>A;.rC   r   wrap_scriptboolwrap_plot_infoLiteral[True]themec                    d S N rC   rJ   rL   rN   s       rI   r)   r)      s    UXUX    Literal[False]tuple[str, RenderRoot]c                    d S rP   rQ   rR   s       rI   r)   r)      s    7:srS   Sequence[Model]tuple[str, Sequence[str]]c                    d S rP   rQ   rR   s       rI   r)   r)      s    _b_brS    tuple[str, Sequence[RenderRoot]]c                    d S rP   rQ   rR   s       rI   r)   r)      s    ADrS   dict[str, Model]tuple[str, dict[str, str]]c                    d S rP   rQ   rR   s       rI   r)   r)      s    `c`crS   !tuple[str, dict[str, RenderRoot]]c                    d S rP   rQ   rR   s       rI   r)   r)      s    BE#rS   T*Model | Sequence[Model] | dict[str, Model]tuple[str, Any]c                   d}t          | t                    rd}| g} t          |           } d}t          }t          | t                    r<| j        }|                                 }t          |                                           } t          | |          5  t          |           \  }\  }ddd           n# 1 swxY w Y   t          dd          }	|	                    t          t          ||g                               |	                    |          }
dd
|rfd|j        D             }nt          |j                  }|r	|d         }n+| |t!          ||                    }nt#          |          }|
|fS )aN   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 document or template in which they will be embedded needs to
    include scripts tags, either from a local URL or Bokeh's CDN (replacing
    ``x.y.z`` with the version of Bokeh you are using):

    .. 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>

    Only the Bokeh core library ``bokeh-x.y.z.min.js`` is always required. The
    other scripts are optional and only need to be included if you want to use
    corresponding features:

    * The ``"bokeh-widgets"`` files are only necessary if you are using any of the
      :ref:`Bokeh widgets <ug_interaction_widgets>`.
    * The ``"bokeh-tables"`` files are only necessary if you are using Bokeh's
      :ref:`data tables <ug_interaction_widgets_examples_datatable>`.
    * The ``"bokeh-api"`` files are required to use the
      :ref:`BokehJS API <ug_advanced_bokehjs>` and must be loaded *after* the
      core BokehJS library.
    * The ``"bokeh-gl"`` files are required to enable
      :ref:`WebGL support <ug_output_webgl>`.
    * the ``"bokeh-mathjax"`` files are required to enable
      :ref:`MathJax support <ug_styling_mathtext>`.

    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)rH   rootr    r4   r3   c                8    t          j        | t                    S )N)rf   macros)r   rB   r   )rf   s    rI   div_for_rootz components.<locals>.div_for_root  s    D8888rS   c                &    g | ]} |          S rQ   rQ   ).0rf   ri   s     rI   
<listcomp>zcomponents.<locals>.<listcomp>  s#    DDD$<<%%DDDrS   r   )rf   r    r4   r3   )r:   r   _check_models_or_docsdict	__class__keyslistvaluesr   r"   r   r=   r   r   scriptsr;   ziptuple)rC   rJ   rL   rN   was_single_object
model_keys	dict_typerD   rE   r7   scriptresultsresultri   s                @rI   r)   r)      s   x &%    "6**F J&*I&$ '$	[[]]
fmmoo&& 
6u	5	5	5 S S%J6%R%R"M[S S S S S S S S S S S S S S S +466F
JJv-i+GGHHIII^^^,,F9 9 9 9  *DDDD+2CDDD{())   		3z73344w6>s   B99B= B=F)templatetemplate_variablesrN   suppress_callback_warning_always_new"Model | Document | Sequence[Model]ResourcesLike | Nonetitle
str | Noner|   Template | strr}   dict[str, Any]r~   r   c          	        g }t          | t                    r| g}nFt          | t                    r/t          | j                  dk    rt          d          | j        }n| }t          j        |          }t          |||          5 }	t          ||          \  }
}t          ||          }t          |	g|          }t          ||
||||          cddd           S # 1 swxY w Y   dS )a*   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 (ResourcesLike) :
            A resources 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

    r   zDocument has no root Models)re   
always_new)r~   )r   r|   r}   N)r:   r   r   lenr;   r<   r   buildr   r"   _title_from_modelsr   r   )rC   r1   r   r|   r}   rN   r~   r   
models_seqdocrD   render_itemsr7   s                rI   r*   r*   &  sk   h #%J&%   X

	FH	%	% v|!!:;;;\


	**I	:5[	Q	Q	Q dUX$I*  qJ  %K  %K  %K!L":u55.ui@@)&)\QV3;Pbd d d	d d d d d d d d d d d d d d d d d ds   A
CC#&C#c                  8    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'   r   r3   versionN)__name__
__module____qualname____annotations__rQ   rS   rI   r   r   m  s7         KKKLLLLLLLLrS   r   targetr   c                   t          | g|          5 }d|_        t          | g                                          \  }ddd           n# 1 swxY w Y   |d         d         d         }t	          |||t
                    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");

    rd    Nr;   r   id)r   r   r   r   )r   r   r!   rr   r   r   )r/   r   rN   r   doc_jsonr   s         rI   r+   r+   s  s    t 
E7	6	6	6 <#	)5'2299;;
< < < < < < < < < < < < < < < w"4(G	   s   ,AAAModelLike | ModelLikeCollectionc                   d}t          | t          t          f          r| g} t          | t                    rt	          d | D                       rd}t          | t
                    rXt	          d |                                 D                       r-t	          d |                                 D                       rd}|st          d          | S )z

    Fc              3  N   K   | ] }t          |t          t          f          V  !d S rP   r:   r   r   rk   xs     rI   	<genexpr>z(_check_models_or_docs.<locals>.<genexpr>  s2      +]+]QRJq5(:K,L,L+]+]+]+]+]+]rS   Tc              3  @   K   | ]}t          |t                    V  d S rP   )r:   r3   r   s     rI   r   z(_check_models_or_docs.<locals>.<genexpr>  s,      661Jq#666666rS   c              3  N   K   | ] }t          |t          t          f          V  !d S rP   r   r   s     rI   r   z(_check_models_or_docs.<locals>.<genexpr>  s1      FFJq5(+,,FFFFFFrS   zwInput must be a Model, a Document, a Sequence of Models and Document, or a dictionary from string to Model and Document)	r:   r   r   r   allrn   rp   rr   r<   )rC   input_type_valids     rI   rm   rm     s      &5(+,,  &(##  +]+]V\+]+]+](](]  &$  6666666 FFfmmooFFFFF    
 F
 
 	
 MrS   Sequence[Model | Document]c                    ||S | D ] }t          |t                    r	|j        c S !t          t          t
                   |           D ]}|j        |j        j        c S t          S rP   )r:   r   r   r
   r   r   documentr   )rC   r   ps      rI   r   r     s       a"" 	7NNN	 (5/6** $ $:!:#### " rS   )r/   r0   r1   r   r2   r3   r4   r5   )...)
rC   r   rJ   rK   rL   rM   rN   r.   r4   r5   )
rC   r   rJ   rK   rL   rT   rN   r.   r4   rU   )
rC   rW   rJ   rK   rL   rM   rN   r.   r4   rX   )
rC   rW   rJ   rK   rL   rT   rN   r.   r4   rZ   )
rC   r\   rJ   rK   rL   rM   rN   r.   r4   r]   )
rC   r\   rJ   rK   rL   rT   rN   r.   r4   r_   )TTN)
rC   ra   rJ   rK   rL   rK   rN   r.   r4   rb   )NN)rC   r   r1   r   r   r   r|   r   r}   r   rN   r.   r~   rK   r   rK   r4   r3   )r/   r   r   r   rN   r.   r4   r   )rC   r   r4   r-   )rC   r   r   r   r4   r3   )F__doc__
__future__r   logging	getLoggerr   logtypingr   r   r   r   r   r	   r
   r   r   r   core.templatesr   r   r   r   r   document.documentr   r   r/   r   r1   r   r   themesr   r7   r   r   elementsr   r   utilr   r   r    r!   r"   wrappersr#   jinja2r$   typing_extensionsr%   
core.typesr&   r'   __all__r,   r   rn   r3   r-   typer.   r(   r)   r*   r   r+   rm   r   rQ   rS   rI   <module>r      s     # " " " " " g!!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                    8 7 7 7 7 7 7 7       0 0 0 0 0 0 0 0       9 9 9 9 9 9 9 9 I I I I I I I I              % $ $ $ $ $ ,++++++++++++ UH_-	 - - - -!&x	':Di<P'P!Q  Q Q Q Q T5$z*::;	 ; ; ; ;0 0 0 0d 
25<?Y Y Y Y 
Y	X[; ; ; ; 
; 
<?<?c c c c 
c	beE E E E 
E 
=@<?d d d d 
d	cfF F F F 
F X\?CG G G G GT 15"&Ed *.35!%05"'Ed Ed Ed Ed Ed EdN    )   E E E E E^   4     rS   