{
const customAxis = {
titleX: -10, titleY: -2, titleAngle: 0, titleAlign: 'center',
domain: false, ticks: false,
labelPadding: 10, labelAlign: 'center'
};
const plot = (sex, axis) => {
return vl
.markBar({ opacity: 0.4 })
.transform(vl.filter(`datum.sex === "${sex}"`))
.encode(
vl.x().sum('people')
.scale({ domain: [0, 12e6] })
.sort(axis ? 'ascending' : 'descending')
.axis({ format: 's' })
.title(`${sex}s`),
vl.y().fieldO('age')
.axis(axis)
.sort('descending')
.title('Age'),
vl.color().fieldN('sex')
.scale({ range: ['#675193', '#ca8861'] })
.title('Sex')
)
.width(250)
.height(350);
};
return vl
.data('data/population.json')
.transform(
vl.calculate('datum.sex === 1 ? "Male" : "Female"').as('sex'),
vl.filter('datum.year === Year')
)
.params(
vl.param('Year').bind(viewof year)
)
.hconcat(
plot('Female', null),
plot('Male', customAxis)
)
.bounds('flush')
.spacing(20)
.render();
}