Modifying TEofW Char Dataset - success

by Nivaldo

JavaScript

var data = [
    {"val":1,"key":"Pr","children":[{"name":"bob"},{"name":"jim"}]},
    {"val":6,"key":"1","children":[{"name":"ted"},{"name":"alice"}]}
];

var dataset = data;
console.log(dataset);

var changeData = true;
var showCumulative = true;
var suppressZero = false;
    
if (changeData) {
    var mDataset = [];
    var sVal = 0;
    //var supressZero = false;
    dataset.forEach(function(d) { 
        // get and modify the property values
        if ( showCumulative ) 
            sVal = sVal + d.val;
        else
            sVal = d.val;
        var key = d.key;
        
        //console.log(d.children);
        var children = [];
        d.children.forEach(function(d) {children.push({"name":d.name});});
        
        // add the modified property values to the new array
        if ( d.val != 0 )
            mDataset.push({"val": sVal, "key": key, "children": children});
        else if ( !suppressZero )
            mDataset.push({"val": sVal, "key": key, "children": children});
    });
    
    dataset = mDataset;
};

console.log(dataset);