-
Notifications
You must be signed in to change notification settings - Fork 179
/
render.jsjob.js
39 lines (33 loc) · 985 Bytes
/
render.jsjob.js
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
// JsJob entrypoint for rendering a FBP graph to an SVG/JPEG/PNG
const TheGraph = require('./index');
require('./themes/the-graph-dark.styl');
require('./themes/the-graph-light.styl');
function waitForStyleLoad(callback) {
// FIXME: check properly, https://gist.github.com/cvan/8a188df72a95a35888b70e5fda80450d
setTimeout(callback, 500);
}
window.jsJobRun = function jsJobRun(inputdata, options, callback) {
let loader = TheGraph.fbpGraph.graph.loadJSON;
let graphData = inputdata;
if (inputdata.fbp) {
graphData = inputdata.fbp;
loader = TheGraph.fbpGraph.graph.loadFBP;
}
loader(graphData, (err, graph) => {
if (err) {
callback(err);
return;
}
console.log('loaded graph');
waitForStyleLoad(() => {
let node;
try {
node = TheGraph.render.graphToDOM(graph, options);
} catch (e) {
callback(e);
return;
}
TheGraph.render.exportImage(node, options, callback);
});
});
};