-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy patheRender.js
More file actions
132 lines (122 loc) · 3.27 KB
/
Copy patheRender.js
File metadata and controls
132 lines (122 loc) · 3.27 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* eslint no-underscore-dangle:0 */
import { embed } from '@nebula.js/stardust';
// eslint-disable-next-line import/no-unresolved
import snapshooter from '@nebula.js/snapshooter/client';
import { openApp, getParams, getConnectionInfo } from './connect';
import initiateWatch from './hot';
import renderFixture from './render-fixture';
const nuke = async ({ app, supernova: { name }, themes, theme, language }) => {
const nuked = embed.createConfiguration({
themes: themes
? themes.map((t) => ({
id: t,
load: async () => (await fetch(`/theme/${t}`)).json(),
}))
: undefined,
context: {
theme,
language,
},
});
const nebbie = nuked(app, {
load: (type) => Promise.resolve(window[type.name]),
types: [
{
name,
},
],
});
return nebbie;
};
async function renderWithEngine() {
const info = await getConnectionInfo();
await initiateWatch(info);
if (!info.enigma.appId) {
location.href = location.origin; //eslint-disable-line
}
const params = getParams();
const app = await openApp(info.enigma.appId);
const nebbie = await nuke({ app, ...info, theme: params.theme, language: params.language });
const element = document.querySelector('#chart-container');
let cfg;
if (params['render-config']) {
const rc = await (await fetch(`/render-config/${params['render-config']}`)).json();
cfg = {
...rc,
// eslint-disable-next-line no-nested-ternary
...(params.object ? { id: params.object } : rc.id ? { id: rc.id } : {}),
type: rc.type ? rc.type : info.supernova.name,
fields: params.cols ? params.cols : rc.fields,
element,
};
} else if (params.object) {
cfg = {
id: params.object,
element,
};
} else {
cfg = {
type: info.supernova.name,
fields: params.cols || [],
element,
};
}
const renderViz = async () => {
await nebbie.render(cfg);
};
let viz;
window.onHotChange(info.supernova.name, async () => {
if (viz) {
viz.close();
nebbie.__DO_NOT_USE__.types.clearFromCache(info.supernova.name);
nebbie.__DO_NOT_USE__.types.register(info.supernova);
}
viz = await renderViz();
});
}
async function renderSnapshot() {
const info = await getConnectionInfo();
const { themes, supernova } = info;
await initiateWatch(info);
const element = document.querySelector('#chart-container');
element.classList.toggle('full', true);
const n = embed.createConfiguration({
themes: themes
? themes.map((t) => ({
key: t,
load: async () => (await fetch(`/theme/${t}`)).json(),
}))
: undefined,
types: [
{
load: (type) => Promise.resolve(window[type.name]),
name: supernova.name,
},
],
context: {
constraints: {
passive: true,
active: true,
},
},
});
window.onHotChange(supernova.name, async () => {
const params = getParams();
snapshooter({
embed: n,
element,
snapshot: params.snapshot,
});
});
}
function render() {
const params = getParams();
if (params.fixture) {
renderFixture(params);
} else if (params.snapshot) {
renderSnapshot();
} else {
renderWithEngine();
}
}
window.addEventListener('load', render);