This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
noflo-graph.html
50 lines (49 loc) · 1.57 KB
/
noflo-graph.html
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
<element name="noflo-graph" attributes="src root">
<script>
var noflo = require('/bergie-noflo');
var loadGraph = function (oldSrc) {
var element = this;
var src = element.getAttribute('src');
var request = new XMLHttpRequest();
request.open('GET', src, true);
request.onload = function () {
if (request.readyState != 4 || request.status != 200) {
return;
}
runGraph(JSON.parse(request.responseText), element);
};
request.send();
};
var runGraph = function (graphData, element) {
noflo.graph.loadJSON(graphData, function (graph) {
graph.baseDir = element.getAttribute('root');
registerInitials(graph, element);
noflo.createNetwork(graph, function (network) {
console.log("Network created");
});
});
};
var registerInitials = function (graph, element) {
for (var i=0; i < element.attributes.length; i++) {
if (element.attributes[i].name.indexOf('-') === -1) {
continue;
}
registerInitial(graph, element.attributes[i].name, element.attributes[i].value);
}
};
var registerInitial = function (graph, name, value) {
var parts = name.split('-');
// Match to a node in graph
for (var i=0; i < graph.nodes.length; i++) {
var node = graph.nodes[i];
if (node.id.toLowerCase() == parts[0]) {
graph.addInitial(value, node.id, parts[1]);
}
}
};
Polymer.register(this, {
src: '',
srcChanged: loadGraph
});
</script>
</element>