plot = {
const start = d3.utcDay.offset(d3.min(alphaForum, (d) => d.date));
const end = d3.utcDay.offset(d3.max(alphaForum, (d) => d.date));
return Plot.plot({
width: 1152,
height: d3.utcYear.count(start, end) * 160,
axis: null,
padding: 0,
x: {
domain: d3.range(54)
},
y: {
axis: "left",
domain: [-1, 0, 1, 2, 3, 4, 5, 6],
ticks: [1, 2, 3, 4, 5],
tickSize: 0,
tickFormat: Plot.formatWeekday()
},
fy: {
padding: 0.1,
reverse: false
},
color: {
scheme: "piyg",
legend: true,
label: "Posts on this day"
},
marks: [
Plot.text(
d3.utcYears(d3.utcYear(start), end),
calendar({text: d3.utcFormat("%Y"), frameAnchor: "right", x: 0, y: -1, dx: -20})
),
// Draw month labels at the start of each month, rounding down to draw a
// month even if the data doesn’t start on the first of the month. As
// above, use y = -1 to place the month labels above the cells. (If you
// want to show weekends, round up to Sunday instead of Monday.)
Plot.text(
d3.utcMonths(d3.utcMonth(start), end).map(d3.utcMonday.ceil),
calendar({text: d3.utcFormat("%b"), frameAnchor: "left", y: -1})
),
// Draw a cell for each day in our dataset. The color of the cell encodes
// the relative daily change. (The first value is not defined because by
// definition we don’t have the previous day’s close.)
// todo – get their URLs
Plot.cell(
postsByDay,
calendar({date: "date", fill: (d) => d.entries.length, tip: true, title: d => `Posts ${d.date.toLocaleDateString()} ${d.entries.length} \n ${d.date.elements[0]?.url}`})
),
// tip: true,
// title: d => `${d.name} – ${d.prettyVersion} – ${(new Date(d.date).toLocaleDateString())} – ${d.authorList}` ,
//
// Plot.groupX({y: "count"}, {x: "species"})
// Draw a line delineating adjacent months. Since the y-domain above is
// set to hide weekends (day number 0 = Sunday and 6 = Saturday), if the
// first day of the month is a weekend, round up to the first monday.
/*
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})
),*/
// Lastly, draw the date for all days spanning the dataset, including
// days for which there is no data.
Plot.text(
d3.utcDays(start, end),
calendar({text: d3.utcFormat("%-d")})
)
]
});
}