chart = {
const container = d3.create("div").attr("class", "scroll-container");
const narrativeContainer = container
.append("div")
.attr("class", "narrative-container");
const narrative = narrativeContainer.append("div").attr("class", "narrative");
narrative
.selectAll(".section")
.data(descriptions)
.join("div")
.attr("class", "section")
.append("h1")
.text(d => d);
const vis = container.append("div").attr("class", "vis-container");
const update = section => {
if (section === mutable currentSection) return;
mutable currentSection = section;
let color = '';
switch (section) {
case 0:
color = "white";
break;
case 1:
color = "pink";
break;
case 2:
color = "green";
break;
case 3:
color = "black";
break;
default:
color = "blue";
break;
}
vis.style("background-color", color);
};
narrativeContainer.on("scroll", () => {
const totalHeight = narrativeContainer.node().getBoundingClientRect().top;
const offset = narrative.node().getBoundingClientRect().y;
const section = Math.floor((totalHeight - offset + 10) / sectionHeight);
update(section);
});
return container.node();
}