function CreatePlot()
{
const start = d3.utcDay.offset(d3.min(daily_orders_product, (d) => d.order_date));
const end = d3.utcDay.offset(d3.max(daily_orders_product, (d) => d.order_date));
const plot = Plot.plot({
width: 1152,
height: d3.utcYear.count(start, end) * 160,
axis: null,
padding: 0,
marginTop: 50,
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
},
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(
daily_orders_product,
calendar({
date: "order_date",
fill: (d) => {
const year = d.order_date.getUTCFullYear();
const deviation = d.revenue - medianRevenuePerYear[year];
return colorBasedOnDeviation(deviation);
}
})
),
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")})
)
]
});
addLegendToPlot(plot);
return plot;
}