{
const baseline = dataStacked.
filter(d => d.year <= 2012).
groupby('indicador').
rollup({baseline: op.mean('valor')}).
objects().
reduce((a, v) => ({...a, [v.indicador]:v.baseline}), {})
const df = dataStacked.
filter(aq.escape(d => d.year > 2012 & Object.keys(baseline).includes(d.indicador))).
derive({valor: aq.escape(d => d.valor / baseline[d.indicador])}).
groupby(['year', 'indicador']).
rollup({valor: op.median('valor')}).
orderby('year')
const plot = Plot.plot({
marginTop: 0,
width: width,
marginLeft: 50,
marginRight: 0,
color: {
scheme: 'RdGy',
reverse: true,
type:'diverging-log',
legend: false,
},
y: {
label: null,
tickSize: 0,
tickFormat: d3.format('.0f')
},
x: {
axis: null,
},
marks: [
Plot.cell(df,{
y: 'year',
x: 'indicador',
fill: 'valor',
title: d => `${d.indicador} en ${d.year}\n${d3.format('.1%')(d.valor)} de la media entre 2007 y 2012`,
inset: 0,
sort: {
x: 'fill',
reduce: 'median',
}
})
]
})
const legend = plot.legend('color', {
ticks: 3,
tickFormat: d => d < 1 ? 'normal' : d == 1 ? '' : 'preocupante',
label: null,
width: width})
return html`<div>${legend}${plot}</div>`
}