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