arealineY(data,
{x: d => (!years || d.Date >= years[0] && d.Date <= years[1]) ? d.Date : NaN,
y: "Close",
color: "gray"})
.plot({
x: {
label: "Year",
domain: years
},
y: {
grid: true,
label: "Share Price [$]",
domain: [0, d3.max(data, (d) => d.Close)]
},
marks: [
Plot.ruleX(data, Plot.pointerX({x: "Date", py: "Close", stroke: "red"})),
Plot.dot(data, Plot.pointerX({x: "Date", y: "Close", stroke: "red"})),
Plot.text(data, Plot.pointerX({px: "Date", py: "Close", dy: -15, frameAnchor: "top", fontVariant: "tabular-nums", text: (d) => [`Apple's share price closed at $${d.Close.toFixed(2)} on ${Plot.formatIsoDate(d.Date)}`]})),
Plot.tip(
[`Apple names Steve Jobs interim CEO`],{x: new Date("1997-09-16"), y:0.2, dy: -3, anchor: "bottom"},
),
Plot.tip(
[`Apple starts selling MacBook`],{x: new Date("2006-05-16"), y:2.32, dy: -3, anchor: "bottom"},
),
Plot.tip(
[`Apple starts selling iPhone`],{x: new Date("2007-06-29"), y:4.36, dy: -43, anchor: "bottom"},
),
Plot.tip(
[`Apple starts selling iPad`],{x: new Date("2010-04-03"), y:8.52, dy: -3, anchor: "bottom"},
),
Plot.tip(
[`Tim Cook suceeds Steve Jobs as Apple's CEO`],{x: new Date("2011-08-24"), y:13.44, dy: -43, dx: 10, anchor: "bottom"},
),
Plot.tip(
[`Apple starts selling Apple Watch`],{x: new Date("2015-04-24"), y:32.57, dy: 19, anchor: "top"},
),
Plot.tip(
[`Apple starts selling Apple TV+`],{x: new Date("2019-11-01"), y:63.96, dy: -3, anchor: "bottom"},
)
],
width: 1200
})