-
Notifications
You must be signed in to change notification settings - Fork 86
/
container.ts
29 lines (24 loc) · 992 Bytes
/
container.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {View} from 'vega';
import embed, {EmbedOptions, VisualizationSpec} from './embed';
/**
* Create a promise to an HTML Div element with an embedded Vega-Lite or Vega visualization.
* The element has a value property with the view. By default all actions except for the editor action are disabled.
*
* The main use case is in [Observable](https://observablehq.com/).
*/
export default async function (spec: VisualizationSpec | string, opt: EmbedOptions = {}) {
const wrapper = document.createElement('div') as HTMLDivElement & {value: View};
wrapper.classList.add('vega-embed-wrapper');
const div = document.createElement('div');
wrapper.appendChild(div);
const actions =
opt.actions === true || opt.actions === false
? opt.actions
: {export: true, source: false, compiled: true, editor: true, ...(opt.actions ?? {})};
const result = await embed(div, spec, {
actions,
...(opt ?? {}),
});
wrapper.value = result.view;
return wrapper;
}