Commit 5e247363 authored by Fintan Mc Gee's avatar Fintan Mc Gee

aligned multiLayerGraph.js and graph.js

parent afbdc535
......@@ -282,7 +282,11 @@ var MultiLayerGraph = function (nodes, links, layerName) {
if(!g.adjacencyList ) {
g.buildAdjacencyList();
}
return g.adjacencyList[inputNode.uid];
if(!g.adjacencyList.hasOwnProperty(inputNode.id)) {
console.log("ERROR getNeighbours could not find node in adjacently List " + JSON.stringify(inputNode));
return [];
}
return g.adjacencyList[inputNode.id];
};
/**************************************
......@@ -1743,9 +1747,6 @@ var MultiLayerGraph = function (nodes, links, layerName) {
targetLayer.buildAdjacencyList();
targetLayer.buildEdgeList();
if (existingEdgeCount > -1) {
console.log("ExisitingEdges:" + existingEdgeCount + " New Edges:" + (filteredEdges.length - existingEdgeCount));
}
......@@ -1828,6 +1829,12 @@ var MultiLayerGraph = function (nodes, links, layerName) {
console.log("Error:addLayerNodesAndLinksByUid was called on layer other than master");
return;
}
if(!g.node) {
g.buildNodeLookUp();
}
if(!g.link) {
g.buildLinkLookUp();
}
var targetLayer = g.getLayerByName(targetLayerName);
if (targetLayer) {
......@@ -2960,6 +2967,13 @@ var MultiLayerGraph = function (nodes, links, layerName) {
layerNames = [layerNames];
}
var usingReferences = false;
if(g.aspects["Master"].length) {
if (typeof(g.aspects["Master"][0]) === "object") {
usingReferences = true;
}
}
layerNames.forEach(function(layerName) {
var l = g.getLayerByName(layerName)
......@@ -2968,7 +2982,10 @@ var MultiLayerGraph = function (nodes, links, layerName) {
// if (typeof(g.aspects["Master"][0]) === "object") {
// check to make sure the layer is not alread in the aspect
if (!g.aspects[aspectName].find( function (layer) {
return layerName === layer.name;
if(!usingReferences) {
return layerName === layer;
}
return layerName === layer.name;
}) ){
g.aspects[aspectName].push(l);
console.log("Added layer " + layerName + " to aspect " + aspectName)
......@@ -2994,7 +3011,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
console.log("Error:removeLayersFromAspect was called for an unrecognised aspect");
return;
}
if (g.name != "MasterLayer") {
if (g.name !== "MasterLayer") {
console.log("Error:removeLayersFromAspect was called on layer other than master");
return;
}
......@@ -3116,13 +3133,18 @@ var MultiLayerGraph = function (nodes, links, layerName) {
for (var aspectName in g.aspects) {
aspectsByRef[aspectName] = [];
g.aspects[aspectName].forEach (function(layerName){
var layerRef = g.layers.find(function(layer) {
if(layer.name === layerName) {
return true;
}
return false;
});
aspectsByRef[aspectName].push(layerRef);
var layerRef = null;
if((typeof(layerName) === "string")) {
layerRef = g.layers.find(function (layer) {
if (layer.name === layerName) {
return true;
}
return false;
});
aspectsByRef[aspectName].push(layerRef);
} else {
layerRef = layerName; // aspects were already references
}
});
}
g.aspects["Master"] = g.layers ;
......@@ -3140,13 +3162,22 @@ var MultiLayerGraph = function (nodes, links, layerName) {
for (var aspectName in g.aspects) {
aspectsByName[aspectName] = [];
g.aspects[aspectName].forEach (function(layer){
aspectsByName[aspectName].push(layer.name);
if((typeof(layer) === "string")) {
// in case layer names are already being used
aspectsByName[aspectName].push(layer);
} else {
aspectsByName[aspectName].push(layer.name);
}
});
}
g.aspects = aspectsByName;
g.aspects["Master"] = [];
g.layers.forEach(function(layer) {
g.aspects["Master"].push(layer.name);
if((typeof(layer) === "string")) {
g.aspects["Master"].push(layer);
} else {
g.aspects["Master"].push(layer.name);
}
});
}
......@@ -3199,7 +3230,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
usingReferences = false;
}
}
return isUsingReferences
return isUsingReferences;
}
// returns true if the specified property should be found on the layer itslef
......@@ -3398,7 +3429,45 @@ var MultiLayerGraph = function (nodes, links, layerName) {
return jsonVersion;
}
};
g.getSerialisableVersion = function() {
var sVersion = {};
sVersion.nodes = g.nodes;
sVersion.links = g.links;
sVersion.name = g.name
sVersion.master = "MasterLayer"
sVersion.layers = [];
g.layers.forEach(function(layer){
sVersion.layers.push(layer.getSerialisableVersion());
});
var aspectsByName = {};
for (var aspectName in g.aspects) {
aspectsByName[aspectName] = [];
g.aspects[aspectName].forEach (function(layer){
if((typeof(layer) === "string")) {
aspectsByName[aspectName].push(layer);
} else {
aspectsByName[aspectName].push(layer.name);
}
});
}
sVersion.aspects = aspectsByName;
sVersion.aspects["Master"] = [];
g.layers.forEach(function(layer) {
sVersion.aspects["Master"].push(layer.name);
});
return sVersion;
};
return g;
......
......@@ -557,7 +557,6 @@ var MultiLayerGraph = function (nodes, links, layerName) {
********************************/
g.mergeGraphData = function(newNodes, newLinks) {
var diff = {nodes:[],links:[]};
g.buildNodeLookUp();
g.buildLinkLookUp();
......@@ -1420,7 +1419,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
});
}
if(!foundLayer) {
console.log("getLayerByName could not find the specified layer" + layerName );
// console.log("getLayerByName could not find the specified layer" + layerName );
}
return foundLayer;
};
......@@ -1770,9 +1769,9 @@ var MultiLayerGraph = function (nodes, links, layerName) {
targetLayer.buildAdjacencyList();
targetLayer.buildEdgeList();
// if (existingEdgeCount > -1) {
// console.log("ExisitingEdges:" + existingEdgeCount + " New Edges:" + (filteredEdges.length - existingEdgeCount));
// }
if (existingEdgeCount > -1) {
console.log("ExisitingEdges:" + existingEdgeCount + " New Edges:" + (filteredEdges.length - existingEdgeCount));
}
}
return targetLayer;
......@@ -3034,7 +3033,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
console.log("Error:removeLayersFromAspect was called for an unrecognised aspect");
return;
}
if (g.name != "MasterLayer") {
if (g.name !== "MasterLayer") {
console.log("Error:removeLayersFromAspect was called on layer other than master");
return;
}
......@@ -3220,7 +3219,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
g.mapLinkEndsToNodeReferences();
//map aspects to aspect names
g.mapAspectsToLayerNames();
g.mapAspectsToLayerReferences();
}
......@@ -3361,12 +3360,12 @@ var MultiLayerGraph = function (nodes, links, layerName) {
g.buildNodeLookUp();
g.buildLinkLookUp();
if(g.name === "MasterLayer") {
g.mapAspectsToLayerNames(); // default as used by the server, overwrritter when rtpepare graph is caleld at froit end
g.mapAspectsToLayerNames(); // default as used by the server, overwrritter when rtpepare graph is called at front end
}
/**************************************
* initAspects()
* Functionality: Initaliseres the aspece with the refercens to the input aspectaspect objects
* Functionality: Initalise the aspects with the refercens to the input aspectaspect objects
*
* @param a JSON object containing the asapects names of keys, and and array of layer names for each aspect
* Created By : Fintan McGee (LIST)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment