Revize 4a133d5e
Přidáno uživatelem Pavel Fidranský před asi 6 roky(ů)
sources/src/main/webapp/js/app.js | ||
---|---|---|
28 | 28 |
this.HOME_URL = null; |
29 | 29 |
/** @prop {object} API Application programming interface paths. */ |
30 | 30 |
this.API = { |
31 |
loadGraph: 'api/graph-data', |
|
32 |
loadDiagram: 'api/diagram', |
|
31 |
loadGraphData: 'api/load-graph-data', |
|
33 | 32 |
}; |
34 | 33 |
|
35 | 34 |
/** @prop {float} headerHeight Current height of the application header. */ |
... | ... | |
62 | 61 |
/** |
63 | 62 |
* Loads graph using diagram (if available). |
64 | 63 |
* @param diagramId Diagram identifier. |
65 |
* @param diagramHash Diagram hash. |
|
66 | 64 |
*/ |
67 |
this.diagramLoader = function(diagramId, diagramHash) {
|
|
68 |
return loadGraphData.bind(this, diagramId, diagramHash);
|
|
65 |
this.diagramLoader = function(diagramId) { |
|
66 |
return loadGraphData.bind(this, diagramId); |
|
69 | 67 |
}; |
70 | 68 |
|
71 | 69 |
/** |
... | ... | |
288 | 286 |
/** |
289 | 287 |
* Loads graph data of a diagram. |
290 | 288 |
* @param {string} diagramId Identifier of the diagram to be loaded. |
291 |
* @param {string} diagramHash Hash of the diagram to be loaded. |
|
292 | 289 |
*/ |
293 |
function loadGraphData(diagramId, diagramHash) {
|
|
290 |
function loadGraphData(diagramId) { |
|
294 | 291 |
var self = this; |
295 | 292 |
|
296 | 293 |
self.loader.enable(); |
297 | 294 |
|
298 |
var loadGraphURL = self.API.loadGraph; |
|
299 |
var loadDiagramURL = self.API.loadDiagram; |
|
295 |
var loadGraphDataURL = self.API.loadGraphData; |
|
300 | 296 |
|
301 | 297 |
if (diagramId !== 'null') { |
302 |
loadGraphURL += '?diagramId=' + diagramId; |
|
303 |
loadDiagramURL += '?diagramId=' + diagramId; |
|
298 |
loadGraphDataURL += '?diagramId=' + diagramId; |
|
304 | 299 |
} |
305 | 300 |
|
306 |
if (diagramHash !== 'null') { |
|
307 |
loadGraphURL += '&diagramHash=' + diagramHash; |
|
308 |
loadDiagramURL += '&diagramHash=' + diagramHash; |
|
309 |
} |
|
310 |
|
|
311 |
// exported data of graph |
|
312 |
var graphExportData = null; |
|
313 |
|
|
314 | 301 |
// get vertex position data |
315 |
$.getJSON(loadDiagramURL).then(function(data) { |
|
316 |
graphExportData = JSON.parse(data.vertices_position); |
|
317 |
|
|
318 |
// get graph data |
|
319 |
return $.getJSON(loadGraphURL); |
|
320 |
|
|
321 |
}, function() { |
|
322 |
// get graph data |
|
323 |
return $.getJSON(loadGraphURL); |
|
324 |
|
|
325 |
}).then(function(data) { |
|
302 |
$.getJSON(loadGraphDataURL).then(function(data) { |
|
326 | 303 |
// construct graph |
327 |
self.graphLoader.run(data, graphExportData);
|
|
304 |
self.graphLoader.run(data); |
|
328 | 305 |
|
329 | 306 |
self.loader.disable(); |
330 | 307 |
|
sources/src/main/webapp/js/graphLoader.js | ||
---|---|---|
6 | 6 |
/** |
7 | 7 |
* Loads a new graph using graph data passed as parameters. |
8 | 8 |
* @param {object} data Data of the graph. |
9 |
* @param {object} graphExportData Export of a previously loaded diagram. |
|
10 |
* @throws {InvalidArgumentException} Thrown when either graph data or export data are incomplete. |
|
9 |
* @throws {InvalidArgumentException} Thrown when either graph data are incomplete. |
|
11 | 10 |
*/ |
12 |
this.run = function(data, graphExportData) {
|
|
11 |
this.run = function(data) { |
|
13 | 12 |
if (app.utils.isUndefined(data.vertices) || app.utils.isUndefined(data.edges)) { |
14 | 13 |
throw new InvalidArgumentException('Invalid data.'); |
15 | 14 |
} |
16 | 15 |
|
17 |
if (graphExportData !== null && (app.utils.isUndefined(data.vertices) || app.utils.isUndefined(data.edges))) { |
|
18 |
throw new InvalidArgumentException('Invalid graph export data.'); |
|
19 |
} |
|
20 |
|
|
21 | 16 |
var canvasSize = ((data.vertices.length * 75) / Math.round(Math.sqrt(data.vertices.length))) + 1000; |
22 | 17 |
|
23 | 18 |
app.attributeTypeList = data.attributeTypes; |
... | ... | |
32 | 27 |
data.vertices.forEach(function(component) { |
33 | 28 |
var vertex = new Vertex(component); |
34 | 29 |
|
35 |
var isPositionSet = false; |
|
36 |
if (graphExportData !== null) { |
|
37 |
var exportedVertex = graphExportData.vertices.find(function(exportedVertex) { |
|
38 |
return exportedVertex.name == this; |
|
39 |
}, vertex.name); |
|
40 |
|
|
41 |
// vertex is present in exported graph data |
|
42 |
if (app.utils.isDefined(exportedVertex)) { |
|
43 |
var coords = new Coordinates(exportedVertex.position.x, exportedVertex.position.y); |
|
44 |
vertex.setPosition(coords); |
|
45 |
|
|
46 |
isPositionSet = true; |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
if (isPositionSet === false) { |
|
51 |
vertex.setPosition(new Coordinates( |
|
52 |
Math.floor(Math.random() * canvasSize), |
|
53 |
Math.floor(Math.random() * canvasSize), |
|
54 |
)); |
|
55 |
} |
|
30 |
vertex.setPosition(new Coordinates( |
|
31 |
Math.floor(Math.random() * canvasSize), |
|
32 |
Math.floor(Math.random() * canvasSize), |
|
33 |
)); |
|
56 | 34 |
|
57 | 35 |
app.nodeList.push(vertex); |
58 | 36 |
app.vertexList.push(vertex); |
Také k dispozici: Unified diff
modified frontend to load graph data using only diagramId (no diagramHash)