Public
Edited
Feb 22, 2023
Insert cell
Insert cell
Insert cell
packedChart = Pack(treeData)
Insert cell
chart = Tree(treeData, {
label: d => d.name,
width: 2000
})
Insert cell
Insert cell
seniorData = FileAttachment("2023-01-30T09-24-31Z-2022-12-31-organogram-senior.csv").csv()
Insert cell
treeData = {
const childrenLookup = [{
name:"root",
type:"organisation",
data:{}
}];
// make a lookup for all the positions bnoth junior and senior...
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;
}
Insert cell
import {Pack} from "@d3/pack"

Insert cell
import {Tree} from "@d3/tree"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more