Recursively convert ibeam parent/child output to flare format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toFlareRecursive(data, parentKey, childKey) { | |
var root = { 'name': 'Classes', 'children': [] }; | |
function findChildren(d){ | |
var subclasses = _.filter(data, function(obj){ | |
return obj[parentKey] === d[childKey]; | |
}); | |
if ( subclasses.length > 0 ) { | |
d.children = []; | |
_.each(subclasses, function(obj){ | |
obj.name = obj.thisClass; | |
d.children.push(obj); | |
findChildren(obj); | |
}); | |
} | |
} | |
_.each(data, function(obj){ | |
if ( obj[parentKey] === "None" ) { | |
obj.name = obj[childKey]; | |
root.children.push(obj); | |
findChildren(obj); | |
} | |
}); | |
return root; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Advantages of this approach