small_multiple = {
const columns = 3,
x_step = 300,
x_padding = 110,
y_step = 160,
y_padding = 80;
const confirmVL = vl
.markArea({ opacity: 0.4, color: "#013", interpolate: 'step' })
.encode(
vl
.x()
.fieldT('date')
.title('时间(月)')
.axis({
labelExpr: '(month(datum.value)+1)',
grid: false,
tickSize: -5,
labelPadding: 10,
title:'时间(月)',
titleFont:'STSong',
tickCount: { interval: "month", step: 1 }
}),
vl
.y({ scale: { domainMin: 0 } })
.fieldQ('new_confirm')
.axis({labelExpr:'replace(format(datum.value,","),","," ")',titlePadding: 10,title:'新增确诊(例)', titleFont:'STSong',
titleFontSize:14,
tickSize:-5,
labelPadding:10,})
);
const my_chart = data =>
vl
.layer(
confirmVL,
vl
.markRule({ color: 'red' })
.encode(vl.x().fieldT('日期'))
.data(new_variant.objects().filter(d => d.国家 == data[0].国家))
)
.title({
text: data[0].国家,
fontSize: 16,
font: 'StSong',
subtitle: `累计确诊 ${d3
.format(',')(data.slice(-1)[0].confirm)
.replaceAll(',', ' ')} 例`,
subtitleColor: '#555'
})
.resolve({ scale: { y: 'independent' } })
.width(x_step - x_padding)
.height(y_step - y_padding)
.data(data);
return html`<svg width=${x_step * columns} height=${Math.ceil(
countries.objects().length / columns
) * y_step} style="background:#FFF">
${await Promise.all(
countries.objects().map((c, i) => {
const pos = {
x: (i % columns) * x_step,
y: Math.floor(i / columns) * y_step
};
const data = hopkins
.objects()
.filter(d => d.country == c.country && d.row <= 189 && d.row>= 9);
return my_chart(data)
.toView()
.toSVG()
.then(svg => `<g transform='translate(${pos.x},${pos.y})'>${svg}</g>`);
})
)}
</svg>`;
}