bar_plot = function(data, cb_norm) {
embed.vega.timeFormatLocale(locale);
const format = cb_norm === 'normalize' ? '~%' : '.2s';
return vl
.markBar({ width: 6 })
.data(
data
.derive({ sum: d => d.inner + d.adjacent + d.other })
.derive({
Intern: d => d.inner,
Benachbart: d => d.adjacent
})
.derive({
Fern: d => d.other
})
.fold(['Fern', 'Intern', 'Benachbart'], {
as: ['distance', 'trips']
})
.derive({
rel: d => op.round((100 * d.trips) / d.sum) / 100,
order: d =>
op.recode(d.distance, { Intern: 1, Benachbart: 2, Fern: 0 })
})
.select('date', 'distance', 'trips', 'rel')
)
.encode(
vl
.x()
.fieldT("date")
.axis({ titleFont: "Helvetica Neue", title: 'Datum' }),
vl
.y()
.fieldQ("trips")
.stack(cb_norm === 'normalize' ? 'normalize' : true)
.axis({
titleFont: "Helvetica Neue",
format: format,
title: "Anzahl Bewegungen"
}),
vl
.color()
.fieldN('distance')
.sort(tri.order)
.scale({ range: tri.color })
.legend({ title: 'Entfernung' }),
vl.order('order'),
vl
.tooltip()
.field(cb_norm === 'normalize' ? 'rel' : 'trips')
.format(format)
);
}