Commit 60a9cee5 authored by Fintan Mc Gee's avatar Fintan Mc Gee

FIxed prjectin of organisations and locations ( and hopefullt projection in general)

parent c0b042d0
......@@ -2879,11 +2879,18 @@ var MultiLayerGraph = function (nodes, links, layerName) {
* Date: 04/12/2018
*/
g.projectNodesInLayer = function(targetLayerName,masterProjectionNodeTypes, masterProjectionEdgeTypes, projectionEdgeType) {
if(g.name != "MasterLayer") {
console.log("Error:projectNodesInLayer was called on layer other than master");
return;
}
var targetLayer = g.getLayerByName(targetLayerName);
if(!targetLayer) {
return;
}
// determining whetre we are using refrencd or Ids for edge source and target
var useIdsForEdgeEndpoints = false;
if(typeof(g.links[0].source) !== "object") {
......@@ -2894,6 +2901,20 @@ var MultiLayerGraph = function (nodes, links, layerName) {
}
var projectionMap = {};
function projectionEdgesfilter(currentEdge) {
if(currentEdge.hasOwnProperty("type")) {
if(currentEdge.type === projectionEdgeType) {
return false;
}
}
return true;
}
// assumeing that we are replacing all exsitng edges of this type in target lyer so removing them form node set
targetLayer.links = targetLayer.links.filter(projectionEdgesfilter);
g.links = g.links.filter(projectionEdgesfilter);
targetLayer.nodes.forEach(function(n) {
var nodeID = n.uid;
......@@ -2908,8 +2929,9 @@ var MultiLayerGraph = function (nodes, links, layerName) {
}
// node is of the correct type
if(!masterProjectionEdgeTypes) {
if(projectionMap[neighbour.uid].indexOf(n.uid) < 0) {
projectionMap[neighbour.uid].push(n.uid);
}
} else{
// TODO handle case where edge resticitons are define
......@@ -2923,6 +2945,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
var linkId = targetLayer.links.length;
var newLinkWeightMap = {};
var newLinksArray = [];
for(var nodeId in projectionMap){
var nodeList = projectionMap[nodeId];
// need to create edges between all nodes in list
......@@ -2942,27 +2965,42 @@ var MultiLayerGraph = function (nodes, links, layerName) {
} else {
return;
}
var newID = sourceID + "_"+ targetID;
var newID = sourceID + "_" + targetID;
if(!newLinkWeightMap.hasOwnProperty(newID)) {
newLinkWeightMap[newID] = 1;
var newLink = {uid: newID,
source:useIdsForEdgeEndpoints?sourceID:targetLayer.node[sourceID],
target:useIdsForEdgeEndpoints?targetID:targetLayer.node[targetID],
type:projectionEdgeType,
projectionNodeType : g.node[nodeId].type,
projectionNodeIds : [nodeId],
projected:true,
weight:newLinkWeightMap[newID]++};
targetLayer.links.push(newLink);
// add to master copy to target
newLinksArray.push(newLink);
//targetLayer.links.push(newLink);
} else {
var currentContext = this;
var existingLink = targetLayer.links.find(function(current){
//var existingLink = targetLayer.links.find(function(current){
var existingLink = newLinksArray.find(function(current){
// console.log("Checking for " + newID + " against edge id" + current.uid + " " );
return current.uid === newID;
})
if(existingLink) {
existingLink.weight = newLinkWeightMap[newID]++;
if(existingLink.projectionNodeIds.indexOf(nodeId) < 0) {
// proejct can go bothe ways so want to cound a-> b and b -> a as euqivalient
// so every node in projection node ID list should be unique
existingLink.weight = newLinkWeightMap[newID]++;
existingLink.projectionNodeIds.push(nodeId);
}
}
}
// change its source/target to the new ones
......@@ -2971,8 +3009,19 @@ var MultiLayerGraph = function (nodes, links, layerName) {
});
}
newLinksArray.forEach(function(nLink){
// nee to add to master grpah and then copy it to child
if(!g.link[nLink.uid]) {
g.links.push(nLink);
targetLayer.copyEdgeToLayer(nLink);
//targetLayer.links.push(nLink);
}
});
g.buildLinkLookUp();
g.buildAdjacencyList();
targetLayer.buildNodeLookUp();
targetLayer.buildLinkLookUp();
targetLayer.buildAdjacencyList();
}
/** copyNodeAttributesToAllLayers
*
......
......@@ -535,10 +535,10 @@ angular.module('blizaarModule.services')
var layerNames = multiLayerGraphService.getLayerNames();
this.updateDHTemporalData();
multiLayerGraphService.getGraph().projectNodesInLayer("locations",["resource"],null,"proj_edge" );
multiLayerGraphService.getGraph().projectNodesInLayer("organizations",["resource"],null,"proj_edge" );
dataService.updateLayerOnServer("projectNodesInLayer","locations",["resource"],null,null,null,"proj_edge" );
dataService.updateLayerOnServer("projectNodesInLayer","organizations",["resource"],null,null,null,"proj_edge" )
multiLayerGraphService.getGraph().projectNodesInLayer("locations",["resource"],null,"proj_edge_resource" );
multiLayerGraphService.getGraph().projectNodesInLayer("organizations",["resource"],null,"proj_edge_resource" );
dataService.updateLayerOnServer("projectNodesInLayer","locations",["resource"],null,null,null,"proj_edge_resource" );
dataService.updateLayerOnServer("projectNodesInLayer","organizations",["resource"],null,null,null,"proj_edge_resource" )
// storing layer types as an entitiy
if(multiLayerGraphService.getGraph().aspects.hasOwnProperty("EntityType")) {
......
......@@ -2901,11 +2901,18 @@ var MultiLayerGraph = function (nodes, links, layerName) {
* Date: 04/12/2018
*/
g.projectNodesInLayer = function(targetLayerName,masterProjectionNodeTypes, masterProjectionEdgeTypes, projectionEdgeType) {
if(g.name != "MasterLayer") {
console.log("Error:projectNodesInLayer was called on layer other than master");
return;
}
var targetLayer = g.getLayerByName(targetLayerName);
if(!targetLayer) {
return;
}
// determining whetre we are using refrencd or Ids for edge source and target
var useIdsForEdgeEndpoints = false;
if(typeof(g.links[0].source) !== "object") {
......@@ -2916,6 +2923,20 @@ var MultiLayerGraph = function (nodes, links, layerName) {
}
var projectionMap = {};
function projectionEdgesfilter(currentEdge) {
if(currentEdge.hasOwnProperty("type")) {
if(currentEdge.type === projectionEdgeType) {
return false;
}
}
return true;
}
// assumeing that we are replacing all exsitng edges of this type in target lyer so removing them form node set
targetLayer.links = targetLayer.links.filter(projectionEdgesfilter);
g.links = g.links.filter(projectionEdgesfilter);
targetLayer.nodes.forEach(function(n) {
var nodeID = n.uid;
......@@ -2930,8 +2951,9 @@ var MultiLayerGraph = function (nodes, links, layerName) {
}
// node is of the correct type
if(!masterProjectionEdgeTypes) {
if(projectionMap[neighbour.uid].indexOf(n.uid) < 0) {
projectionMap[neighbour.uid].push(n.uid);
}
} else{
// TODO handle case where edge resticitons are define
......@@ -2945,6 +2967,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
var linkId = targetLayer.links.length;
var newLinkWeightMap = {};
var newLinksArray = [];
for(var nodeId in projectionMap){
var nodeList = projectionMap[nodeId];
// need to create edges between all nodes in list
......@@ -2964,27 +2987,42 @@ var MultiLayerGraph = function (nodes, links, layerName) {
} else {
return;
}
var newID = sourceID + "_"+ targetID;
var newID = sourceID + "_" + targetID;
if(!newLinkWeightMap.hasOwnProperty(newID)) {
newLinkWeightMap[newID] = 1;
var newLink = {uid: newID,
source:useIdsForEdgeEndpoints?sourceID:targetLayer.node[sourceID],
target:useIdsForEdgeEndpoints?targetID:targetLayer.node[targetID],
type:projectionEdgeType,
projectionNodeType : g.node[nodeId].type,
projectionNodeIds : [nodeId],
projected:true,
weight:newLinkWeightMap[newID]++};
targetLayer.links.push(newLink);
// add to master copy to target
newLinksArray.push(newLink);
//targetLayer.links.push(newLink);
} else {
var currentContext = this;
var existingLink = targetLayer.links.find(function(current){
//var existingLink = targetLayer.links.find(function(current){
var existingLink = newLinksArray.find(function(current){
// console.log("Checking for " + newID + " against edge id" + current.uid + " " );
return current.uid === newID;
})
if(existingLink) {
existingLink.weight = newLinkWeightMap[newID]++;
if(existingLink.projectionNodeIds.indexOf(nodeId) < 0) {
// proejct can go bothe ways so want to cound a-> b and b -> a as euqivalient
// so every node in projection node ID list should be unique
existingLink.weight = newLinkWeightMap[newID]++;
existingLink.projectionNodeIds.push(nodeId);
}
}
}
// change its source/target to the new ones
......@@ -2993,8 +3031,19 @@ var MultiLayerGraph = function (nodes, links, layerName) {
});
}
newLinksArray.forEach(function(nLink){
// nee to add to master grpah and then copy it to child
if(!g.link[nLink.uid]) {
g.links.push(nLink);
targetLayer.copyEdgeToLayer(nLink);
//targetLayer.links.push(nLink);
}
});
g.buildLinkLookUp();
g.buildAdjacencyList();
targetLayer.buildNodeLookUp();
targetLayer.buildLinkLookUp();
targetLayer.buildAdjacencyList();
}
/** copyNodeAttributesToAllLayers
*
......
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