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 | 1
5
5
5
5
1
1
361
361
361
361
361
361
361
361
1
100
1
3
6
1
2
1
2
1
1
1
1
1
2
2
1
1
1
1
1
1
1
31
31
1
26
26
1
26
1
26
1
1
1
1
44
44
44
44
44
44
44
124
44
80
80
1
1
1
1
1
4
4
4
1
3
3
3
3
1
1
1
1
309
309
1
1
1
1
1
1
211
211
211
1
1
1
1
1
1
94
94
94
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
3
3
3
1
1
1
1
1
186
186
186
186
1
558
1
318
1
5
1
1
1
1
341
341
341
341
341
1
147
147
93
54
147
1
147
1
147
1
39
1
38
38
41
38
1
41
41
41
41
41
1
146
146
146
146
146
203
203
203
1
146
146
1
192
192
192
192
128
128
192
128
128
128
128
192
192
99
99
99
192
1
1
| var __extends = this.__extends || function (d, b) {
for (var p in b) Eif (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Graph = (function () {
function Graph(components, connections, firstMainComponent, counter) {
Eif (typeof components === "undefined") { components = []; }
Eif (typeof connections === "undefined") { connections = []; }
Eif (typeof firstMainComponent === "undefined") { firstMainComponent = null; }
Eif (typeof counter === "undefined") { counter = 0; }
this.components = components;
this.connections = connections;
this.firstMainComponent = firstMainComponent;
this.counter = counter;
}
/**
transforms to JSON, JSON.stringify() will
call this function if it exists
*/
Graph.prototype.toJSON = function () {
return {
components: this.components,
connections: this.connections
};
};
/**
in graph
*/
Graph.prototype.containsComponent = function (component) {
for (var i = 0, _ref = this.components, length = _ref.length; i < length; ++i) {
if (_ref[i] == component) {
return true;
}
}
return false;
};
/**
removes the component of the graph and returns the connections related to it
*/
Graph.prototype.removeComponent = function (component) {
if (this.containsComponent(component)) {
Eif (component == this.firstMainComponent) {
this.firstMainComponent = null;
}
var returnlist = [];
var filteredlist = [];
for (var i = 0, _ref = this.connections, length = _ref.length; i < length; ++i) {
var connection = _ref[i];
if (connection.startComponent == component || connection.endComponent == component) {
returnlist.push(connection);
} else {
filteredlist.push(connection);
}
}
this.components.splice(this.components.indexOf(component), 1);
this.connections = filteredlist;
return returnlist;
}
return null;
};
Graph.prototype.connect = function (startComponent, outputPort, endComponent, inputPort) {
var connection = new Connection(startComponent, outputPort, endComponent, inputPort);
this.connections.push(connection);
};
/*
expands with other graph
*/
Graph.prototype.expand = function (other) {
this.concatComponents(other.components);
this.concatConnections(other.connections);
//if(this.counter){
// other.components.forEach(component => {
// component.id = this.counter++;
// });
//}
};
Graph.prototype.concatComponents = function (components) {
this.components = this.components.concat(components);
};
Graph.prototype.concatConnections = function (connections) {
this.connections = this.connections.concat(connections);
};
return Graph;
})();
exports.Graph = Graph;
var IndexedGraph = (function () {
function IndexedGraph(graph) {
this.components = {};
this.inputConnections = {};
this.outputConnections = {};
var components = this.components;
var outputConnections = this.outputConnections;
var inputConnections = this.inputConnections;
graph.components.forEach(function (component) {
components[component.id] = component;
});
graph.connections.forEach(function (connection) {
outputConnections[connection.startNode] = connection;
inputConnections[connection.endNode] = connection;
});
}
return IndexedGraph;
})();
exports.IndexedGraph = IndexedGraph;
var Macro = (function (_super) {
__extends(Macro, _super);
function Macro(name, description) {
_super.call(this);
this.name = name;
this.description = description;
}
Macro.fromGraph = function (name, description, graphData) {
var newmacro = new Macro(name, description);
newmacro.components = graphData.components;
newmacro.connections = graphData.connections;
return newmacro;
};
return Macro;
})(Graph);
exports.Macro = Macro;
//============= COMPONENTS ===========
var Component = (function () {
function Component() {
this.position = { x: 0, y: 0 };
this.id = 0;
}
Component.type = "abrstract component";
return Component;
})();
exports.Component = Component;
/**
A command component
*/
var CommandComponent = (function (_super) {
__extends(CommandComponent, _super);
function CommandComponent() {
_super.apply(this, arguments);
this.type = CommandComponent.type;
this.exec = null;
}
CommandComponent.type = "command";
return CommandComponent;
})(Component);
exports.CommandComponent = CommandComponent;
/**
A file component
*/
var FileComponent = (function (_super) {
__extends(FileComponent, _super);
function FileComponent(filename) {
_super.call(this);
this.type = FileComponent.type;
this.filename = filename;
}
FileComponent.type = "file";
return FileComponent;
})(Component);
exports.FileComponent = FileComponent;
/**
A macro Component
*/
var GraphComponent = (function (_super) {
__extends(GraphComponent, _super);
function GraphComponent(name, description) {
_super.call(this);
this.name = name;
this.description = description;
this.type = GraphComponent.type;
this.entryComponent = null;
this.exitComponent = null;
this.counter = 0;
this.components = [];
this.connections = [];
}
GraphComponent.prototype.setGraphData = function (graphData) {
this.components = graphData.components;
this.connections = graphData.connections;
this.entryComponent = graphData.firstMainComponent;
};
GraphComponent.type = "graph";
return GraphComponent;
})(Component);
exports.GraphComponent = GraphComponent;
/**
A macro Component
*/
var MacroComponent = (function (_super) {
__extends(MacroComponent, _super);
function MacroComponent(macro) {
_super.call(this);
this.macro = macro;
this.type = MacroComponent.type;
}
MacroComponent.type = "macro";
return MacroComponent;
})(Component);
exports.MacroComponent = MacroComponent;
//======== ==========
var Connection = (function () {
function Connection(startComponent, startPort, endComponent, endPort) {
this.startComponent = startComponent;
this.startPort = startPort;
this.endComponent = endComponent;
this.endPort = endPort;
}
Object.defineProperty(Connection.prototype, "startNode", {
get: function () {
return this.startComponent.id;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Connection.prototype, "endNode", {
get: function () {
return this.endComponent.id;
},
enumerable: true,
configurable: true
});
Connection.prototype.toJSON = function () {
return {
startNode: this.startNode,
startPort: this.startPort,
endNode: this.endComponent.id,
endPort: this.endPort
};
};
return Connection;
})();
exports.Connection = Connection;
//======== ==========
var Boundary = (function () {
function Boundary(left, rigth, top, bottom, components) {
this.left = left;
this.rigth = rigth;
this.top = top;
this.bottom = bottom;
this.components = components;
}
Boundary.createFromXY = function (x, y, component) {
var bottom;
if (component.type === "file") {
bottom = y + 100;
} else {
bottom = y + 350;
}
return new this(x, x, y, bottom, [component]);
};
Boundary.createFromPoint = function (point, component) {
return this.createFromXY(point.x, point.y, component);
};
Boundary.createFromComponent = function (component) {
return this.createFromPoint(component.position, component);
};
Boundary.createFromComponents = function (components) {
if (components.length === 0) {
return null;
}
var boundary = this.createFromComponent(components[0]);
for (var i = 1, len = components.length; i < len; ++i) {
boundary.extend(this.createFromComponent(components[i]));
}
return boundary;
};
Boundary.prototype.extend = function (boundary2) {
this.left = Math.min(boundary2.left, this.left);
this.rigth = Math.max(boundary2.rigth, this.rigth);
this.top = Math.min(boundary2.top, this.top);
this.bottom = Math.max(boundary2.bottom, this.bottom);
this.components = this.components.concat(boundary2.components);
};
Boundary.translate = function (boundary, x, y) {
boundary.left += x;
boundary.rigth += x;
boundary.top += y;
boundary.bottom += y;
boundary.components.forEach(function (component) {
var position = component.position;
position.x += x;
position.y += y;
});
};
Boundary.prototype.translateXY = function (x, y) {
if (typeof y === "undefined") { y = 0; }
Boundary.translate(this, x, y);
};
/**
arranges the layout
*/
Boundary.arrangeLayout = function (boundaries) {
var maxX = 0;
var prevBound = null;
var components = [];
boundaries.forEach(function (boundary) {
maxX = Math.max(boundary.rigth, maxX);
components = components.concat(boundary.components);
});
boundaries.forEach(function (boundary) {
var translateX = maxX - boundary.rigth;
var translateY = prevBound ? prevBound.bottom - boundary.top : 0;
boundary.translateXY(translateX, translateY);
prevBound = boundary;
});
var x = 0, y = 0, bottom = 350;
if (boundaries.length) {
x = maxX + 350;
y = Math.max((prevBound.bottom - 350) / 2, 0);
bottom = Math.max(prevBound.bottom, 350);
}
return [new Boundary(0, x, 0, bottom, components), { x: x, y: y }];
};
return Boundary;
})();
exports.Boundary = Boundary;
|