allTransitions = (transitions, title) => {
const container = html`<canvas></canvas>`
const getColor = label => colorMap[label]
const labels = transitions.map(d => dateDiffToHuman(d.date));
const flows = [
'First Time',
'Low-Value', 'New Low-Value', 'Reactivated Low-Value', 'High to Low-Value',
'High-Value', 'New High-Value', 'Low to High-Value', 'Reactivated High-Value',
'Bounced', 'Lapsed Low-Value', 'Lapsed High-Value'
]
const data = {
labels,
datasets: flows.map((label, index) => {
const direction = label.match(/^(Bounced|Lapsed)/) ? -1 : 1
return {
label,
data: transitions.map(s => s.transitions[label] * direction),
fill: true,
borderColor: getColor(label),
backgroundColor: getColor(label)
}})
}
const options = {
legend: { align: 'start', position: transitions.length >= 12 ? 'right' : 'top', },
maintainAspectRatio: transitions.length >= 12,
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;
}