forked from flowhub/the-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo-full.html
254 lines (229 loc) · 9.19 KB
/
demo-full.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html>
<head>
<title>Graph Editor</title>
<meta charset="utf-8">
<!-- Libraries -->
<script src="../node_modules/webcomponents.js/webcomponents.js"></script>
<script src="../node_modules/react/dist/react.js"></script>
<script src="../node_modules/react-dom/dist/react-dom.js"></script>
<script src="../node_modules/klayjs-noflo/klay-noflo.js"></script>
<script src="../node_modules/hammerjs/hammer.min.js"></script>
<script src="../bower_components/ease-djdeath/index.js"></script>
<script src="../bower_components/react.animate-djdeath/react.animate.js"></script>
<!-- Browserify Libraries -->
<script src="../dist/the-graph.js"></script>
<!-- Custom elements -->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../the-graph-editor/the-graph-editor.html">
<link rel="import" href="../the-graph-nav/the-graph-nav.html">
<!-- Fonts -->
<link rel="stylesheet" href="../node_modules/font-awesome/css/font-awesome.min.css">
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:400' rel='stylesheet' type='text/css'>
<style>
@font-face {
/* we want the svg version */
font-family: 'FontAwesomeSVG';
src: url('../node_modules/font-awesome/fonts/fontawesome-webfont.svg?v=4.0.3#fontawesomeregular') format('svg'),
url('../node_modules/font-awesome/fonts/fontawesome-webfont.eot?#iefix&v=4.0.3') format('embedded-opentype'),
url('../node_modules/font-awesome/fonts/fontawesome-webfont.woff?v=4.0.3') format('woff'),
url('../node_modules/font-awesome/fonts/fontawesome-webfont.ttf?v=4.0.3') format('truetype');
font-weight: normal;
font-style: normal;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
<style>
html, body {
width: 100%;
height: 100%;
}
body {
background-color: hsl(189, 47%, 6%);
font-family: "SourceCodePro",Helvetica,Arial,sans-serif;
overflow: hidden;
}
#editor {
background-color: transparent;
position: absolute;
top: 0;
left: 0;
}
#nav {
position: absolute;
right: 0px;
bottom: 0px;
}
#testing {
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<the-graph-editor id="editor"
width="800" height="600"
grid="72"
snap="36"
theme="dark">
</the-graph-editor>
<the-graph-nav id="nav" width="216" height="162"></the-graph-nav>
<div id="testing">
<button id="autolayout">autolayout</button>
<button id="theme">theme</button>
<button id="focus">focus</button>
<button id="refresh">refresh</button>
</div>
<div id="loading" style="position:absolute; top:10px; left:10px; background-color:white; padding:10px; border-radius:5px;">
<img src="assets/loading.gif"/>
<div id="loading-message">loading custom elements...</div>
</div>
<script type="text/javascript">
Polymer.veiledElements = ["the-graph-editor"];
window.addEventListener('polymer-ready', function() {
"use strict";
// Remove loading message
var loadingMessage = document.getElementById("loading-message");
loadingMessage.innerHTML = "loading graph data...";
window.loadGraph = function (json) {
// Remove loading message
var loading = document.getElementById("loading");
loading.parentNode.removeChild(loading);
// Load graph
var editor = document.getElementById('editor');
var graph = json.data ? JSON.parse(json.data.files['noflo.json'].content) : json;
var graphString = JSON.stringify(graph);
editor.graph = graph;
// Attach nav
var nav = document.getElementById('nav');
editor.addEventListener('viewchanged', function(e) {
nav.view = e.detail;
});
nav.addEventListener('panto', function(e) {
var pan = e.detail;
editor.pan[0] = pan.x;
editor.pan[1] = pan.y;
});
nav.addEventListener('tap', function() {
editor.triggerFit();
});
editor.addEventListener('graphInitialised', function() {
// FIXME: editor should not init fbpGraph, but be passed in a ready instance
nav.graph = editor.fbpGraph;
});
// Simulate a library update
setTimeout(function () {
var originalComponent = editor.getComponent('core/Split');
if (!originalComponent) {
console.warn("Didn't find component. Something is amiss.");
return;
}
var component = JSON.parse(JSON.stringify(originalComponent));
component.icon = 'github';
component.inports.push({
name: 'supercalifragilisticexpialidocious',
type: 'boolean'
});
component.outports.push({
name: 'boo',
type: 'boolean'
});
editor.registerComponent(component);
}, 1000);
// Simulate node icon updates
var iconKeys = Object.keys(TheGraph.FONT_AWESOME);
window.setInterval(function () {
if (!editor.fbpGraph) { return; }
var nodes = editor.fbpGraph.nodes;
if (nodes.length>0) {
var randomNodeId = nodes[Math.floor(Math.random()*nodes.length)].id;
var randomIcon = iconKeys[Math.floor(Math.random()*iconKeys.length)];
editor.updateIcon(randomNodeId, randomIcon);
}
}, 1000);
// Simulate un/triggering wire animations
var animatingEdge1 = null;
var animatingEdge2 = null;
window.setInterval(function () {
if (!editor.fbpGraph) { return; }
if (animatingEdge2) {
editor.unanimateEdge(animatingEdge2);
}
if (animatingEdge1) {
animatingEdge2 = animatingEdge1;
}
var edges = editor.fbpGraph.edges;
if (edges.length>0) {
animatingEdge1 = edges[Math.floor(Math.random()*edges.length)];
editor.animateEdge(animatingEdge1);
}
}, 2014);
// Simulate un/triggering errors
var errorNodeId = null;
var makeRandomError = function () {
if (!editor.fbpGraph) { return; }
if (errorNodeId) {
editor.removeErrorNode(errorNodeId);
}
var nodes = editor.fbpGraph.nodes;
if (nodes.length>0) {
errorNodeId = nodes[Math.floor(Math.random()*nodes.length)].id;
editor.addErrorNode(errorNodeId);
editor.updateErrorNodes();
}
};
window.setInterval(makeRandomError, 3551);
makeRandomError();
// Autolayout button
document.getElementById("autolayout").addEventListener("click", function () {
editor.triggerAutolayout();
});
// Toggle theme
var theme = "dark";
document.getElementById("theme").addEventListener("click", function () {
theme = (theme==="dark" ? "light" : "dark");
editor.theme = theme;
nav.theme = theme;
});
// Focus a node
document.getElementById("focus").addEventListener("click", function () {
var nodes = editor.fbpGraph.nodes;
var randomNode = nodes[Math.floor(Math.random()*nodes.length)];
editor.focusNode(randomNode);
});
// Refresh graph
document.getElementById("refresh").addEventListener("click", function () {
if (!editor.fbpGraph) { return; }
editor.graph = JSON.parse(graphString);
});
// Log some stuff
window.editor = editor;
console.log(editor);
};
var body = document.querySelector('body');
var script = document.createElement('script');
script.type = 'application/javascript';
// Clock
// script.src = 'https://api.github.com/gists/7135158?callback=loadGraph';
// script.src = 'clock.json.js';
script.src = 'assets/photobooth.json.js';
// Gesture object building (lots of ports!)
// script.src = 'https://api.github.com/gists/7022120?callback=loadGraph';
// Gesture data gathering (big graph)
// script.src = 'https://api.github.com/gists/7022262?callback=loadGraph';
// Edge algo test
//script.src = 'https://api.github.com/gists/6890344?callback=loadGraph';
body.appendChild(script);
// Resize to fill window and also have explicit w/h attributes
var editor = document.getElementById("editor");
var resize = function () {
editor.setAttribute("width", window.innerWidth);
editor.setAttribute("height", window.innerHeight);
};
window.addEventListener("resize", resize);
resize();
});
</script>
</body>
</html>