Skip to content

Instantly share code, notes, and snippets.

@scogle
Created October 6, 2014 19:28
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 scogle/d6caea314e9463d5a573 to your computer and use it in GitHub Desktop.
Save scogle/d6caea314e9463d5a573 to your computer and use it in GitHub Desktop.
Recursively convert ibeam parent/child output to flare format
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;
}
@scogle
Copy link
Author

scogle commented Oct 6, 2014

Advantages of this approach

  • All extra data returned by the query is maintained (i.e., color, etc.)
  • Only does what's necessary. Doesn't bother with 'size' key since that's not strictly part of the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment