From ed1f6ed50800bde612e8d0e75bb68ca9c3ec3cc0 Mon Sep 17 00:00:00 2001 From: David Moreno Lumbreras Date: Sun, 6 Jan 2019 20:31:47 +0100 Subject: [PATCH] Refactor code --- public/network_vis_controller.js | 484 +++++++++++++++---------------- 1 file changed, 242 insertions(+), 242 deletions(-) diff --git a/public/network_vis_controller.js b/public/network_vis_controller.js index e338700..e8fc110 100644 --- a/public/network_vis_controller.js +++ b/public/network_vis_controller.js @@ -15,51 +15,51 @@ const ResizeSensor = require('css-element-queries/src/ResizeSensor'); module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, Private) { var network_id, loading_id; - $scope.errorNodeColor = function(){ - $("#" + network_id).hide(); - $("#" + loading_id).hide(); - $("#errorHtml").html("

ERROR: Node Color must be the LAST selection

"); - $("#errorHtml").show(); + $scope.errorNodeColor = function () { + $("#" + network_id).hide(); + $("#" + loading_id).hide(); + $("#errorHtml").html("

ERROR: Node Color must be the LAST selection

"); + $("#errorHtml").show(); } - $scope.errorNodeNodeRelation = function(){ - $("#" + network_id).hide(); - $("#" + loading_id).hide(); - $("#errorHtml").html("

ERROR: You can only choose Node-Node or Node-Relation

"); - $("#errorHtml").show(); + $scope.errorNodeNodeRelation = function () { + $("#" + network_id).hide(); + $("#" + loading_id).hide(); + $("#errorHtml").html("

ERROR: You can only choose Node-Node or Node-Relation

"); + $("#errorHtml").show(); } - $scope.initialShows = function(){ - $("#" + network_id).show(); - $("#" + loading_id).show(); - $("#errorHtml").hide(); + $scope.initialShows = function () { + $("#" + network_id).show(); + $("#" + loading_id).show(); + $("#errorHtml").hide(); } - $scope.startDynamicResize = function(network){ - new ResizeSensor($("#" + network_id), function() { + $scope.startDynamicResize = function (network) { + new ResizeSensor($("#" + network_id), function () { network.setSize('100%', '100%'); }); } - $scope.drawColorLegend = function(usedColors, colorDicc){ + $scope.drawColorLegend = function (usedColors, colorDicc) { var canvas = document.getElementsByTagName("canvas")[0]; var context = canvas.getContext("2d"); - context.fillStyle="#FFE8D6"; + context.fillStyle = "#FFE8D6"; var totalheight = usedColors.length * 25 - context.fillRect(canvas.width*(-2)-10, canvas.height*(-2)-18, 350, totalheight); + context.fillRect(canvas.width * (-2) - 10, canvas.height * (-2) - 18, 350, totalheight); context.fillStyle = "black"; context.font = "bold 30px Arial"; context.textAlign = "start"; - context.fillText("LEGEND OF COLORS:", canvas.width*(-2), canvas.height*(-2)); + context.fillText("LEGEND OF COLORS:", canvas.width * (-2), canvas.height * (-2)); - var p=canvas.height*(-2) + 40; - for(var key in colorDicc){ + var p = canvas.height * (-2) + 40; + for (var key in colorDicc) { context.fillStyle = colorDicc[key]; context.font = "bold 20px Arial"; - context.fillText(key, canvas.width*(-2), p); - p = p +22; + context.fillText(key, canvas.width * (-2), p); + p = p + 22; } } @@ -68,19 +68,19 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P if (resp) { // new in 6.5 resp.columns.forEach((col) => { - if(col.aggConfig.schema.name === "first"){ - if(firstFirstBucketId){ + if (col.aggConfig.schema.name === "first") { + if (firstFirstBucketId) { firstSecondBucketId = col.id - }else{ + } else { firstFirstBucketId = col.id } - }else if(col.aggConfig.schema.name === "second"){ + } else if (col.aggConfig.schema.name === "second") { secondBucketId = col.id - }else if(col.aggConfig.schema.name === "colornode"){ + } else if (col.aggConfig.schema.name === "colornode") { colorBucketId = col.id - }else if(col.aggConfig.schema.name === "size_node"){ + } else if (col.aggConfig.schema.name === "size_node") { nodeSizeId = col.id - }else if(col.aggConfig.schema.name === "size_edge"){ + } else if (col.aggConfig.schema.name === "size_edge") { edgeSizeId = col.id } }); @@ -90,19 +90,19 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P network_id = "net_" + $scope.$id; loading_id = "loading_" + $scope.$parent.$id; $("#" + loading_id).hide(); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////NODE-NODE Type/////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - if($scope.vis.aggs.bySchemaName['first'].length >= 1 && !$scope.vis.aggs.bySchemaName['second']){ + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////NODE-NODE Type/////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if ($scope.vis.aggs.bySchemaName['first'].length >= 1 && !$scope.vis.aggs.bySchemaName['second']) { $scope.initialShows(); $(".secondNode").show(); // Retrieve the id of the configured tags aggregation var firstFieldAggId = $scope.vis.aggs.bySchemaName['first'][0].id; - if($scope.vis.aggs.bySchemaName['first'].length > 1){ + if ($scope.vis.aggs.bySchemaName['first'].length > 1) { var secondFieldAggId = $scope.vis.aggs.bySchemaName['first'][1].id; } - if($scope.vis.aggs.bySchemaName['colornode']){ + if ($scope.vis.aggs.bySchemaName['colornode']) { var colorNodeAggId = $scope.vis.aggs.bySchemaName['colornode'][0].id; var colorNodeAggName = $scope.vis.aggs.bySchemaName['colornode'][0].params.field.displayName; var colorDicc = {}; @@ -111,181 +111,181 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P //Names of the terms that have been selected var firstFieldAggName = $scope.vis.aggs.bySchemaName['first'][0].params.field.displayName; - if($scope.vis.aggs.bySchemaName['first'].length > 1){ + if ($scope.vis.aggs.bySchemaName['first'].length > 1) { var secondFieldAggName = $scope.vis.aggs.bySchemaName['first'][1].params.field.displayName; } // Retrieve the metrics aggregation configured - if($scope.vis.aggs.bySchemaName['size_node']){ + if ($scope.vis.aggs.bySchemaName['size_node']) { var metricsAgg_sizeNode = $scope.vis.aggs.bySchemaName['size_node'][0]; } - if($scope.vis.aggs.bySchemaName['size_edge']){ + if ($scope.vis.aggs.bySchemaName['size_edge']) { var metricsAgg_sizeEdge = $scope.vis.aggs.bySchemaName['size_edge'][0]; } // Get the buckets of that aggregation var buckets = resp.rows; - ///////////////////////////////////////////////////////////////DATA PARSED AND BUILDING NODES/////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////DATA PARSED AND BUILDING NODES/////////////////////////////////////////////////////////////// var dataParsed = []; // Iterate the buckets var i = 0; - var dataNodes = buckets.map(function(bucket) { + var dataNodes = buckets.map(function (bucket) { - var result = $.grep(dataParsed, function(e){ return e.keyFirstNode == bucket[firstFirstBucketId]; }); - if (result.length == 0) { - dataParsed[i] = {}; + var result = $.grep(dataParsed, function (e) { return e.keyFirstNode == bucket[firstFirstBucketId]; }); + if (result.length == 0) { + dataParsed[i] = {}; - dataParsed[i].keyFirstNode = bucket[firstFirstBucketId]; + dataParsed[i].keyFirstNode = bucket[firstFirstBucketId]; - //Metrics are for the sizes - if(metricsAgg_sizeNode){ - // Use the getValue function of the aggregation to get the value of a bucket - var value = bucket[nodeSizeId]//metricsAgg_sizeNode.getValue(bucket); - var sizeVal = Math.min($scope.vis.params.maxCutMetricSizeNode, value); + //Metrics are for the sizes + if (metricsAgg_sizeNode) { + // Use the getValue function of the aggregation to get the value of a bucket + var value = bucket[nodeSizeId]//metricsAgg_sizeNode.getValue(bucket); + var sizeVal = Math.min($scope.vis.params.maxCutMetricSizeNode, value); - //No show nodes under the value - if($scope.vis.params.minCutMetricSizeNode > value){ - dataParsed.splice(i, 1); - return; + //No show nodes under the value + if ($scope.vis.params.minCutMetricSizeNode > value) { + dataParsed.splice(i, 1); + return; + } + } else { + var sizeVal = 20; } - }else{ - var sizeVal = 20; - } - dataParsed[i].valorSizeNode = sizeVal; - dataParsed[i].nodeColorValue = "default"; - dataParsed[i].nodeColorKey = "default"; - if(!dataParsed[i].relationWithSecondNode){ - dataParsed[i].relationWithSecondNode = []; - } + dataParsed[i].valorSizeNode = sizeVal; + dataParsed[i].nodeColorValue = "default"; + dataParsed[i].nodeColorKey = "default"; + if (!dataParsed[i].relationWithSecondNode) { + dataParsed[i].relationWithSecondNode = []; + } - //Iterate rows and choose the edge size - if($scope.vis.aggs.bySchemaName['first'].length > 1){ - if(metricsAgg_sizeEdge){ - var value_sizeEdge = bucket[edgeSizeId]; - var sizeEdgeVal = Math.min($scope.vis.params.maxCutMetricSizeEdge, value_sizeEdge); - }else{ - var sizeEdgeVal = 0.1; - } + //Iterate rows and choose the edge size + if ($scope.vis.aggs.bySchemaName['first'].length > 1) { + if (metricsAgg_sizeEdge) { + var value_sizeEdge = bucket[edgeSizeId]; + var sizeEdgeVal = Math.min($scope.vis.params.maxCutMetricSizeEdge, value_sizeEdge); + } else { + var sizeEdgeVal = 0.1; + } - if(colorNodeAggId){ - if(colorDicc[bucket[colorBucketId]]){ - dataParsed[i].nodeColorKey = bucket[colorBucketId]; - dataParsed[i].nodeColorValue = colorDicc[bucket[colorBucketId]]; - }else{ - //repeat to find a NO-REPEATED color - while(true){ - var confirmColor = randomColor(); - if(usedColors.indexOf(confirmColor) == -1){ - colorDicc[bucket[colorBucketId]] = confirmColor; - dataParsed[i].nodeColorKey = bucket[colorBucketId]; - dataParsed[i].nodeColorValue = colorDicc[bucket[colorBucketId]]; - usedColors.push(confirmColor); - break; + if (colorNodeAggId) { + if (colorDicc[bucket[colorBucketId]]) { + dataParsed[i].nodeColorKey = bucket[colorBucketId]; + dataParsed[i].nodeColorValue = colorDicc[bucket[colorBucketId]]; + } else { + //repeat to find a NO-REPEATED color + while (true) { + var confirmColor = randomColor(); + if (usedColors.indexOf(confirmColor) == -1) { + colorDicc[bucket[colorBucketId]] = confirmColor; + dataParsed[i].nodeColorKey = bucket[colorBucketId]; + dataParsed[i].nodeColorValue = colorDicc[bucket[colorBucketId]]; + usedColors.push(confirmColor); + break; + } } + } + } + var relation = { + keySecondNode: bucket[firstSecondBucketId], + countMetric: bucket[nodeSizeId], + widthOfEdge: sizeEdgeVal } + dataParsed[i].relationWithSecondNode.push(relation) } - var relation = { - keySecondNode: bucket[firstSecondBucketId], - countMetric: bucket[nodeSizeId], - widthOfEdge: sizeEdgeVal + //assigning color and the content of the popup + var inPopup = "

" + bucket[firstFirstBucketId] + "

" + if (dataParsed[i].nodeColorValue != "default") { + var colorNodeFinal = dataParsed[i].nodeColorValue; + inPopup += "

" + dataParsed[i].nodeColorKey + "

"; + } else { + var colorNodeFinal = $scope.vis.params.firstNodeColor; } - dataParsed[i].relationWithSecondNode.push(relation) - } - - //assigning color and the content of the popup - var inPopup = "

" + bucket[firstFirstBucketId] + "

" - if(dataParsed[i].nodeColorValue != "default"){ - var colorNodeFinal = dataParsed[i].nodeColorValue; - inPopup += "

" + dataParsed[i].nodeColorKey + "

"; - }else{ - var colorNodeFinal = $scope.vis.params.firstNodeColor; - } - i++; - //Return the node totally built - var nodeReturn = { - id: i, - key: bucket[firstFirstBucketId], - color: colorNodeFinal, - shape: $scope.vis.params.shapeFirstNode, - //size: sizeVal - value: sizeVal, - font : { - color: $scope.vis.params.labelColor + i++; + //Return the node totally built + var nodeReturn = { + id: i, + key: bucket[firstFirstBucketId], + color: colorNodeFinal, + shape: $scope.vis.params.shapeFirstNode, + //size: sizeVal + value: sizeVal, + font: { + color: $scope.vis.params.labelColor + } } - } - //If activated, show the labels - if($scope.vis.params.showLabels){ - nodeReturn.label = bucket[firstFirstBucketId]; - } + //If activated, show the labels + if ($scope.vis.params.showLabels) { + nodeReturn.label = bucket[firstFirstBucketId]; + } - //If activated, show the popups - if($scope.vis.params.showPopup){ - nodeReturn.title = inPopup; - } + //If activated, show the popups + if ($scope.vis.params.showPopup) { + nodeReturn.title = inPopup; + } - return nodeReturn; + return nodeReturn; - } else if (result.length == 1) { - //Repetido el nodo, solo añadimos sus relaciones - var dataParsed_node_exist = result[0] - //Iterate rows and choose the edge size - if($scope.vis.aggs.bySchemaName['first'].length > 1){ - if(metricsAgg_sizeEdge){ - var value_sizeEdge = bucket[edgeSizeId]; - var sizeEdgeVal = Math.min($scope.vis.params.maxCutMetricSizeEdge, value_sizeEdge); - }else{ - var sizeEdgeVal = 0.1; - } + } else if (result.length == 1) { + //Repetido el nodo, solo añadimos sus relaciones + var dataParsed_node_exist = result[0] + //Iterate rows and choose the edge size + if ($scope.vis.aggs.bySchemaName['first'].length > 1) { + if (metricsAgg_sizeEdge) { + var value_sizeEdge = bucket[edgeSizeId]; + var sizeEdgeVal = Math.min($scope.vis.params.maxCutMetricSizeEdge, value_sizeEdge); + } else { + var sizeEdgeVal = 0.1; + } - var relation = { - keySecondNode: bucket[firstSecondBucketId], - countMetric: bucket[nodeSizeId], - widthOfEdge: sizeEdgeVal + var relation = { + keySecondNode: bucket[firstSecondBucketId], + countMetric: bucket[nodeSizeId], + widthOfEdge: sizeEdgeVal + } + dataParsed_node_exist.relationWithSecondNode.push(relation) } - dataParsed_node_exist.relationWithSecondNode.push(relation) + return undefined } - return undefined - } }); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////BUILDING EDGES/////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////BUILDING EDGES/////////////////////////////////////////////////////////////////////// //Clean "undefined" in the array dataNodes = dataNodes.filter(Boolean); var dataEdges = []; - for(var n = 0; n 1){ - for(var r = 0; r 1) { + for (var r = 0; r < dataParsed[n].relationWithSecondNode.length; r++) { //Find in the relations the second node to relate - var nodeOfSecondType = $.grep(dataNodes, function(e){ return e.key == dataParsed[n].relationWithSecondNode[r].keySecondNode; }); + var nodeOfSecondType = $.grep(dataNodes, function (e) { return e.key == dataParsed[n].relationWithSecondNode[r].keySecondNode; }); if (nodeOfSecondType.length == 0) { //Not found, added to the DataNodes - node of type 2 i++; var newNode = { - id : i, + id: i, key: dataParsed[n].relationWithSecondNode[r].keySecondNode, - label : dataParsed[n].relationWithSecondNode[r].keySecondNode, + label: dataParsed[n].relationWithSecondNode[r].keySecondNode, color: $scope.vis.params.secondNodeColor, - font : { - color: $scope.vis.params.labelColor + font: { + color: $scope.vis.params.labelColor }, shape: $scope.vis.params.shapeSecondNode }; @@ -293,8 +293,8 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P dataNodes.push(newNode); //And create the relation (edge) var edge = { - from : result[0].id, - to : dataNodes[dataNodes.length-1].id, + from: result[0].id, + to: dataNodes[dataNodes.length - 1].id, value: dataParsed[n].relationWithSecondNode[r].widthOfEdge } dataEdges.push(edge); @@ -302,8 +302,8 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P } else if (nodeOfSecondType.length == 1) { //The node exists, creates only the edge var enlace = { - from : result[0].id, - to : nodeOfSecondType[0].id, + from: result[0].id, + to: nodeOfSecondType[0].id, value: dataParsed[n].relationWithSecondNode[r].widthOfEdge } dataEdges.push(enlace); @@ -316,10 +316,10 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P console.log("Error: Multiples nodes with same id found"); } } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////Creation of the network with the library////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////Creation of the network with the library////////////////////////////////////////////////////////// var nodesDataSet = new visN.DataSet(dataNodes); var edgesDataSet = new visN.DataSet(dataEdges); @@ -334,27 +334,27 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P //CHANGE: Options controlled by user directly var options_1 = { height: container.getBoundingClientRect().height.toString(), - physics:{ - barnesHut:{ + physics: { + barnesHut: { gravitationalConstant: $scope.vis.params.gravitationalConstant, springConstant: $scope.vis.params.springConstant } }, - edges:{ + edges: { arrowStrikethrough: false, smooth: { type: $scope.vis.params.smoothType }, - scaling:{ - min:$scope.vis.params.minEdgeSize, - max:$scope.vis.params.maxEdgeSize + scaling: { + min: $scope.vis.params.minEdgeSize, + max: $scope.vis.params.maxEdgeSize } }, nodes: { physics: $scope.vis.params.nodePhysics, - scaling:{ - min:$scope.vis.params.minNodeSize, - max:$scope.vis.params.maxNodeSize + scaling: { + min: $scope.vis.params.minNodeSize, + max: $scope.vis.params.maxNodeSize } }, layout: { @@ -367,7 +367,7 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P switch ($scope.vis.params.posArrow) { case 'from': var options_2 = { - edges:{ + edges: { arrows: { from: { enabled: $scope.vis.params.displayArrow, @@ -380,7 +380,7 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P break; case 'middle': var options_2 = { - edges:{ + edges: { arrows: { middle: { enabled: $scope.vis.params.displayArrow, @@ -393,7 +393,7 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P break; case 'to': var options_2 = { - edges:{ + edges: { arrows: { to: { enabled: $scope.vis.params.displayArrow, @@ -406,7 +406,7 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P break; default: var options_2 = { - edges:{ + edges: { arrows: { from: { enabled: $scope.vis.params.displayArrow, @@ -421,35 +421,35 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P var options = angular.merge(options_1, options_2); console.log("Create network now"); var network = new visN.Network(container, data, options); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $scope.startDynamicResize(network); network.on("afterDrawing", function (canvasP) { $("#" + loading_id).hide(); // Draw the color legend if Node Color is activated - if($scope.vis.aggs.bySchemaName['colornode'] && $scope.vis.params.showColorLegend){ + if ($scope.vis.aggs.bySchemaName['colornode'] && $scope.vis.params.showColorLegend) { $scope.drawColorLegend(usedColors, colorDicc); } }); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////NODE-RELATION Type///////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - }else if($scope.vis.aggs.bySchemaName['first'].length == 1 && $scope.vis.aggs.bySchemaName['second']){ + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////NODE-RELATION Type///////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + } else if ($scope.vis.aggs.bySchemaName['first'].length == 1 && $scope.vis.aggs.bySchemaName['second']) { $scope.initialShows(); $(".secondNode").hide(); // Retrieve the id of the configured tags aggregation var firstFieldAggId = $scope.vis.aggs.bySchemaName['first'][0].id; var secondFieldAggId = $scope.vis.aggs.bySchemaName['second'][0].id; - if($scope.vis.aggs.bySchemaName['colornode']){ + if ($scope.vis.aggs.bySchemaName['colornode']) { var colorNodeAggId = $scope.vis.aggs.bySchemaName['colornode'][0].id; var colorNodeAggName = $scope.vis.aggs.bySchemaName['colornode'][0].params.field.displayName; var colorDicc = {}; var usedColors = []; //Check if "Node Color" is the last selection - if($scope.vis.aggs.indexOf($scope.vis.aggs.bySchemaName['colornode'][0]) <= $scope.vis.aggs.indexOf($scope.vis.aggs.bySchemaName['second'][0])){ + if ($scope.vis.aggs.indexOf($scope.vis.aggs.bySchemaName['colornode'][0]) <= $scope.vis.aggs.indexOf($scope.vis.aggs.bySchemaName['second'][0])) { $scope.errorNodeColor(); return; } @@ -460,39 +460,39 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P var secondFieldAggName = $scope.vis.aggs.bySchemaName['second'][0].params.field.displayName; // Retrieve the metrics aggregation configured - if($scope.vis.aggs.bySchemaName['size_node']){ + if ($scope.vis.aggs.bySchemaName['size_node']) { var metricsAgg_sizeNode = $scope.vis.aggs.bySchemaName['size_node'][0]; } - if($scope.vis.aggs.bySchemaName['size_edge']){ + if ($scope.vis.aggs.bySchemaName['size_edge']) { var metricsAgg_sizeEdge = $scope.vis.aggs.bySchemaName['size_edge'][0]; } // Get the buckets of that aggregation var buckets = resp.rows; - ///////////////////////////////////////////////////////////////DATA PARSED AND BUILDING NODES/////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////DATA PARSED AND BUILDING NODES/////////////////////////////////////////////////////////////// var dataParsed = []; // Iterate the buckets var i = 0; - var dataNodes = buckets.map(function(bucket) { - //New structure, needed to search after algorimt - var result = $.grep(dataParsed, function(e){ return e.keyNode == bucket[firstFirstBucketId]; }); - if (result.length == 0) { + var dataNodes = buckets.map(function (bucket) { + //New structure, needed to search after algorimt + var result = $.grep(dataParsed, function (e) { return e.keyNode == bucket[firstFirstBucketId]; }); + if (result.length == 0) { dataParsed[i] = {}; dataParsed[i].keyNode = bucket[firstFirstBucketId]; //Metrics are for the sizes - if(metricsAgg_sizeNode){ + if (metricsAgg_sizeNode) { // Use the getValue function of the aggregation to get the value of a bucket var value = bucket[nodeSizeId]; var sizeVal = Math.min($scope.vis.params.maxCutMetricSizeNode, value); //No show nodes under the value - if($scope.vis.params.minCutMetricSizeNode > value){ + if ($scope.vis.params.minCutMetricSizeNode > value) { dataParsed.splice(i, 1); return; } - }else{ + } else { var sizeVal = 20; } @@ -502,23 +502,23 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P dataParsed[i].relationWithSecondField = [] //RELATION////////////////////////////// - if(metricsAgg_sizeEdge){ + if (metricsAgg_sizeEdge) { var value_sizeEdge = bucket[edgeSizeId]; var sizeEdgeVal = Math.min($scope.vis.params.maxCutMetricSizeEdge, value_sizeEdge); - }else{ + } else { var sizeEdgeVal = 0.1; } //Get the color of the node, save in the dictionary - if(colorNodeAggId){ - if(colorDicc[bucket[colorBucketId]]){ + if (colorNodeAggId) { + if (colorDicc[bucket[colorBucketId]]) { dataParsed[i].nodeColorKey = bucket[colorBucketId]; dataParsed[i].nodeColorValue = colorDicc[bucket[colorBucketId]]; - }else{ + } else { //repeat to find a NO-REPEATED color - while(true){ + while (true) { var confirmColor = randomColor(); - if(usedColors.indexOf(confirmColor) == -1){ + if (usedColors.indexOf(confirmColor) == -1) { colorDicc[bucket[colorBucketId]] = confirmColor; dataParsed[i].nodeColorKey = bucket[colorBucketId]; dataParsed[i].nodeColorValue = colorDicc[bucket[colorBucketId]]; @@ -539,10 +539,10 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P ///////////////////////////// var inPopup = "

" + bucket[firstFirstBucketId] + "

" - if(dataParsed[i].nodeColorValue != "default"){ + if (dataParsed[i].nodeColorValue != "default") { var colorNodeFinal = dataParsed[i].nodeColorValue; inPopup += "

" + dataParsed[i].nodeColorKey + "

"; - }else{ + } else { var colorNodeFinal = $scope.vis.params.firstNodeColor; } @@ -555,80 +555,80 @@ module.controller('KbnNetworkVisController', function ($scope, $sce, $timeout, P shape: $scope.vis.params.shapeFirstNode, //size: sizeVal value: sizeVal, - font : { - color: $scope.vis.params.labelColor + font: { + color: $scope.vis.params.labelColor } } //If activated, show the labels - if($scope.vis.params.showLabels){ + if ($scope.vis.params.showLabels) { nodeReturn.label = bucket[firstFirstBucketId]; } //If activated, show the popups - if($scope.vis.params.showPopup){ + if ($scope.vis.params.showPopup) { nodeReturn.title = inPopup; } return nodeReturn; } else if (result.length == 1) { - //Repetido el nodo, solo añadimos sus relaciones - var dataParsed_node_exist = result[0] - if($scope.vis.aggs.bySchemaName['second'].length > 0){ - if(metricsAgg_sizeEdge){ - var value_sizeEdge = bucket[edgeSizeId]; - var sizeEdgeVal = Math.min($scope.vis.params.maxCutMetricSizeEdge, value_sizeEdge); - }else{ - var sizeEdgeVal = 0.1; - } + //Repetido el nodo, solo añadimos sus relaciones + var dataParsed_node_exist = result[0] + if ($scope.vis.aggs.bySchemaName['second'].length > 0) { + if (metricsAgg_sizeEdge) { + var value_sizeEdge = bucket[edgeSizeId]; + var sizeEdgeVal = Math.min($scope.vis.params.maxCutMetricSizeEdge, value_sizeEdge); + } else { + var sizeEdgeVal = 0.1; + } - var relation = { - keyRelation: bucket[secondBucketId], - countMetric: bucket[nodeSizeId], - widthOfEdge: sizeEdgeVal + var relation = { + keyRelation: bucket[secondBucketId], + countMetric: bucket[nodeSizeId], + widthOfEdge: sizeEdgeVal + } + dataParsed_node_exist.relationWithSecondField.push(relation) } - dataParsed_node_exist.relationWithSecondField.push(relation) - } - return undefined + return undefined } }); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////BUILDING EDGES/////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////BUILDING EDGES/////////////////////////////////////////////////////////////////////// //Clean "undefinded" in the array dataNodes = dataNodes.filter(Boolean); var dataEdges = []; //Iterate parsed nodes - for(var n = 0; n