I'm trying to make a bundle layout with D3. However, I'd like to make it non-hierarchical (or pseudo non-hierarchical) so as to have no gaps between the edge nodes. The image below hopefully serves as a good example of the gaps I would like to remove (see top of image between different coloured text).
I've attempted to remedy this two ways: by replacing the type which distinguishes node types with a generic type, and by replacing the node type with the authors' names (thereby making all nodes a different type, forcing equal spacing). The former of these attempts being similar to the suggestion proposed in response to this query.
However, when I run the line
var nodes = cluster.nodes(packageHierarchy(theArr, id_to_user_dict));
I inevitably get the error "Uncaught TypeError: Cannot read property 'parent' of undefined." How can I force a generic root on this data so that my code works properly?
My code to generate the code structure for the included diagram is below. The two solutions that I proposed above are commented out within the "package hierarchy" function. Note that it is derived from Bostock's sample for hierarchical edge bundling.
function packageHierarchy(classes, dictionary) {
for (var i = 0; i < classes.length; i++){
var imports = [];
// classes[i].name = "root" + "^" + classes[i]["author"];
// classes[i].name = classes[i]["author"] + "^" + classes[i]["author"];
classes[i].name = classes[i]["type"] + "^" + classes[i]["author"];
for (var j = 0; j < classes[i]["values"].length; j++){
if (classes[i]["values"][j]["type"] == "comments"){
var responseObj = classes[i]["values"][j]["in_response_to"];
var responseAuthor = dictionary[classes[i]["values"][j]["in_response_to"]];
if (responseAuthor != undefined){
imports.push(responseAuthor);
}
}
}
classes[i].imports = imports;
}
var map = {};
function find(name, data) {
var node = map[name], i;
if (!node) {
node = map[name] = data || {name: name, children: [] };
if (name.length) {
node.parent = find(name.substring(0, i = name.indexOf("^")));
node.parent.children.push(node);
node.key = name.substring(i + 1);
}
}
return node;
}
classes.forEach(function(d) {
find(d.name, d);
});
return map[""];
}