σ
mάJ]c           @` s  d  Z  d d l m Z m Z m Z m Z d d l Z e j e  Z	 d 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 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! d d l" m# Z# m$ Z$ m% Z% m& Z& d d l' m( Z( m) Z) d Z* d   Z+ e, e, e# d  Z- d e i  e# e/ e/ d  Z0 d e# d  Z1 d   Z2 d   Z3 d S(   u   

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   collections_abc(   t   string_typesi   (   t   AUTOLOAD_JSt   AUTOLOAD_TAGt   FILEt   ROOT_DIVt   MACROS(   t   DEFAULT_TITLEt   Document(   t   Model(   t   bundle_all_models(   t   encode_utf8i   (   t   bundle_for_objs_and_resources(   t   html_page_for_render_itemst   script_for_render_items(   t
   FromCurdoct   OutputDocumentFort   standalone_docs_jsont%   standalone_docs_json_and_render_items(   t   wrap_in_onloadt   wrap_in_script_tagu   autoload_staticu
   componentsu	   file_htmlu	   json_itemc         C` s'  t  |  t  r |  g } n' t  |  t  r6 |  j } n t d   t |   t |  g  \ } \ } Wd QXt   py d } t | | g  } t	 | j j
   j    d \ } }	 t t j d | j d | j d | j | | g d | j d	 |	   }
 t j d
 | d	 |	  } t |
  t |  f S(   uΐ   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

    u2   autoload_static expects a single Model or DocumentNu    i    t   js_urlst   css_urlst   js_rawt   css_rawt	   elementidt   src_path(   t
   isinstanceR   R   t   rootst
   ValueErrorR   R   R   R   t   listt   to_jsont   itemsR   R   t   rendert   js_filest	   css_filesR   t   css_raw_strR   R   (   t   modelt	   resourcest   script_patht   modelst	   docs_jsont   render_itemt   bundlet   scriptt   modelidR   t   jst   tag(    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pyt   autoload_static7   s(    %					c         ` s  t  |  t  p t  |  t  } t |   }  d } d } t  |  t  r |  j   } |  j } g  } x | D] } | j |  |  qg W| }  n  t	 |  d |  t
 |   \ }	 \ }
 Wd QXt   pΕ d } | t |	 |
 g  7} | rσ t |  } n  t |  } d     | r0t   f d   |
 j D  } n	 |
 j } | rL| d } n0 | d k	 rp| t | |   } n t |  } | | f S(   u   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. The widgets and tables resources are only necessary if the components
    make use of widgets and tables.

    .. code-block:: html

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

    Note that in Jupyter Notebooks, it is not possible to use components and show in
    the same notebook cell.

    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 dicts that can be used to build your own divs.
            (default: True)

            If False, the returned dictionary contains the following information:

            .. code-block:: python

                {
                    'modelid':  'The model ID, used with Document.get_model_by_id',
                    'elementid': 'The css identifier the BokehJS will look for to target the plot',
                    'docid': 'Used by Bokeh to find the doc embedded in the returned script',
                }

        theme (Theme, optional) :
            Defaults to the ``Theme`` instance in the current document.
            Setting this to ``None`` uses the default theme or the theme
            already specified in the document. Any other value must be an
            instance of the ``Theme`` class.

    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_dict)

            components((plot1, plot2), wrap_script=False, wrap_plot_info=False)
            # => (javascript, (plot1_dict, plot2_dict))

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

    t   apply_themeNu    c         S` s   t  j d |  d t  S(   Nt   roott   macros(   R	   R%   R
   (   R6   (    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pyt   div_for_rootέ   s    c         3` s   |  ] }   |  Vq d  S(   N(    (   t   .0R6   (   R8   (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pys	   <genexpr>α   s    i    (   R   R   R   t   _check_models_or_docst   Nonet   dictt   keyst	   __class__t   appendR   R   R   R   R   R   R"   R    t   zipt   tuple(   R,   t   wrap_scriptt   wrap_plot_infot   themet   was_single_objectt
   model_keyst	   dict_typet   valuest   kR-   R.   R0   t   resultst   result(    (   R8   s5   lib/python2.7/site-packages/bokeh/embed/standalone.pyt
   componentso   s8    T			"	c         C` sΆ   t  |  t  r |  g }  n  t  |  t  r6 |  j }  n  t |  d | d | b } t |  d | \ }	 }
 t |  |  } t | g |  } t | |	 |
 d | d | d | SWd QXd S(   uI   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) :
            Defaults to the ``Theme`` instance in the current document.
            Setting this to ``None`` uses the default theme or the theme
            already specified in the document. Any other value must be an
            instance of the ``Theme`` class.

        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

    R5   t
   always_newt   suppress_callback_warningt   titlet   templatet   template_variablesN(	   R   R   R   R    R   R   t   _title_from_modelsR   R   (   R,   R*   RO   RP   RQ   RD   RN   t   _always_newt   docR-   t   render_itemsR/   (    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pyt	   file_htmlπ   s    3c         C` sw   t  |  g d |  } d | _ t |  g  } Wd QXt | j    d } | d d d } i | d 6| d 6| d	 6S(
   u	   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) :
            Defaults to the ``Theme`` instance in the current document.
            Setting this to ``None`` uses the default theme or the theme
            already specified in the document. Any other value must be an
            instance of the ``Theme`` class.

    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");

    R5   u    Ni    u   rootsu   root_idsu	   target_idu   root_idu   doc(   R   RO   R   R"   RH   (   R)   t   targetRD   RT   R-   t   root_id(    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pyt	   json_item0  s    :	c         C` sΑ   t  } t |  t t f  r' |  g }  n  t |  t j  rX t d   |  D  rX t } n  t |  t  r¨ t d   |  j	   D  r¨ t d   |  j
   D  r¨ t } n  | s½ t d   n  |  S(   u   

    c         s` s$   |  ] } t  | t t f  Vq d  S(   N(   R   R   R   (   R9   t   x(    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pys	   <genexpr>  s    c         s` s   |  ] } t  | t  Vq d  S(   N(   R   R   (   R9   RZ   (    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pys	   <genexpr>  s    c         s` s$   |  ] } t  | t t f  Vq d  S(   N(   R   R   R   (   R9   RZ   (    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pys	   <genexpr>  s    uw   Input must be a Model, a Document, a Sequence of Models and Document, or a dictionary from string to Model and Document(   t   FalseR   R   R   R   t   Sequencet   allt   TrueR<   R=   RH   R!   (   R,   t   input_type_valid(    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pyR:     s    (		c         C` se   | d  k	 r | Sx$ |  D] } t | t  r | j Sq Wx' |  D] } | j d  k	 r> | j j Sq> Wt S(   N(   R;   R   R   RO   t   documentR   (   R,   RO   t   p(    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pyRR     s    (   u   autoload_staticu
   componentsu	   file_htmlu	   json_item(4   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logt   bokeh.util.futureR   t   sixR   t   core.templatesR   R   R   R	   R
   t   document.documentR   R   R)   R   t   util.compilerR   t   util.stringR   R/   R   t   elementsR   R   t   utilR   R   R   R   t   wrappersR   R   t   __all__R4   R^   RL   R;   R[   RV   RY   R:   RR   (    (    (    s5   lib/python2.7/site-packages/bokeh/embed/standalone.pyt   <module>	   s:   "("   	89P	