Public
Edited
May 16, 2023
Insert cell
Insert cell
Sunburst(data, {
label: (d) => d?.label, // display text
value: (d) => d?.total, // angle of each arc
title: (d, n) => d?.total?.toLocaleString(), // hover text
color: d3.schemeSet1,
width,
height: 720
})
Insert cell
viewof showTotals = Inputs.radio([true, false], {
label: "Show totals",
value: true
})
Insert cell
data = ({
label: "Birth date accuracy IAM",
children: Array.from(
d3.group(animalsCreatedByBirthDateAccuracy, (d) => d.BIRTHDATEACCURACY)
).map((d) => {
const accuracy = d[0];
const value = d[1];
const total = d3.sum(d[1], (d) => d.TOTAL);

return {
label: `${accuracyToLabel[accuracy]}${showTotals ? ` (${total})` : ""}`,
value,
children: Array.from(d3.group(value, (d) => d.SPECIES)).map((d) => {
const speciesLabel = d[0];
const speciesValue = d[1];
const total = d3.sum(d[1], (d) => d.TOTAL);

return {
label: `${speciesLabel}${showTotals ? ` (${total})` : ""}`,
children: Array.from(d3.group(speciesValue, (d) => d.SEX)).map(
(d) => {
const sexLabel = d[0];
const total = d3.sum(d[1], (d) => d.TOTAL);

return {
label: `${sexLabel}${showTotals ? ` (${total})` : ""}`,
total
};
}
)
};
})
};
})
})
Insert cell
import {Sunburst} from "@d3/sunburst"
Insert cell
Animals created by birth date accuracy.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
animalsCreatedByBirthDateAccuracy
X
BIRTHDATEACCURACY
Y
TOTAL
Color
SPECIES
Size
Facet X
Facet Y
SEX
Mark
bar
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Mobs created by birth date accuracy (1).csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
mobsData
X
birthDateAccuracy
Y
size
Color
species
Size
Facet X
species
Facet Y
sex
Mark
bar
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Sunburst(mobsSunburstData, {
label: (d) => d?.label, // display text
value: (d) => d?.total, // angle of each arc
title: (d, n) => d?.total?.toLocaleString(), // hover text
color: d3.schemeSet1,
width,
height: 720
})
Insert cell
mobsSunburstData = ({
label: "Birth date accuracy Mob",
children: Array.from(d3.group(mobsData, (d) => d.birthDateAccuracy)).map(
(d) => {
const accuracy = d[0];
const value = d[1];
const total = d3.sum(d[1], (d) => d.total);

return {
label: accuracy,
// label: `${accuracyToLabel[accuracy]}${showTotals ? ` (${total})` : ""}`,
value,
children: Array.from(d3.group(value, (d) => d.species)).map((d) => {
const speciesLabel = d[0];
const speciesValue = d[1];
const total = d3.sum(d[1], (d) => d.total);

return {
label: `${speciesLabel}${showTotals ? ` (${total})` : ""}`,
children: Array.from(d3.group(speciesValue, (d) => d.sex)).map(
(d) => {
const sexLabel = d[0];
const total = d3.sum(d[1], (d) => d.total);

return {
label: `${sexLabel}${showTotals ? ` (${total})` : ""}`,
total
};
}
)
};
})
};
}
)
})
Insert cell
accuracyToLabel = ({
before_year: "Not tracked",
day: "Day",
week: "Week",
month: "Month",
year: "Year"
})
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more