Hand-added votes per question (paper, show of hands): counted in the turnout and shown hatched orange at the end of each result bar, kept apart from phone ballots
This commit is contained in:
+24
-9
@@ -117,23 +117,38 @@ export function fill(percent, cls = "bar-fill") {
|
||||
export function resultsView(q) {
|
||||
const r = q.results;
|
||||
if (!r) return null;
|
||||
const base = r.ballots - r.blank;
|
||||
const max = Math.max(1, ...r.counts);
|
||||
const rows = q.options.map((label, i) =>
|
||||
h("div", { class: "bar-row" + (r.counts[i] === max && r.counts[i] > 0 ? " lead" : "") },
|
||||
// votes added by hand ride at the end of each bar, hatched orange, so nobody mistakes them for phone ballots
|
||||
const ex = r.extra || { counts: r.counts.map(() => 0), blank: 0, ballots: 0 };
|
||||
const tot = r.counts.map((c, i) => c + (ex.counts[i] || 0));
|
||||
const ballots = r.ballots + ex.ballots, blank = r.blank + ex.blank, base = ballots - blank;
|
||||
const max = Math.max(1, ...tot);
|
||||
const rows = q.options.map((label, i) => {
|
||||
const stack = h("div", { class: "bar-stack" },
|
||||
seg("bar-fill", r.counts[i]), ex.counts[i] ? seg("bar-extra", ex.counts[i]) : null);
|
||||
stack.style.width = `${pct(tot[i], max)}%`;
|
||||
return h("div", { class: "bar-row" + (tot[i] === max && tot[i] > 0 ? " lead" : "") },
|
||||
h("div", { class: "bar-label" }, label),
|
||||
h("div", { class: "bar-track" }, fill(pct(r.counts[i], max))),
|
||||
h("div", { class: "bar-num" }, r.counts[i], h("small", {}, ` ${pct(r.counts[i], base).toLocaleString("fr-FR")} %`)),
|
||||
));
|
||||
h("div", { class: "bar-track" }, stack),
|
||||
h("div", { class: "bar-num" }, tot[i], h("small", {}, ` ${pct(tot[i], base).toLocaleString("fr-FR")} %`)),
|
||||
);
|
||||
});
|
||||
return h("div", { class: "results" },
|
||||
rows,
|
||||
h("p", { class: "results-foot" },
|
||||
`${r.ballots} bulletin${r.ballots > 1 ? "s" : ""}`,
|
||||
q.allow_blank ? `, dont ${r.blank} blanc${r.blank > 1 ? "s" : ""}` : "",
|
||||
`${ballots} bulletin${ballots > 1 ? "s" : ""}`,
|
||||
q.allow_blank ? `, dont ${blank} blanc${blank > 1 ? "s" : ""}` : "",
|
||||
ex.ballots ? h("span", { class: "extra-note" }, `, dont ${ex.ballots} ajouté${ex.ballots > 1 ? "s" : ""} à la main`) : "",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// a flex share of a bar (CSSOM write, the CSP blocks style="")
|
||||
function seg(cls, n) {
|
||||
const el = h("div", { class: cls });
|
||||
el.style.flexGrow = String(n);
|
||||
return el;
|
||||
}
|
||||
|
||||
export const STATE_LABEL = { draft: "Brouillon", open: "Vote ouvert", closed: "Clos" };
|
||||
|
||||
export function toast(msg, kind = "info") {
|
||||
|
||||
Reference in New Issue
Block a user