plot = {
const start = d3.utcDay.offset(d3.min(dji, (d) => d.Date));
const end = d3.utcDay.offset(d3.max(dji, (d) => d.Date));
return Plot.plot({
width: 1152,
height: d3.utcYear.count(start, end) * 160,
axis: null,
padding: 0,
x: {
domain: d3.range(53)
},
y: {
axis: "left",
domain: [-1, 0, 1, 2, 3, 4, 5, 6],
ticks: [0, 1, 2, 3, 4, 5, 6],
tickSize: 0,
tickFormat: Plot.formatWeekday()
},
fy: {
padding: 0.1,
reverse: true
},
color: {
scheme: "piyg",
domain: [0, 1300],
legend: true,
percent: true,
ticks: 8,
tickFormat: "+d",
label: "Daily amount"
},
marks: [
Plot.text(
d3.utcYears(d3.utcYear(start), end),
calendar({text: d3.utcFormat("%Y"), frameAnchor: "right", x: 0, y: -1, dx: -20})
),
Plot.text(
d3.utcMonths(d3.utcMonth(start), end).map(d3.utcMonday.ceil),
calendar({text: d3.utcFormat("%b"), frameAnchor: "left", y: -1})
),
Plot.cell(
dji.slice(1),
calendar({ date: "Date", fill: (d) => (Plot.valueof(d, "Close") - d3.mean(dji, (d) => Plot.valueof(d, "Close"))) })
),
new MonthLine(
d3.utcMonths(d3.utcMonth(start), end)
.map((d) => d3.utcDay.offset(d, d.getUTCDay() === 0 ? 1
: d.getUTCDay() === 6 ? 2
: 0)),
calendar({stroke: "white", strokeWidth: 3})
),
Plot.text(
d3.utcDays(start, end),
calendar({text: d3.utcFormat("%-d")})
)
]
});
}