highValuePopulationStack = (data, title) => {
const getColor = label => colorMap[label]
const container = html`<canvas></canvas>`;
const states = Object.keys(data[0].transitions).filter(l => ['New High-Value', 'Low to High-Value', 'Lapsed High-Value', 'High to Low-Value', 'Reactivated High-Value'].includes(l))
const myChart = new Chart(container, {
type: 'bar',
options: {
title: { display: true, text: title },
legend: { align: 'start', position: 'right' },
scales: {
xAxes: [{stacked: true}],
yAxes: [{stacked: true}]
}
},
data: {
labels: data.map((t) => dateDiffToHuman(t.date)),
datasets: states.map((label, index) => {
const direction = label.match(/^(Bounced|Lapsed|High to)/) ? -1 : 1
const baseColor = direction === 1 ? color.blue : color.red
const backgroundColor = d3.color(baseColor).brighter(index * 0.5).hex()
return {
label,
fill: true,
backgroundColor,
data: data.map(s => s.transitions[label] * direction)
}
})
},
});
return container;
}