{
const bisector = d3.bisector((i) => stocks[i].Date);
const basis = (I, Y) => Y[I[bisector.center(I, date)]];
return Plot.plot({
style: "overflow: visible;",
y: {
type: "log",
grid: true,
label: "Change in price (%)",
tickFormat: (
(f) => (x) =>
f((x - 1) * 100)
)(d3.format("+d"))
},
marks: [
Plot.ruleY([1]),
Plot.ruleX([date]),
Plot.lineY(
stocks,
Plot.normalizeY(basis, {
x: "Date",
y: "Close",
stroke: "Symbol"
})
),
Plot.text(
stocks,
Plot.selectLast(
Plot.normalizeY(basis, {
x: "Date",
y: "Close",
z: "Symbol",
text: "Symbol",
textAnchor: "start",
dx: 3
})
)
)
]
});
}