-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpreprocessing_nf.js
104 lines (92 loc) · 3.06 KB
/
preprocessing_nf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import * as d3 from 'd3';
import * as fs from 'fs';
"STEP 1-----------------------------------------------------------------------"
const args = process.argv.slice(2)
const fileName = args[0]
const rootDir = args[1]
const folderName = args[2]
let unprocessedData = fs.readFileSync(`${rootDir}/finalInput/${folderName}/${fileName}`)
unprocessedData = JSON.parse(unprocessedData)
let nodes = unprocessedData["nodes"]
let links = unprocessedData["links"]
const radiusCalc = (minR, maxR, gamma, value) => maxR - (maxR - minR) * Math.exp(-gamma * (value - 1));
function ticked() {
const params = {
minR: 15,
maxR: 200,
gamma: 0.1,
nonNodeR: 8,
lambda: 15000000,
charge: 200,
minZoom: 0.05,
maxZoom: 6,
alphaDecay: 0.03,
velocityDecay: 0.2,
minAlpha: 0.001,
heatingCharge: 5000,
heatingCutoff: 0.1,
centreX: -167.2703,
centreY: -1547.4755,
centreScale: 0.1,
intScale: 0.5,
};
let chargeStrength, alpha = this.alpha()
if (alpha > params.heatingCutoff) {
chargeStrength = -params.heatingCharge;
} else {
chargeStrength = -params.charge;
}
this.force("charge", d3.forceManyBody().strength(chargeStrength))
.force(
"collide",
d3
.forceCollide()
.strength(0.9)
.radius(function (d, i) {
return d.num > 0
? radiusCalc(params.minR, params.maxR, params.gamma, d.num)
: params.nonNodeR;
})
)
.force("link")
.iterations(100)
.strength(1);
}
const ended = (nodes, links, fileName) => {
"parsed the result to the main dir"
let annealedData = JSON.stringify({ nodes, links });
fs.writeFileSync(`./${fileName.match(/(.*?).json/)[1]}_annealed.json`, annealedData)
}
// This is the default settings from Joseph bubble-track
const params = {
minR: 15,
maxR: 200,
gamma: 0.1,
nonNodeR: 8,
lambda: 15000000,
charge: 200,
minZoom: 0.05,
maxZoom: 6,
alphaDecay: 0.03,
velocityDecay: 0.2,
minAlpha: 0.001,
heatingCharge: 5000,
heatingCutoff: 0.1,
centreX: -167.2703,
centreY: -1547.4755,
centreScale: 0.1,
intScale: 0.5,
};
console.log(nodes);
// console.log(links)
const simulation = d3
.forceSimulation(nodes)
// .force("center", d3.forceCenter(compStat.width/2, compStat.height/2))
.force("charge",d3.forceManyBody().strength(function (d) {return d.num > 0 ? -params.charge : 0;}))
.force("collide",d3.forceCollide().strength(0.9).radius(function (d, i) {return d.num > 0? radiusCalc(params.minR, params.maxR, params.gamma, d.num): 0;}))
.force("link",d3.forceLink(links).id(function (d) {return d.id;}).distance(function (d) {return d.len * params.lambda;}).iterations(100).strength(1))
.alphaDecay(params.alphaDecay)
.velocityDecay(params.velocityDecay)
.alphaMin(params.minAlpha)
.on("tick", ticked)
.on("end", () => ended(nodes, links, fileName))