in viz-lib/src/visualizations/sunburst/initSunburst.js [57:113]
function buildHierarchy(data) {
data = isDataInHierarchyFormat(data) ? buildNodesFromHierarchyData(data) : buildNodesFromTableData(data);
// build tree
const root = {
name: "root",
children: [],
};
data.forEach(d => {
const nodes = d.nodes;
const size = parseInt(d.size, 10);
// build graph, nodes, and child nodes
let currentNode = root;
for (let j = 0; j < nodes.length; j += 1) {
let children = currentNode.children;
const nodeName = nodes[j];
const isLeaf = j + 1 === nodes.length;
if (!children) {
currentNode.children = children = [];
children.push({
name: exitNode,
size: currentNode.size,
});
}
let childNode = find(children, child => child.name === nodeName);
if (isLeaf && childNode) {
childNode.children = childNode.children || [];
childNode.children.push({
name: exitNode,
size,
});
} else if (isLeaf) {
children.push({
name: nodeName,
size,
});
} else {
if (!childNode) {
childNode = {
name: nodeName,
children: [],
};
children.push(childNode);
}
currentNode = childNode;
}
}
});
return root;
}