options = (legendHitBoxes) => ({
type: "bar",
data: {
labels: Data.monthAbbreviations,
datasets: [
{
backgroundColor: Style.colours.opening,
borderColor: Style.colours.opening,
borderDash: [4, 4],
data: data.openingHeadcount,
hidden: true,
label: "Opening",
pointRadius: 6,
pointStyle: "circle",
type: "line"
},
{
backgroundColor: (context) => {
const value = context.dataset.data[context.dataIndex];
if (value[1] < value[0]) return Style.colours.startStopDecrease;
return Style.colours.startStopIncrease;
},
barPercentage: 0.5,
data: data.startingEndingHeadcount,
hidden: true,
label: "Start/End"
},
{
backgroundColor: (context) => {
const value = context.dataset.data[context.dataIndex];
if (value[1] < value[0]) return Style.colours.openCloseDecrease;
return Style.colours.openCloseIncrease;
},
borderColor: "#aaa",
borderSkipped: false,
borderWidth: { bottom: 1, left: 0, right: 0, top: 1 },
data: data.openingClosingHeadcount,
label: "Open/Close2"
}
]
},
options: {
datasets: { bar: { grouped: false } },
displayConnectionLines: true,
layout: { padding: 16 },
plugins: {
legend: {
labels: {
generateLabels: (chart) => generateLegendItems(chart, legendHitBoxes)
},
onClick: handleLegendItemClick
},
title: {
display: true,
text: `Headcount Range by Month for ${WorkforceData.sizeByMonthForCalendarYear.year}`
},
tooltip: {
enabled: false,
external: (context) => {
ChartJS.headcountTooltipHandler(
context,
WorkforceData.sizeByMonthForCalendarYear.months
);
},
intersect: false
}
},
scales: {
x: { grid: { drawOnChartArea: false } },
y: { beginAtZero: false, grid: { drawOnChartArea: false } }
}
},
plugins: [{ afterDraw: ChartJS.drawConnectionLines }]
})