This commit is contained in:
Emma Lewis 2020-07-07 18:08:47 +03:00 committed by GitHub
commit 76849ef6df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -27,3 +27,19 @@ def extra_css_urls():
@hookimpl
def extra_js_urls():
return cached_filepaths_for_extension('js')
@hookimpl
def extra_body_script(template, database, table, datasette):
config = (
datasette.plugin_config("datasette-vega", database=database, table=table)
or {}
)
js = []
value = config.get("container")
if value:
js.append(
"window.DATASETTE_VEGA_{} = '{}';".format(
"CONTAINER", value
)
)
return "\n".join(js)

View file

@ -47,8 +47,13 @@ document.addEventListener('DOMContentLoaded', () => {
jsonUrl = jsonEl.getAttribute('href');
// Create elements for adding graph tool to page
visTool = document.createElement('div');
let table = document.querySelector('table.rows-and-columns');
table.parentNode.insertBefore(visTool, table);
const container = window.DATASETTE_VEGA_CONTAINER;
if (container && document.querySelector(container)) {
document.querySelector(container).appendChild(visTool);
} else {
let table = document.querySelector('table.rows-and-columns');
table.parentNode.insertBefore(visTool, table);
}
}
}
if (jsonUrl) {