Skip to content

Instantly share code, notes, and snippets.

@andrewheekin
Created July 21, 2016 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewheekin/cc6cdeb7a09217391464352884dd391b to your computer and use it in GitHub Desktop.
Save andrewheekin/cc6cdeb7a09217391464352884dd391b to your computer and use it in GitHub Desktop.
var csv = `MW,A,50
W,B,100
MW,B,100
E,C,70
E,A,90
W,D,200
W,F,190`
var csvArr = csv.split('\n')
csvArr.forEach((item, index, arr) => arr[index] = item.split(','));
var flare = {};
csvArr.forEach((item, index, arr) => {
if (item[0] in flare) flare[item[0]][item[1]] = item[2];
else {
flare[item[0]] = {};
flare[item[0]][item[1]] = item[2];
}
})
var flarejson = {name:"flare", children:[]}
for (var key in flare){
let child = [];
for (var key2 in flare[key]){
child.push({name:key2, size:flare[key][key2]});
}
flarejson.children.push({name:key, children:child});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment