bar_plot = function (data, cb_norm) {
const format = cb_norm === "normalize" ? "~%" : ".2s";
return vl
.markBar({ width: 6 })
.data(
data
.derive({ sum: (d) => d.inner + d.adjacent + d.other })
.derive({ long_distance: (d) => d.other })
.fold(["inner", "adjacent", "long_distance"], {
as: ["distance", "trips"]
})
.derive({ rel: (d) => op.round((100 * d.trips) / d.sum) / 100 })
.select("date", "distance", "trips", "rel")
)
.encode(
vl
.x()
.fieldT("date")
.axis({ title: "Date", titleFont: "Helvetica Neue" }),
vl
.y()
.fieldQ("trips")
.stack(cb_norm === "normalize" ? "normalize" : true)
.axis({ title: "Trips", titleFont: "Helvetica Neue", format: format }),
vl.color().fieldN("distance").sort(tri.order).scale({ range: tri.color }),
vl
.tooltip()
.field(cb_norm === "normalize" ? "rel" : "trips")
.format(format)
);
}