Pivot near neighbour finding working

This commit is contained in:
Pitchaya Boonsarngsuk
2018-01-24 09:51:08 +00:00
parent 6b53b3301d
commit 688ce750c7

View File

@@ -63,6 +63,13 @@ var MULTIPLIER = 50,
// Create a color scheme for a range of numbers. // Create a color scheme for a range of numbers.
var color = d3.scaleOrdinal(d3.schemeCategory10); var color = d3.scaleOrdinal(d3.schemeCategory10);
$(document).ready(function() {
distanceFunction = calculateDistance;
d3.select('#startSimulation').on('click', startHybridSimulation);
$("#HLParameters").show();
});
/** /**
* Parse the data from the provided csv file using Papa Parse library * Parse the data from the provided csv file using Papa Parse library
* @param {file} evt - csv file. * @param {file} evt - csv file.
@@ -112,10 +119,16 @@ function processData(data, error) {
props.pop(); //Hide Iris index / last column from distance function props.pop(); //Hide Iris index / last column from distance function
//Put the nodes in random starting positions //Put the nodes in random starting positions
//TODO Change this back
nodes.forEach(function (d) {
d.x = 0;
d.y = 0;
});
/*
nodes.forEach(function (d) { nodes.forEach(function (d) {
d.x = (Math.random()-0.5) * 100000; d.x = (Math.random()-0.5) * 100000;
d.y = (Math.random()-0.5) * 100000; d.y = (Math.random()-0.5) * 100000;
}); });*/
addNodesToDOM(nodes); addNodesToDOM(nodes);
@@ -139,7 +152,7 @@ function addNodesToDOM(data) {
// it is a CLASS property). // it is a CLASS property).
.attr("fill", function (d) { .attr("fill", function (d) {
return color(d[COLOR_ATTRIBUTE]); return color(d[COLOR_ATTRIBUTE]);
}) })/*
.on("mouseover", function (d) { .on("mouseover", function (d) {
div.transition() div.transition()
.duration(200) .duration(200)
@@ -158,6 +171,7 @@ function addNodesToDOM(data) {
node.attr("opacity", 1); node.attr("opacity", 1);
}) })
.on("click", function (d) { .on("click", function (d) {
console.log("click", clickedIndex);
if (clickedIndex !== d.index) { if (clickedIndex !== d.index) {
if (springForce) { if (springForce) {
highlightNeighbours(Array.from(simulation.force(forceName).nodeNeighbours(d.index).keys())); highlightNeighbours(Array.from(simulation.force(forceName).nodeNeighbours(d.index).keys()));
@@ -167,12 +181,13 @@ function addNodesToDOM(data) {
node.attr("r", NODE_SIZE).attr("stroke-width", 0); node.attr("r", NODE_SIZE).attr("stroke-width", 0);
clickedIndex = -1; clickedIndex = -1;
} }
}); })*/;
if (selectedData) if (selectedData)
unSelectNodes(selectedData); unSelectNodes(selectedData);
} }
function ticked() { function ticked() {
console.log("ticked");
// If rendering is selected, then draw at every iteration. // If rendering is selected, then draw at every iteration.
if (rendering === true) { if (rendering === true) {
node // Each sub-circle in the SVG, update cx and cy node // Each sub-circle in the SVG, update cx and cy
@@ -190,6 +205,7 @@ function ticked() {
} }
function ended() { function ended() {
console.log("ended");
if (rendering !== true) { // Never drawn anything before? Now it's time. if (rendering !== true) { // Never drawn anything before? Now it's time.
node node
.attr("cx", function (d) { .attr("cx", function (d) {
@@ -215,6 +231,7 @@ function ended() {
} }
function brushEnded() { function brushEnded() {
console.log("brushEnded");
var s = d3.event.selection, var s = d3.event.selection,
results = []; results = [];
@@ -248,6 +265,7 @@ function brushEnded() {
* @param {*} node * @param {*} node
*/ */
function formatTooltip(node) { function formatTooltip(node) {
console.log("formatTooltip", node);
var textString = "", var textString = "",
temp = ""; temp = "";
@@ -266,6 +284,7 @@ function formatTooltip(node) {
* Halt the execution. * Halt the execution.
*/ */
function stopSimulation() { function stopSimulation() {
console.log("stopSimulation");
simulation.stop(); simulation.stop();
if (typeof hybridSimulation !== 'undefined') { if (typeof hybridSimulation !== 'undefined') {
hybridSimulation.stop(); hybridSimulation.stop();
@@ -278,6 +297,7 @@ function stopSimulation() {
* @return {number} the mean of the array. * @return {number} the mean of the array.
*/ */
function getAverage(array) { function getAverage(array) {
console.log("getAverage", array);
var total = 0; var total = 0;
for (var i = 0; i < array.length; i++) { for (var i = 0; i < array.length; i++) {
total += array[i]; total += array[i];
@@ -290,7 +310,7 @@ function getAverage(array) {
* @param {*} data * @param {*} data
*/ */
function unSelectNodes(data) { function unSelectNodes(data) {
console.log("unSelectNodes", data);
selectedData = data; selectedData = data;
if (fileName === data.name && nodes) { if (fileName === data.name && nodes) {
node node
@@ -348,7 +368,7 @@ function colorToAttribute() {
/** /**
* Update the distance range. * Update the distance range.
*/
function updateDistanceRange() { function updateDistanceRange() {
if (springForce) { if (springForce) {
simulation.force(forceName).distanceRange(SELECTED_DISTANCE); simulation.force(forceName).distanceRange(SELECTED_DISTANCE);
@@ -380,7 +400,7 @@ function pauseUnPause() {
* @param {*} dataNodes * @param {*} dataNodes
* @param {*} properties * @param {*} properties
* @param {*} normalization * @param {*} normalization
*/
function calculateAverageDistance(dataNodes, properties, normalization) { function calculateAverageDistance(dataNodes, properties, normalization) {
var sum = 0, var sum = 0,
n = nodes.length; n = nodes.length;
@@ -397,4 +417,4 @@ function calculateAverageDistance(dataNodes, properties, normalization) {
} }
return sum / n; return sum / n;
} }*/