-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
398 lines (307 loc) · 11.6 KB
/
index.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Visual System</title>
<!-- External libs -->
<script src="lib/jquery-2.0.3.min.js"></script>
<script src="lib/paper.js"></script>
<script src="lib/jquery.mousewheel.js"></script>
<script src="lib/moment.min.js"></script>
<!-- App -->
<script>
$(function() {
});
function guid(){
// Credits: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
</script>
<script type="text/paperscript" canvas="papercanvas">
/* Helper function */
var scene = new Path.Rectangle(view.bounds);
scene.fillColor = 'white';
scene.onMouseDrag = function(event) {
contexts.position += event.delta;
links.position += event.delta;
parts.position += event.delta;
};
/* Links tool */
function ConnectionAttempt(from){
var connectionAttempt = links.children['connectionAttempt'];
if(connectionAttempt) { connectionAttempt.remove(); }
var connectionAttempt = new Path.Line(from.position, from.position);
connectionAttempt.name = 'connectionAttempt';
connectionAttempt.strokeColor = 'black';
connectionAttempt.strokeWidth = 1;
connectionAttempt.strokeCap = 'round';
connectionAttempt.dashArray = [4,2];
connectionAttempt.from = from;
links.addChild(connectionAttempt);
}
function Connection(output, input){
var connectionAttempt = output.parent.children['connectionAttempt'];
if (connectionAttempt) { connectionAttempt.remove(); }
var from = output.parent;
var to = input.parent;
var linkId = from.guid + '+' + to.guid;
if (links.children[linkId]){
console.log('link already exists');
} else {
var link = new Path.Line(output.position, input.position);
link.name = linkId;
link.from = from;
link.to = to;
link.strokeColor = 'black';
link.strokeWidth = 1;
link.strokeCap = 'round';
links.addChild(link);
console.log('Added link: ' + link.name);
}
}
function moveMyLinks(group){
for (var l in links.children){
var link = links.children[l];
var from = link.from;
var to = link.to;
if(from.guid == group.guid){
link.segments[0].point = group.children['output'].position;
}
if(to.guid == group.guid){
link.segments[1].point = group.children['input'].position;
}
}
}
/* Intermediate objects */
function Input(position){
var input = new Path.Circle(position, 10);
// Unique ID's within group
input.name = 'input';
input.concept = 'input';
return input;
}
function Output(position){
var output = new Path.Circle(position, 10);
// Unique ID's within group
output.concept = 'output';
output.name = 'output';
return output;
}
/* Objects on canvas */
function Context(point){
var group = new Group();
var size = new Size(80,50);
var rectangle = new Rectangle(point - size / 2, size);
var p = new Path.Rectangle(rectangle);
group.addChild(p);
var corner = new Path();
corner.strokeColor = 'black';
var point = rectangle.point + rectangle.size;
corner.add(point);
corner.add(point + new Point(0,-20));
corner.add(point + new Point(-20,0));
corner.closed = true;
corner.name = 'corner';
corner.onMouseDrag = function(event) {
this.position += event.delta;
this.parent.firstChild.bounds.bottomRight += event.delta;
};
group.addChild(corner);
group.fillColor = new Color(0.99);
group.strokeColor = new Color(0.2);
group.concept = 'context';
group.guid = guid();
group.onMouseDrag = function(event) { group.position += event.delta; };
contexts.addChild(group);
return group;
}
function Trigger(point){
var group = new Group();
var body = new Path.Circle(point, 30);
var output = new Output(point + new Point(30,0));
output.onMouseDrag = function(event) { new ConnectionAttempt(this); }
group.addChild(body);
group.addChild(output);
group.fillColor = 'white';
group.strokeColor = 'gray';
group.concept = 'trigger';
group.guid = guid();
group.onMouseDrag = function(event) {
group.bringToFront();
group.position += event.delta;
moveMyLinks(group);
};
parts.addChild(group);
return group;
}
function Processor(point){
var group = new Group();
var size = new Size(60,60);
var body = new Path.Rectangle(point - size / 2, size);
var input = new Input(point + new Point(-30,0));
var output = new Output(point + new Point(+30,0));
output.onMouseDrag = function(event) { new ConnectionAttempt(this); }
input.onMouseDrag = function(event) { new ConnectionAttempt(this); }
group.addChild(body);
group.addChild(input);
group.addChild(output);
group.fillColor = 'white';
group.strokeColor = 'gray';
group.concept = 'processor';
group.guid = guid();
group.onMouseDrag = function(event) {
group.bringToFront();
group.position += event.delta;
moveMyLinks(group);
};
parts.addChild(group);
return group;
}
function Exporter(point){
var group = new Group();
var size = new Size(60,60);
var body = new Path.Rectangle(point - size / 2, size)
var input = new Input(point + new Point(-30,0));
input.onMouseDrag = function(event) { new ConnectionAttempt(this); }
group.addChild(body);
group.addChild(input);
group.fillColor = 'white';
group.strokeColor = 'gray';
group.concept = 'exporter';
group.guid = guid();
group.onMouseDrag = function(event) {
group.bringToFront();
group.position += event.delta;
moveMyLinks(group);
};
parts.addChild(group);
return group;
}
function Operator(point){
var group = new Group();
var v1 = point + new Point(-30,30);
var v2 = point;
var v3 = point + new Point( 30,30);
var body = new Path.Arc(v1, v2, v3);
body.closed = true;
var head = new Path.Circle(point + new Point(0,-25),20);
var input = new Input(point + new Point(-30,20));
var output = new Output(point + new Point(+30,20));
output.onMouseDrag = function(event) { new ConnectionAttempt(this); }
input.onMouseDrag = function(event) { new ConnectionAttempt(this); }
group.addChild(body);
group.addChild(input);
group.addChild(output);
group.addChild(head);
group.fillColor = 'white';
group.strokeColor = 'gray';
group.concept = 'operator';
group.guid = guid();
group.onMouseDrag = function(event) {
group.bringToFront();
group.position += event.delta;
moveMyLinks(group);
};
parts.addChild(group);
return group;
}
/* Mouse Handlers */
function onMouseDrag(event){
var connectionAttempt = links.children['connectionAttempt'];
if(connectionAttempt){
//var start = connectionAttempt.segments[0].point;
connectionAttempt.segments[1].point = event.point;
}
}
function onMouseDown(event){
}
function onMouseUp(event){
// Connecting parts...
var connectionAttempt = links.children['connectionAttempt'];
if(connectionAttempt){
var hit = parts.hitTest(event.point);
if(hit){
var from = connectionAttempt.from;
var to = hit.item;
if(from.concept == 'output' && to.concept == 'input' ){ new Connection(from, to); }
if(from.concept == 'input' && to.concept == 'output'){ new Connection(to, from); }
}
connectionAttempt.remove();
}
}
$('#papercanvas').mousewheel(function(event, delta) {
var x = event.clientX;
var y = event.clientY;
var factor = 1 + (delta / 10);
var sign = factor > 0 ? 1 : -1;
//mercator.zoom(factor, x * sign, y * sign);
console.log(delta>0?"Zoom in!":"Zoom out!")
return false;
});
/* PaperJS Settings */
function onFrame(event) {
}
/* My App */
var contexts = new Group();
var links = new Group();
var parts = new Group();
var hud = new Group();
var bar = new Path.Rectangle(new Point(30,30), new Size(120, 440));
bar.fillColor = 'white';
bar.strokeColor = 'black';
bar.dashArray = [4,2];
//bar.opacity = 0.2;
hud.addChild(bar);
var trigger = new Trigger (new Point(90, 80));
trigger.children['output'].onMouseDrag = null;
trigger.onMouseDrag = function(event) { this.position = event.point; }
trigger.onMouseUp = function(event) { parts.addChild(new Trigger(event.point)); this.position = new Point(90, 80); };
var processor = new Processor(new Point(90,160));
processor.children['input'].onMouseDrag = null;
processor.children['output'].onMouseDrag = null;
processor.onMouseDrag = function(event) { this.position = event.point; }
processor.onMouseUp = function(event) { parts.addChild(new Processor(event.point)); this.position = new Point(90, 160); };
var exporter = new Exporter (new Point(90,240));
exporter.children['input'].onMouseDrag = null;
exporter.onMouseDrag = function(event) { this.position = event.point; }
exporter.onMouseUp = function(event) { parts.addChild(new Exporter(event.point)); this.position = new Point(90, 240); };
var operator = new Operator (new Point(90,340));
operator.children['input'].onMouseDrag = null;
operator.children['output'].onMouseDrag = null;
operator.onMouseDrag = function(event) { this.position = event.point; }
operator.onMouseUp = function(event) { parts.addChild(new Operator(event.point)); this.position = new Point(90, 340); };
var context = new Context (new Point(90,420));
context.children['corner'].onMouseDrag = null;
context.onMouseDrag = function(event) { this.position = event.point; }
context.onMouseUp = function(event) { contexts.addChild(new Context(event.point)); this.position = new Point(90, 420); };
hud.addChild(context);
hud.addChild(trigger);
hud.addChild(processor);
hud.addChild(exporter);
hud.addChild(operator);
hud.dashArray = [4,2];
hud.opacity = 0.1;
hud.onMouseEnter = function(event){ hud.opacity = 1.0; }
hud.onMouseLeave = function(event){ hud.opacity = 0.1; }
/*
M O D U L E S:
Triggers: Click
Processors: Download
Exporters: Show (text)
Operators: Check (check input and send to output if OK)
*/
</script>
</head>
<body style='margin: 0; overflow: hidden;'>
<div id="popup" style="display: none; position: absolute;">
<div id="name">name</div>
<div id="volume">volume</div>
<div id="meter">meter</div>
<div id="tags">tags</div>
</div>
<canvas id="papercanvas" resize></canvas>
</body>
</html>