allTransitionsOverTime = (transitions, title) => {
const container = html`<canvas></canvas>`
const getColor = label => colorMap[label]
const fromLabels = ['First Time', 'Low-Value', 'High-Value', 'Inactive']
const flows = {
'First Time': ['Bounced', 'New Low-Value', 'New High-Value', ],
'Low-Value': ['Low-Value', 'Lapsed Low-Value', 'Low to High-Value', ],
'High-Value': ['High to Low-Value', 'Lapsed High-Value', 'High-Value'],
'Inactive': ['Reactivated Low-Value', 'Reactivated High-Value'],
}
const labels = transitions.map(d => dateDiffToHuman(d.date));
const data = {
labels,
datasets: Object.entries(flows).map((entry, index) => entry[1].map((label, index) => ({
type: 'bar',
label: `${label}`,
stack: entry[0],
data: transitions.map(s => s.transitions[label]),
fill: true,
backgroundColor: getColor(label)
}))).flat()
}
const options = {
legend: { align: 'start', position: 'right'},
title: { display: true, text: title },
scales: {
xAxes: [{stacked: true}],
yAxes: [{stacked: true}]
}
}
const type = 'bar'
const myChart = new Chart(container, {type, options, data})
return container;
}