Can someone help me figure out why my json file isn't being produced. I used a small subset of the data and it worked. When I use the full set I get either and empty array, the first two lines worked, or a cyclic error.
Here is the first few lines of my csv....
parent,name,nsize,lsize,type,level,nfill
NR2F2,NNMT,20,3.035224474,black,red,blue
NR2F2,CDH6,20,2.497522953,black,red,blue
NR2F2,LOX,20,2.882828876,black,red,blue
NR2F2,AFAP1L2,20,3.250988851,black,red,blue
NR2F2,KCNG1,20,1.871023523,black,red,blue
NR2F2,THBS2,20,3.556420832,black,red,blue
NR2F2,RHOU,20,4.892457573,black,red,blue
NR2F2,ITIH5,20,1.579040121,black,red,blue
and here is the script that I've copied from Generate (multilevel) flare.json data format from flat json
//load csv and copy to global variable
d3.csv("../jsfiles/nr2f2tbx5hey2json.csv", function(csv_data) {
var nested_data = d3.nest()
.entries(csv_data);
var dataMap = {};
var dataMap = nested_data.reduce(function(map, node) {
map[node.name] = node;
return map;
}, {});
// create the tree array
var tree = [];
nested_data.forEach(function(node) {
// add to parent
var parent = dataMap[node.parent];
if (parent) {
// create child array if it doesn't exist
(parent.children || (parent.children = []))
// add node to child array
.push(node);
} else {
// parent is null or missing
tree.push(node);
}
});
//create the root node for the treemap
var root = {};
// Add the data to the tree
root.name = "Start";
root.children = tree;
console.log(JSON.stringify(root,null, 4));
It looks like it errors out after the //create the tree array section
Any help is appreciated. Thanks!