treeData = {
const childrenLookup = [{
name:"root",
type:"organisation",
data:{}
}];
let seniorCount = 0;
seniorData.forEach((row, i)=>{
const postID = Number(row["Post Unique Reference"]);
childrenLookup[postID] = {
name:`id${postID}`,
parent:row["Reports to Senior Post"] == "XX" ? 'root' : `id${row["Reports to Senior Post"]}`,
type:"senior",
data:row,
}
seniorCount = i;
});
seniorCount ++;
juniorData.forEach((row, i)=>{
const postID = `id${seniorCount + i}`;
if(!isNaN(seniorCount + i) && !isNaN(Number(row["Reports to Senior Post"]))){
childrenLookup[seniorCount + i] = {
name:postID,
parent:`id${Number(row["Reports to Senior Post"])}`,
type:"junior",
data:row,
}
}
})
const tree = d3.stratify()
.id(d=>d.name)
.parentId(d=>d.parent)
(childrenLookup);
return tree;
}