questionGraph = function(qlabel) {
const deduped = new Map();
msgs.filter((msg) => (msg.q == qlabel)).map((msg) => {
deduped.set(msg.id, {choice: choices[qlabel][parseInt(msg.c)], ...msg});
});
const vals = Array.from(deduped.values());
return vegalite({
"width": (width* 0.6),
"config": {"axis":{"labelColor": "white", "titleColor": "white"}},
"mark": "bar",
"encoding":
{
"x": {
"aggregate": "distinct",
"field": "id",
"type": "quantitative",
"axis": {title: "personas"},
"scale": {"domain":[0, Math.max(10, vals.length*1.2)]}
},
"y": {"field": "choice", "type": "nominal",
"axis": {title: "selección"},
"scale": {"domain": choices[qlabel]}
}
},
"data": {"values": vals},
})
}