From f67016c3f1d2f652dbb0fb3c926064062045ebe2 Mon Sep 17 00:00:00 2001 From: Pitchaya Boonsarngsuk <2285135b@student.gla.ac.uk> Date: Mon, 15 Jan 2018 13:47:45 +0000 Subject: [PATCH] Add options for hybrid --- ...3-force-neighbourSampling-papaparsing.html | 40 +++++++++++++++---- .../js/src/neighbourSampling-papaparsing.js | 27 ++++++++----- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/examples/d3-force-neighbourSampling-papaparsing.html b/examples/d3-force-neighbourSampling-papaparsing.html index 77760d0..c574844 100644 --- a/examples/d3-force-neighbourSampling-papaparsing.html +++ b/examples/d3-force-neighbourSampling-papaparsing.html @@ -145,23 +145,47 @@
- -

+
+ +
+ +
+ +
+ +
+ Neighbour diff --git a/examples/js/src/neighbourSampling-papaparsing.js b/examples/js/src/neighbourSampling-papaparsing.js index d8f6661..5e6d20e 100644 --- a/examples/js/src/neighbourSampling-papaparsing.js +++ b/examples/js/src/neighbourSampling-papaparsing.js @@ -56,7 +56,10 @@ var MULTIPLIER = 50, FULL_ITERATIONS = 20, NODE_SIZE = 10, COLOR_ATTRIBUTE = "", - SELECTED_DISTANCE = 10; + SELECTED_DISTANCE = 10, + FULL_NEIGHBOUR_SIZE = 6, + FULL_SAMPLE_SIZE = 3, + FULL_SELECTED_DISTANCE = 10; // Create a color scheme for a range of numbers. var color = d3.scaleOrdinal(d3.schemeCategory10); @@ -105,6 +108,15 @@ function processData(data, error) { props.forEach(function (d) { opts.add(new Option(d, d, (d === COLOR_ATTRIBUTE) ? true : false)); }); + opts.selectedIndex = props.length-1; + + props.pop(); //Hide Iris index / last column from distance function + + //Put the nodes in random starting positions + nodes.forEach(function (d) { + d.x = (Math.random()-0.5) * 100000; + d.y = (Math.random()-0.5) * 100000; + }); // Add the nodes to DOM. node = svg.append("g") @@ -264,7 +276,7 @@ function startNeighbourSamplingSimulation() { .neighbourSize(NEIGHBOUR_SIZE) .sampleSize(SAMPLE_SIZE) // .freeness(0.5) - .distanceRange(SELECTED_DISTANCE) + .distanceRange(SELECTED_DISTANCE * MULTIPLIER) // The distance function that will be used to calculate distances // between nodes. .distance(function (s, t) { @@ -296,8 +308,8 @@ function startHybridSimulation() { .neighbourSize(NEIGHBOUR_SIZE) .sampleSize(SAMPLE_SIZE); - var sample = hybridSimulation.sample(); - var remainder = hybridSimulation.remainder(); + let sample = hybridSimulation.sample(); + let remainder = hybridSimulation.remainder(); // Add the nodes to DOM. node = svg.append("g") @@ -334,16 +346,13 @@ function startHybridSimulation() { unSelectNodes(selectedData); } - hybridSimulation - .distance(distanceFunction); hybridSimulation .on("sampleTick", tickedHybrid) .on("fullTick", tickedHybrid) - .on("startFull", started) + .on("startFull", startedFull) .on("end", endedHybrid); - function tickedHybrid() { if (rendering === true) { node @@ -356,7 +365,7 @@ function startHybridSimulation() { } } - function started() { + function startedFull() { d3.selectAll(".nodes").remove(); // Add the nodes to DOM. node = svg.append("g")