Skip to content

Commit 29d9a47

Browse files
committed
Fixed issue with self linked nodes by refactoring addPath() to allow node copy on left and right of link.
1 parent 04b459d commit 29d9a47

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

treemap.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,39 +199,36 @@ d3.json("whitematter.json", function(d) {
199199
}
200200
}
201201

202+
202203
addPath(map, f.data.name, ref);
203204
}
204205
if (e.children) {
205206
for (let i in e.children) getPath(e.children[i], name, dep, map, ref);
206207
}
207208
}
208209

209-
function addPath(map, destination, origin) {
210+
function addPath(map, destinationName, originIndex) {
210211
let target = 0;
211-
//todo copies need to be accessible from node
212212
var copies = false;
213-
//iterate over nodes in the sankey object
214213
for(i = 0; i < map.nodes.length; i++) {
215-
//target equals location of node with title of destination
216-
if (map.nodes[i].name === destination) {
214+
if (map.nodes[i].name === destinationName) {
217215
target = i;
218-
//if the destination location is the same as the origin copies++
219-
if(target == origin && copies == false){
216+
if(target == originIndex && i == map.nodes.length - 1){
220217
console.log(i);
221-
map.nodes.push({ name: destination });
218+
map.nodes.push({ name: destinationName });
222219
target = map.nodes.length;
223220
copies = true;
224221
}
225222
}
226223
else if(i == map.nodes.length - 1){
227-
map.nodes.push({ name: destination });
224+
map.nodes.push({ name: destinationName });
228225
target = i+1;
229226
}
230227

231228
}
232229

233230
map.links.push({
234-
"source": origin,
231+
"source": originIndex,
235232
"target": target,
236233
"value": 1
237234
});

0 commit comments

Comments
 (0)