compoundInterestPlot = (domain, factors, yearsForFactor, lineLabelPoints) => {
const percentage = d => d.interest + "%";
return Plot.plot({
title: "Compound interest’s exponential growth curves",
subtitle: "acts like cancer in our social structure, hence self-destructs if untreated",
grid: true,
legend: true,
x: {
domain: domain.x,
},
y: {
domain: domain.y,
ticks: 5,
},
marks: [
Plot.line(
factors,
{
x: "year",
y: "factor",
stroke: "interest",
}
),
Plot.dot(
yearsForFactor,
{
x: "year",
y: "factor",
r: 3,
fill: "red"
}
),
Plot.dot(
lineLabelPoints,
{
x: "year",
y: "factor",
z: "interest",
fill: "white",
r: 9
}
),
Plot.text(
lineLabelPoints,
{
x: "year",
y: "factor",
z: "interest",
text: percentage,
fontWeight: "bold",
}
),
Plot.tip(
factors,
Plot.pointerX({x: "year", y: "factor"})
),
],
width: 18*36,
height: 12*36,
marginTop: 36,
marginBottom: 36,
marginLeft: 36,
marginRight: 36,
})
}