plot_color_ratio = function(svg) {
let y_pos = 430;
let delta_y = 50;
let num_passports = data.length;
let multiplier = delta_y / num_passports;
let x_pos = parseInt(0.8 * width);
console.log(multiplier);
svg
.selectAll(".colratio")
.data(counts)
.join("rect")
.attr('width', 20)
.attr('height', d => d['counts'] * multiplier)
.attr('y', function(d, i) {
return y_pos + d['cumul'] * multiplier;
})
.attr('x', function(d, i) {
return x_pos;
})
.attr('class', "colratio")
.attr("fill", d => colors.get(d['color']))
.attr("opacity", 1);
svg
.selectAll(".colratiotxt")
.data(counts)
.join("text")
.attr('x', x_pos + 23)
.attr('y', function(d, i) {
return y_pos + d['cumul'] * multiplier + 3.5;
})
.text(
d =>
`${((d['counts'] / num_passports) * 100).toPrecision(
2
)}% of passports are ${d['color']}`
)
.attr("font-family", "sans-serif")
.attr("fill", "#545252")
.style("font-size", "9px");
}