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) { ...@@ -282,7 +282,11 @@ var MultiLayerGraph = function (nodes, links, layerName) {
if(!g.adjacencyList ) { if(!g.adjacencyList ) {
g.buildAdjacencyList(); 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) { ...@@ -1743,9 +1747,6 @@ var MultiLayerGraph = function (nodes, links, layerName) {
targetLayer.buildAdjacencyList(); targetLayer.buildAdjacencyList();
targetLayer.buildEdgeList(); targetLayer.buildEdgeList();
if (existingEdgeCount > -1) { if (existingEdgeCount > -1) {
console.log("ExisitingEdges:" + existingEdgeCount + " New Edges:" + (filteredEdges.length - existingEdgeCount)); console.log("ExisitingEdges:" + existingEdgeCount + " New Edges:" + (filteredEdges.length - existingEdgeCount));
} }
...@@ -1828,6 +1829,12 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -1828,6 +1829,12 @@ var MultiLayerGraph = function (nodes, links, layerName) {
console.log("Error:addLayerNodesAndLinksByUid was called on layer other than master"); console.log("Error:addLayerNodesAndLinksByUid was called on layer other than master");
return; return;
} }
if(!g.node) {
g.buildNodeLookUp();
}
if(!g.link) {
g.buildLinkLookUp();
}
var targetLayer = g.getLayerByName(targetLayerName); var targetLayer = g.getLayerByName(targetLayerName);
if (targetLayer) { if (targetLayer) {
...@@ -2960,6 +2967,13 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -2960,6 +2967,13 @@ var MultiLayerGraph = function (nodes, links, layerName) {
layerNames = [layerNames]; layerNames = [layerNames];
} }
var usingReferences = false;
if(g.aspects["Master"].length) {
if (typeof(g.aspects["Master"][0]) === "object") {
usingReferences = true;
}
}
layerNames.forEach(function(layerName) { layerNames.forEach(function(layerName) {
var l = g.getLayerByName(layerName) var l = g.getLayerByName(layerName)
...@@ -2968,7 +2982,10 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -2968,7 +2982,10 @@ var MultiLayerGraph = function (nodes, links, layerName) {
// if (typeof(g.aspects["Master"][0]) === "object") { // if (typeof(g.aspects["Master"][0]) === "object") {
// check to make sure the layer is not alread in the aspect // check to make sure the layer is not alread in the aspect
if (!g.aspects[aspectName].find( function (layer) { 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); g.aspects[aspectName].push(l);
console.log("Added layer " + layerName + " to aspect " + aspectName) console.log("Added layer " + layerName + " to aspect " + aspectName)
...@@ -2994,7 +3011,7 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -2994,7 +3011,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
console.log("Error:removeLayersFromAspect was called for an unrecognised aspect"); console.log("Error:removeLayersFromAspect was called for an unrecognised aspect");
return; return;
} }
if (g.name != "MasterLayer") { if (g.name !== "MasterLayer") {
console.log("Error:removeLayersFromAspect was called on layer other than master"); console.log("Error:removeLayersFromAspect was called on layer other than master");
return; return;
} }
...@@ -3116,13 +3133,18 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -3116,13 +3133,18 @@ var MultiLayerGraph = function (nodes, links, layerName) {
for (var aspectName in g.aspects) { for (var aspectName in g.aspects) {
aspectsByRef[aspectName] = []; aspectsByRef[aspectName] = [];
g.aspects[aspectName].forEach (function(layerName){ g.aspects[aspectName].forEach (function(layerName){
var layerRef = g.layers.find(function(layer) { var layerRef = null;
if(layer.name === layerName) { if((typeof(layerName) === "string")) {
return true; layerRef = g.layers.find(function (layer) {
} if (layer.name === layerName) {
return false; return true;
}); }
aspectsByRef[aspectName].push(layerRef); return false;
});
aspectsByRef[aspectName].push(layerRef);
} else {
layerRef = layerName; // aspects were already references
}
}); });
} }
g.aspects["Master"] = g.layers ; g.aspects["Master"] = g.layers ;
...@@ -3140,13 +3162,22 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -3140,13 +3162,22 @@ var MultiLayerGraph = function (nodes, links, layerName) {
for (var aspectName in g.aspects) { for (var aspectName in g.aspects) {
aspectsByName[aspectName] = []; aspectsByName[aspectName] = [];
g.aspects[aspectName].forEach (function(layer){ 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 = aspectsByName;
g.aspects["Master"] = []; g.aspects["Master"] = [];
g.layers.forEach(function(layer) { 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) { ...@@ -3199,7 +3230,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
usingReferences = false; usingReferences = false;
} }
} }
return isUsingReferences return isUsingReferences;
} }
// returns true if the specified property should be found on the layer itslef // returns true if the specified property should be found on the layer itslef
...@@ -3398,7 +3429,45 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -3398,7 +3429,45 @@ var MultiLayerGraph = function (nodes, links, layerName) {
return jsonVersion; 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; return g;
......
...@@ -557,7 +557,6 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -557,7 +557,6 @@ var MultiLayerGraph = function (nodes, links, layerName) {
********************************/ ********************************/
g.mergeGraphData = function(newNodes, newLinks) { g.mergeGraphData = function(newNodes, newLinks) {
var diff = {nodes:[],links:[]}; var diff = {nodes:[],links:[]};
g.buildNodeLookUp(); g.buildNodeLookUp();
g.buildLinkLookUp(); g.buildLinkLookUp();
...@@ -1420,7 +1419,7 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -1420,7 +1419,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
}); });
} }
if(!foundLayer) { if(!foundLayer) {
console.log("getLayerByName could not find the specified layer" + layerName ); // console.log("getLayerByName could not find the specified layer" + layerName );
} }
return foundLayer; return foundLayer;
}; };
...@@ -1770,9 +1769,9 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -1770,9 +1769,9 @@ var MultiLayerGraph = function (nodes, links, layerName) {
targetLayer.buildAdjacencyList(); targetLayer.buildAdjacencyList();
targetLayer.buildEdgeList(); targetLayer.buildEdgeList();
// if (existingEdgeCount > -1) { if (existingEdgeCount > -1) {
// console.log("ExisitingEdges:" + existingEdgeCount + " New Edges:" + (filteredEdges.length - existingEdgeCount)); console.log("ExisitingEdges:" + existingEdgeCount + " New Edges:" + (filteredEdges.length - existingEdgeCount));
// } }
} }
return targetLayer; return targetLayer;
...@@ -3034,7 +3033,7 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -3034,7 +3033,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
console.log("Error:removeLayersFromAspect was called for an unrecognised aspect"); console.log("Error:removeLayersFromAspect was called for an unrecognised aspect");
return; return;
} }
if (g.name != "MasterLayer") { if (g.name !== "MasterLayer") {
console.log("Error:removeLayersFromAspect was called on layer other than master"); console.log("Error:removeLayersFromAspect was called on layer other than master");
return; return;
} }
...@@ -3220,7 +3219,7 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -3220,7 +3219,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
g.mapLinkEndsToNodeReferences(); g.mapLinkEndsToNodeReferences();
//map aspects to aspect names //map aspects to aspect names
g.mapAspectsToLayerNames(); g.mapAspectsToLayerReferences();
} }
...@@ -3361,12 +3360,12 @@ var MultiLayerGraph = function (nodes, links, layerName) { ...@@ -3361,12 +3360,12 @@ var MultiLayerGraph = function (nodes, links, layerName) {
g.buildNodeLookUp(); g.buildNodeLookUp();
g.buildLinkLookUp(); g.buildLinkLookUp();
if(g.name === "MasterLayer") { 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() * 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 * @param a JSON object containing the asapects names of keys, and and array of layer names for each aspect
* Created By : Fintan McGee (LIST) * 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