1

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!

Community
  • 1
  • 1
fastmhc
  • 11
  • 2
  • Maybe your data is cyclical? – Nick.Mc Aug 31 '15 at 01:15
  • It is a list of interactions (parent interactions with source (name). There are some interactions that have a feedback loop. So if 1--> 2, 2-->3, and 3-->1. Would this be the problem? and is there a way to change this script to arrange the json correctly for these feedback loops? – fastmhc Aug 31 '15 at 01:29
  • How do you represent a loop in a hierarchy tree? you can't. That's my guess from the 'cyclical error'. It's found an endless loop 1>2>3>1>2>3... I'm guessing that's the issue. You could do more tests on your data to confirm. – Nick.Mc Aug 31 '15 at 01:40
  • I was hoping it would work out to 1-->2, 2-->3, and 1-->3. I'm lost on how to change it so that the parents that have targets higher up can change from 3-->1 to 1-->3 – fastmhc Aug 31 '15 at 02:33
  • OK so this is all an assumption at this stage. I have added the javacript tag in case someone can help you. I guess you need to recognise this in the code (but this is difficult as the information spans many nodes) – Nick.Mc Aug 31 '15 at 03:04

0 Answers0