1 |
1e2b2c27
|
Tomáš Šimandl
|
/**
|
2 |
|
|
* Main class of the application.
|
3 |
|
|
*/
|
4 |
|
|
function App() {
|
5 |
|
|
this.loader = new Loader;
|
6 |
|
|
|
7 |
|
|
this.HOME_URL = null;
|
8 |
|
|
|
9 |
|
|
this.api = {
|
10 |
|
|
loadGraph: 'LoadGraphData',
|
11 |
|
|
loadDiagram: 'LoadDiagram',
|
12 |
|
|
};
|
13 |
|
|
|
14 |
|
|
/**
|
15 |
|
|
* Loads graph using diagram (if available).
|
16 |
|
|
* @param diagramId Diagram identifier.
|
17 |
|
|
* @param diagramHash Diagram hash.
|
18 |
|
|
*/
|
19 |
|
|
this.diagramLoader = function(diagramId, diagramHash) {
|
20 |
|
|
return function() {
|
21 |
|
|
loadGraphData(diagramId, diagramHash, null, null);
|
22 |
|
|
};
|
23 |
|
|
};
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* Loads graph using EFP data.
|
27 |
|
|
* @param withEfps Is EFPs in graph?
|
28 |
|
|
* @param efpSettings EFP settings.
|
29 |
|
|
*/
|
30 |
|
|
this.efpLoader = function(withEfps, efpSettings) {
|
31 |
|
|
return function() {
|
32 |
|
|
loadGraphData(null, null, withEfps, efpSettings);
|
33 |
|
|
};
|
34 |
|
|
};
|
35 |
|
|
|
36 |
|
|
this.run = function(startFn) {
|
37 |
|
|
console.log('running...');
|
38 |
|
|
|
39 |
|
|
bootstrap();
|
40 |
|
|
startFn();
|
41 |
|
|
};
|
42 |
|
|
|
43 |
|
|
function bootstrap() {
|
44 |
|
|
GraphManager.init();
|
45 |
|
|
ViewportManager.init();
|
46 |
|
|
OffScreenKiv.init();
|
47 |
|
|
|
48 |
|
|
// when user changes window size then set height and width #viewport and #rightPanel
|
49 |
|
|
$(window).bind('resize', setHeight);
|
50 |
|
|
|
51 |
|
|
setHeight();
|
52 |
|
|
|
53 |
|
|
// zoom
|
54 |
|
|
$('#zoomIn').click(function() {
|
55 |
|
|
ViewportManager.zoom.zoomIn();
|
56 |
|
|
});
|
57 |
|
|
|
58 |
|
|
$('#zoomOut').click(function() {
|
59 |
|
|
ViewportManager.zoom.zoomOut();
|
60 |
|
|
});
|
61 |
|
|
|
62 |
|
|
// viewport mode
|
63 |
|
|
$("input[name='actionMove']").change(function() {
|
64 |
|
|
var action = $("input[name='actionMove']:checked").val();
|
65 |
|
|
var vertex;
|
66 |
|
|
|
67 |
|
|
if (action == 'move') {
|
68 |
|
|
for (var i = 0; i < GraphManager.graph.vertices.length; i++) {
|
69 |
|
|
// remove context menu
|
70 |
|
|
ViewportManager.removeContextMenu('#vertex'+ (i+1));
|
71 |
|
|
|
72 |
|
|
vertex = GraphManager.graph.vertices[i];
|
73 |
|
|
vertex.$selector.unbind('mousedown', OffScreenKiv.showVertexInRightPanel);
|
74 |
|
|
vertex.$selector.mousedown(ViewportManager.vertexMousedownHandler);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
} else if (action == 'exclude') {
|
78 |
|
|
for (var j = 0; j < GraphManager.graph.vertices.length; j++) {
|
79 |
|
|
vertex = GraphManager.graph.vertices[j];
|
80 |
|
|
vertex.$selector.unbind('mousedown', ViewportManager.vertexMousedownHandler);
|
81 |
|
|
vertex.$selector.mousedown(OffScreenKiv.showVertexInRightPanel);
|
82 |
|
|
|
83 |
|
|
// add context menu
|
84 |
|
|
ViewportManager.addContextMenu('#vertex'+ (j+1));
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
});
|
88 |
|
|
|
89 |
|
|
// search
|
90 |
|
|
$("#search").click(OffScreenKiv.search);
|
91 |
|
|
$("#searchText").focusin(function() {
|
92 |
|
|
if ($(this).val() == 'Search components...') {
|
93 |
|
|
$(this).val('');
|
94 |
|
|
}
|
95 |
|
|
});
|
96 |
|
|
|
97 |
|
|
$("#countOfFinded").click(OffScreenKiv.deselectHighlightSearchedVertices);
|
98 |
|
|
$("#mostEdge").click(OffScreenKiv.excludeVerticesWithMostEdges);
|
99 |
|
|
$("#vertexToGroup").click(OffScreenKiv.excludeVerticesWithMostEdgesToGroup);
|
100 |
|
|
$('#applyLayout').click(GraphManager.forceDirectedLayoutOnClick);
|
101 |
|
|
|
102 |
|
|
$('.sort-button').click(OffScreenKiv.sortComponents);
|
103 |
|
|
$('#includeAllComponents').click(OffScreenKiv.includeAllComponents);
|
104 |
|
|
|
105 |
|
|
initSearchOnEnterPressed();
|
106 |
|
|
initZoomKeys();
|
107 |
|
|
initViewportMove();
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
function loadGraphData(diagram_id, diagram_hash, with_efps, efp_settings) {
|
111 |
|
|
app.loader.enable();
|
112 |
|
|
|
113 |
|
|
var load_url = app.api.loadGraph;
|
114 |
|
|
var load_diagram_url = app.api.loadDiagram;
|
115 |
|
|
|
116 |
|
|
if (diagram_id !== null) {
|
117 |
|
|
load_url += "?diagram_id=" + diagram_id;
|
118 |
|
|
load_diagram_url += "?diagram_id=" + diagram_id;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
if (diagram_hash !== null) {
|
122 |
|
|
load_url += "&diagram_hash=" + diagram_hash;
|
123 |
|
|
load_diagram_url += "&diagram_hash=" + diagram_hash;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
if (with_efps !== null) {
|
127 |
|
|
/* Build graph with EFPs */
|
128 |
|
|
GraphManager.isEfpGraph = true;
|
129 |
|
|
|
130 |
|
|
// set EFP settings
|
131 |
|
|
GraphManager.efpMinIntDiameter = efp_settings.minInterfaceDiameter;
|
132 |
|
|
GraphManager.efpMaxIntDiameter = efp_settings.maxInterfaceDiameter;
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
// gets vertex position data
|
136 |
|
|
$.getJSON(load_diagram_url, function(data) {
|
137 |
|
|
GraphManager.vertices_position = data;
|
138 |
|
|
});
|
139 |
|
|
|
140 |
|
|
// build the graph
|
141 |
|
|
$.getJSON(load_url, function(data) {
|
142 |
|
|
GraphManager.graph = data;
|
143 |
|
|
|
144 |
|
|
GraphManager.buildGraph();
|
145 |
|
|
ViewportManager.revive();
|
146 |
|
|
});
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
/**
|
150 |
|
|
* Set height of viewport and right panel.
|
151 |
|
|
*/
|
152 |
|
|
function setHeight() {
|
153 |
|
|
var headerHeight = $('#header').height() + $('#navigation').height() + 5; /* magic 5, dunno where it comes from */
|
154 |
|
|
var contentHeight = $(window).height() - headerHeight;
|
155 |
|
|
|
156 |
|
|
$('#viewport').height(contentHeight);
|
157 |
|
|
$('#rightPanel').height(contentHeight - 40); /* 40px is the sidebar-navbar */
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
/**
|
161 |
|
|
* Set Enter as accelerator for the searching box
|
162 |
|
|
*/
|
163 |
|
|
function initSearchOnEnterPressed() {
|
164 |
|
|
$("#searchText").keydown(function(event) {
|
165 |
|
|
// react on Enter key pressed
|
166 |
|
|
if (event.which === 13) {
|
167 |
|
|
OffScreenKiv.search();
|
168 |
|
|
}
|
169 |
|
|
});
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
/**
|
173 |
|
|
* Initialize zoom keys.
|
174 |
|
|
*/
|
175 |
|
|
function initZoomKeys() {
|
176 |
|
|
var scrollViewportOnZoom = function(e) {
|
177 |
|
|
e = e ? e : window.event;
|
178 |
|
|
var raw = e.detail ? e.detail : e.deltaY;
|
179 |
|
|
|
180 |
|
|
if (event.ctrlKey === true) {
|
181 |
|
|
e.preventDefault();
|
182 |
|
|
|
183 |
|
|
if (raw > 0){
|
184 |
|
|
ViewportManager.zoom.zoomOut();
|
185 |
|
|
}
|
186 |
|
|
if (raw < 0){
|
187 |
|
|
ViewportManager.zoom.zoomIn();
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
};
|
191 |
|
|
|
192 |
|
|
$(window).keydown(function(event) {
|
193 |
|
|
if (event.ctrlKey === false) return;
|
194 |
|
|
|
195 |
|
|
$('#zoom_help').show();
|
196 |
|
|
|
197 |
|
|
// key code 107 is the plus sign
|
198 |
|
|
if (event.which === 107) {
|
199 |
|
|
event.preventDefault();
|
200 |
|
|
|
201 |
|
|
ViewportManager.zoom.zoomIn();
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
// key code 109 is the plus sign
|
205 |
|
|
if (event.which === 109) {
|
206 |
|
|
event.preventDefault();
|
207 |
|
|
|
208 |
|
|
ViewportManager.zoom.zoomOut();
|
209 |
|
|
}
|
210 |
|
|
});
|
211 |
|
|
|
212 |
|
|
$(window).keyup(function(event) {
|
213 |
|
|
if (event.ctrlKey === false) {
|
214 |
|
|
$('#zoom_help').hide();
|
215 |
|
|
}
|
216 |
|
|
});
|
217 |
|
|
|
218 |
|
|
document.getElementById('envelope').addEventListener('wheel', scrollViewportOnZoom);
|
219 |
|
|
document.getElementById('zoom_help').addEventListener('wheel', scrollViewportOnZoom);
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
/**
|
223 |
|
|
* Initialization of moving with viewport
|
224 |
|
|
*/
|
225 |
|
|
function initViewportMove() {
|
226 |
|
|
var viewport = $('#viewport'),
|
227 |
|
|
viewportX, viewportY,
|
228 |
|
|
startX, startY;
|
229 |
|
|
|
230 |
|
|
var bindMove = function(e) {
|
231 |
|
|
if (e.button === 0) {
|
232 |
|
|
document.getElementById('envelope').addEventListener('mousemove', move);
|
233 |
|
|
|
234 |
|
|
viewportX = viewport.scrollLeft();
|
235 |
|
|
viewportY = viewport.scrollTop();
|
236 |
|
|
|
237 |
|
|
startX = e.screenX;
|
238 |
|
|
startY = e.screenY;
|
239 |
|
|
}
|
240 |
|
|
};
|
241 |
|
|
|
242 |
|
|
var unbindMove = function(e) {
|
243 |
|
|
document.getElementById('envelope').removeEventListener('mousemove', move);
|
244 |
|
|
};
|
245 |
|
|
|
246 |
|
|
var move = function(e) {
|
247 |
|
|
e.preventDefault();
|
248 |
|
|
e.stopPropagation();
|
249 |
|
|
|
250 |
|
|
viewport.scrollLeft(viewportX + startX - e.screenX);
|
251 |
|
|
viewport.scrollTop(viewportY + startY - e.screenY);
|
252 |
|
|
};
|
253 |
|
|
|
254 |
|
|
document.getElementById('viewport').addEventListener('mousedown', bindMove);
|
255 |
|
|
document.getElementById('envelope').addEventListener('mouseup', unbindMove);
|
256 |
|
|
document.getElementById('envelope').addEventListener('mouseleave', unbindMove);
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
}
|