<commit_before>/**
 * force-directed-layout.js
 *
 * This module contains logic for performing the force-directed layout
 * algorithm on a graph.
 *
 * @author <NAME>.
 */
 
 

var Graph = require('./../model/graph');
var Vertex = require('./../model/vertex');
var Port = require('./../model/port');
var Edge = require('./../model/edge');
var CardinalPortPosition = require('./../model/cardinalPortPosition');
var change = false;
//ideal length
var iLength = 100;
//force strength
var forceStr = 1.0/3.0;
//stretching force
var stretchForce  = 0.70;
var vertices;
var mGraph;


//Based partially on https://code.google.com/p/jung/source/browse/branches/guava/jung/jung-algorithms/src/main/java/edu/uci/ics/jung/algorithms/layout/SpringLayout.java?r=19

function layOutGraph(graph) {
	mGraph = graph;
	vertices = graph.get('vertices');
	var edgeList = graph.get('edges');
	var runner = true;
	//var loopCount =0;
	while(runner){
		//console.log('loop count is: '+loopCount+'\n');
		change = false;
		
		for(var i=0;i<edgeList.length;i++){
			springForce(edgeList[i]);
		}
		if(change === false){
			runner = false;
		}
		//loopCount++;
	}
	//defaulting all ports that do not have a position
	for(var j=0;j < vertices.length; j++){
		var inputs = vertices[j].get('inputs');
		var outputs = vertices[j].get('outputs');
		
		for(var h =0; h < inputs.length; h++){
			
			if(inputs[h].get('position') === null){
				inputs[h].set('position', new cardinalPortPosition('E', 50));
			}
			
		}
		for(h =0;h < outputs.length; h++){
			if(outputs[h].get('position') === null){
				outputs[h].set('position', new cardinalPortPosition('W', 50));
			}
		}
	}
	
	for(var b=0;b<vertices.length; b++){
		console.log(vertices[b].get('position').x+','+vertices[b].get('position').y);
	}

}

function springForce(edge){
	//vertex to
	var vt = mGraph.getVertexById(edge.get('to').get('ownerVertexId'));
	//vertex from
	var vf = mGraph.getVertexById(edge.get('from').get('ownerVertexId'));
	//x distance between them
	var xL = edgeXLength(edge);
	//y distance between them
	var yL = edgeYLength(edge);
	//straight line edge length
	var length = edgeLength(edge);
	//checks for both pined
	if(vt.get('isPinned') ===true && vf.get('isPinned')===true){
		return;
	}
	
	//hacky solution for length being 0<commit_msg>removed test case<commit_after>/**
 * force-directed-layout.js
 *
 * This module contains logic for performing the force-directed layout
 * algorithm on a graph.
 *
 * @author <NAME>.
 */
 
 

var Graph = require('./../model/graph');
var Vertex = require('./../model/vertex');
var Port = require('./../model/port');
var Edge = require('./../model/edge');
var CardinalPortPosition = require('./../model/cardinalPortPosition');
var change = false;
//ideal length
var iLength = 100;
//force strength
var forceStr = 1.0/3.0;
//stretching force
var stretchForce  = 0.70;
var vertices;
var mGraph;


//Based partially on https://code.google.com/p/jung/source/browse/branches/guava/jung/jung-algorithms/src/main/java/edu/uci/ics/jung/algorithms/layout/SpringLayout.java?r=19

function layOutGraph(graph) {
	mGraph = graph;
	vertices = graph.get('vertices');
	var edgeList = graph.get('edges');
	var runner = true;
	//var loopCount =0;
	while(runner){
		//console.log('loop count is: '+loopCount+'\n');
		change = false;
		
		for(var i=0;i<edgeList.length;i++){
			springForce(edgeList[i]);
		}
		if(change === false){
			runner = false;
		}
		//loopCount++;
	}
	//defaulting all ports that do not have a position
	for(var j=0;j < vertices.length; j++){
		var inputs = vertices[j].get('inputs');
		var outputs = vertices[j].get('outputs');
		
		for(var h =0; h < inputs.length; h++){
			
			if(inputs[h].get('position') === null){
				inputs[h].set('position', new cardinalPortPosition('E', 50));
			}
			
		}
		for(h =0;h < outputs.length; h++){
			if(outputs[h].get('position') === null){
				outputs[h].set('position', new cardinalPortPosition('W', 50));
			}
		}
	}
}

function springForce(edge){
	//vertex to
	var vt = mGraph.getVertexById(edge.get('to').get('ownerVertexId'));
	//vertex from
	var vf = mGraph.getVertexById(edge.get('from').get('ownerVertexId'));
	//x distance between them
	var xL = edgeXLength(edge);
	//y distance between them
	var yL = edgeYLength(edge);
	//straight line edge length
	var length = edgeLength(edge);
	//checks for both pined
	if(vt.get('isPinned') ===true && vf.get('isPinned')===true){
		return;
	}
	
	//hacky solution for length being 0
{'fraction_non_alphanumeric': 0.1868279569892473, 'fraction_numerical': 0.010080645161290322, 'mean_word_length': 3.837486457204767, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7641279', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1531, 'n_words': 357}