<commit_before>''' This module provides functions for embedding Bokeh plots in various
different ways.

There are a number of different combinations of options when embedding
Bokeh plots. The data for the plot can be contained in the document,
or on a Bokeh server, or in a sidecar JavaScript file. Likewise, BokehJS
may be inlined in the document, or loaded from CDN or a Bokeh server.

The functions in ``bokeh.embed`` provide functionality to embed in all
these different cases.

'''

from __future__ import absolute_import

from warnings import warn
import uuid

from .protocol import serialize_json
from .resources import Resources
from .templates import (
    AUTOLOAD, AUTOLOAD_SERVER, AUTOLOAD_STATIC, FILE,
    NOTEBOOK_DIV, PLOT_DIV, PLOT_JS, PLOT_SCRIPT, RESOURCES
)
from .util.string import encode_utf8

from .plot_object import PlotObject
from collections import Sequence
from six import string_types


def _wrap_in_function(code):
    # Indent and wrap Bokeh function def around
    code = "\n".join(["    " + line for line in code.split("\n")])
    return 'Bokeh.$(function() {\n%s\n});' % code


def components(plot_objects, resources=None, wrap_script=True, wrap_plot_info=True):
    '''
    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


    .. note:: The returned components assume that BokehJS resources
              are **already loaded**.

    Args
    ----
    plot_objects : PlotObject|list|dict|tuple
        A single PlotObject, a list/tuple of PlotObjects, or a dictionary of keys and PlotObjects.

    resources :
        Deprecated argument

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

    wrap_plot_info : boolean, optional
        If true, then a set of divs are returned.
        If set to false, then dictionaries are returned that can be used to manually
        build your own divs. (default: True)

        If false, the returned dictionary contains the following information::

            {
                'modelid':  'The plots id, which can be used in the Bokeh.index',
                'elementid': 'The css identifier the BokehJS will look for to target the plot',
                'modeltype': 'Plot',
            }



    Returns
    -------
    (script, div[s]) :  UTF-8 encoded

        The output, depends on the input as follows::

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

            components((plot_1, plot_2))
            #=> (script, (plot_1_div, plot_2_div))

            components({"Plot 1": plot_1, "Plot 2": plot_2})
            #=> (script, {"Plot 1": plot_1_div, "Plot 2": plot_2_div})

    (raw_script, plot_info[s]) : UTF-8 encoded
<commit_msg>Update docs as not always Plot modeltype returned.<commit_after>''' This module provides functions for embedding Bokeh plots in various
different ways.

There are a number of different combinations of options when embedding
Bokeh plots. The data for the plot can be contained in the document,
or on a Bokeh server, or in a sidecar JavaScript file. Likewise, BokehJS
may be inlined in the document, or loaded from CDN or a Bokeh server.

The functions in ``bokeh.embed`` provide functionality to embed in all
these different cases.

'''

from __future__ import absolute_import

from warnings import warn
import uuid

from .protocol import serialize_json
from .resources import Resources
from .templates import (
    AUTOLOAD, AUTOLOAD_SERVER, AUTOLOAD_STATIC, FILE,
    NOTEBOOK_DIV, PLOT_DIV, PLOT_JS, PLOT_SCRIPT, RESOURCES
)
from .util.string import encode_utf8

from .plot_object import PlotObject
from collections import Sequence
from six import string_types


def _wrap_in_function(code):
    # Indent and wrap Bokeh function def around
    code = "\n".join(["    " + line for line in code.split("\n")])
    return 'Bokeh.$(function() {\n%s\n});' % code


def components(plot_objects, resources=None, wrap_script=True, wrap_plot_info=True):
    '''
    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


    .. note:: The returned components assume that BokehJS resources
              are **already loaded**.

    Args
    ----
    plot_objects : PlotObject|list|dict|tuple
        A single PlotObject, a list/tuple of PlotObjects, or a dictionary of keys and PlotObjects.

    resources :
        Deprecated argument

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

    wrap_plot_info : boolean, optional
        If true, then a set of divs are returned.
        If set to false, then dictionaries are returned that can be used to manually
        build your own divs. (default: True)

        If false, the returned dictionary contains the following information::

            {
                'modelid':  'The plots id, which can be used in the Bokeh.index',
                'elementid': 'The css identifier the BokehJS will look for to target the plot',
                'modeltype': 'The Bokeh model name e.g. Plot, Slider',
            }



    Returns
    -------
    (script, div[s]) :  UTF-8 encoded

        The output, depends on the input as follows::

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

            components((plot_1, plot_2))
            #=> (script, (plot_1_div, plot_2_div))

            components({"Plot 1": plot_1, "Plot 2": plot_2})
            #=> (script, {"Plot 1": plot_1_div, "Plot 2": plot_2_div})

    (raw_script, plot_info[s]) : UTF-8 encoded

{'fraction_non_alphanumeric': 0.07995828263514689, 'fraction_numerical': 0.005214670606640014, 'mean_word_length': 2.890466531440162, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '453070', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1581, 'n_words': 667}