appendPerson = (container, person, personIndex) => {
let personContainer = container.append("g")
.attr("class", "person")
.attr("data-id", person.id);
const lifetimeStartPoint = {
x: xScale(d3.isoParse(person.birthDate)),
y: personHeight * personIndex
};
const lifetimeEndPoint = {
x: xScale(d3.isoParse(person.deathDate)),
y: lifetimeStartPoint.y
};
const lifetimeWidth = lifetimeEndPoint.x - lifetimeStartPoint.x;
if (person.url) {
personContainer = personContainer.append("a")
.attr("href", person.url)
.attr("target", "_blank");
personContainer.append("rect")
.attr("class", "hoverable-area")
.attr("x", lifetimeStartPoint.x)
.attr("y", lifetimeStartPoint.y)
.attr("width", lifetimeWidth)
.attr("height", personHeight);
}
personContainer.append("rect")
.attr("class", "lifetime-bar")
.attr("x", lifetimeStartPoint.x)
.attr("y", lifetimeStartPoint.y)
.attr("width", lifetimeWidth)
.attr("height", lifetimeBarHeight);
const text = getText(person);
const textWidth = measureWidth(text);
const remainingPlaneWidth = range[1] - lifetimeStartPoint.x;
if (textWidth <= remainingPlaneWidth) {
personContainer.append("text")
.attr("x", lifetimeStartPoint.x)
.attr("y", lifetimeStartPoint.y + 12)
.attr("text-anchor", "start")
.text(text);
} else {
personContainer.append("text")
.attr("x", lifetimeEndPoint.x)
.attr("y", lifetimeEndPoint.y + 12)
.attr("text-anchor", "end")
.text(text);
}
}