From 0101245e9e03bb609b9a3b591c1708cb46780654 Mon Sep 17 00:00:00 2001 From: Pitchaya Boonsarngsuk <2285135b@student.gla.ac.uk> Date: Wed, 3 Jan 2018 10:32:40 +0700 Subject: [PATCH] Clean up old codes --- examples/js/distances/distance.js | 4 ++-- .../js/src/neighbourSampling-papaparsing.js | 5 ++--- index.js | 4 ++-- src/link.js | 21 ++++++++++++------- src/neighbourSamplingDistance.js | 15 ++++++------- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/examples/js/distances/distance.js b/examples/js/distances/distance.js index 592416f..14d26ac 100644 --- a/examples/js/distances/distance.js +++ b/examples/js/distances/distance.js @@ -65,6 +65,6 @@ function calculateDistance(source, target, properties, normArgs) { sumDiff *= properties.length/cols; } - console.log(sumDiff); + //console.log(sumDiff); return sumDiff; -} \ No newline at end of file +} diff --git a/examples/js/src/neighbourSampling-papaparsing.js b/examples/js/src/neighbourSampling-papaparsing.js index be6e691..1c9f878 100644 --- a/examples/js/src/neighbourSampling-papaparsing.js +++ b/examples/js/src/neighbourSampling-papaparsing.js @@ -25,9 +25,8 @@ var intercom = Intercom.getInstance(); intercom.on("select", unSelectNodes); -var links = [], - nodes, - node, +var nodes, // as in Data points + node, // as in SVG object that have all small circles on screen props, norm, p1 = 0, diff --git a/index.js b/index.js index cb76f9c..19935c5 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,11 @@ -export { +/*export { default as forceNeighbourSampling } from "./src/neighbourSampling"; export { default as forceNeighbourSamplingPre } - from "./src/neighbourSamplingPre"; + from "./src/neighbourSamplingPre";*/ export { default as forceNeighbourSamplingDistance } diff --git a/src/link.js b/src/link.js index 0211c7b..9cb3acd 100644 --- a/src/link.js +++ b/src/link.js @@ -36,9 +36,11 @@ export default function(links) { } function force(alpha) { - for (var k = 0, n = links.length; k < iterations; ++k) { - for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) { - link = links[i], source = link.source, target = link.target; + for (var k = 0, n = links.length; k < iterations; ++k) { // Each iteration in a tick + for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) { //For each link + link = links[i]; + source = link.source; + target = link.target; x = target.x + target.vx - source.x - source.vx || jiggle(); y = target.y + target.vy - source.y - source.vy || jiggle(); l = Math.sqrt(x * x + y * y); @@ -66,14 +68,17 @@ export default function(links) { } for (i = 0; i < m; ++i) { - link = links[i], link.index = i; - if (typeof link.source !== "object") link.source = find(nodeById, link.source); - if (typeof link.target !== "object") link.target = find(nodeById, link.target); - ++count[link.source.index], ++count[link.target.index]; + link = links[i]; + link.index = i; + //if (typeof link.source !== "object") link.source = find(nodeById, link.source); + //if (typeof link.target !== "object") link.target = find(nodeById, link.target); + ++count[link.source.index]; + ++count[link.target.index]; } for (i = 0, bias = new Array(m); i < m; ++i) { - link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]); + link = links[i]; + bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]); } strengths = new Array(m), initializeStrength(); diff --git a/src/neighbourSamplingDistance.js b/src/neighbourSamplingDistance.js index 75a386e..c5787f5 100644 --- a/src/neighbourSamplingDistance.js +++ b/src/neighbourSamplingDistance.js @@ -26,9 +26,9 @@ export default function () { nodes, neighbourSize = 6, sampleSize = 3, - freeness = 0.85, - springForce = 0.7, - dampingFactor = 0.3, + //freeness = 0.85, + //springForce = 0.7, + //dampingFactor = 0.3, velocity, multiplier = 50; @@ -99,8 +99,9 @@ export default function () { neighbs = new Map([...neighbs.entries()].sort(sortDistances)); neighbours[i] = neighbs; - exclude.concat(neighbs); - samples[i] = createRandomSample(i, exclude, n, sampleSize); + //exclude.concat(neighbs); + //samples[i] = createRandomSample(i, exclude, n, sampleSize); + //Samples will be created at the start of each it anyway. } } @@ -276,9 +277,9 @@ export default function () { return getAvgVelocity(); }; - force.freeness = function (_) { + /*force.freeness = function (_) { return arguments.length ? (freeness = +_, force) : freeness; - }; + };*/ force.distanceRange = function (_) { return arguments.length ? (distanceRange = +_, force) : distanceRange;