import json import jinja2 HTML_TEMPLATE = jinja2.Template( """ {%- if fullhtml -%} {%- endif %} {%- if not requirejs %} {%- if mode == 'vega-lite' %} {%- endif %} {%- endif %} {%- if fullhtml %} {%- if requirejs %} {%- endif %} {%- endif %}
{%- if fullhtml %} {%- endif %} """ ) HTML_TEMPLATE_UNIVERSAL = jinja2.Template( """
""" ) TEMPLATES = { "standard": HTML_TEMPLATE, "universal": HTML_TEMPLATE_UNIVERSAL, } def spec_to_html( spec, mode, vega_version, vegaembed_version, vegalite_version=None, base_url="https://cdn.jsdelivr.net/npm/", output_div="vis", embed_options=None, json_kwds=None, fullhtml=True, requirejs=False, template="standard", ): """Embed a Vega/Vega-Lite spec into an HTML page Parameters ---------- spec : dict a dictionary representing a vega-lite plot spec. mode : string {'vega' | 'vega-lite'} The rendering mode. This value is overridden by embed_options['mode'], if it is present. vega_version : string For html output, the version of vega.js to use. vegalite_version : string For html output, the version of vegalite.js to use. vegaembed_version : string For html output, the version of vegaembed.js to use. base_url : string (optional) The base url from which to load the javascript libraries. output_div : string (optional) The id of the div element where the plot will be shown. embed_options : dict (optional) Dictionary of options to pass to the vega-embed script. Default entry is {'mode': mode}. json_kwds : dict (optional) Dictionary of keywords to pass to json.dumps(). fullhtml : boolean (optional) If True (default) then return a full html page. If False, then return an HTML snippet that can be embedded into an HTML page. requirejs : boolean (optional) If False (default) then load libraries from base_url using