Results export as plain text: procès-verbal, compact, liste, barres, markdown and csv templates with a preview, copy and download, from the share tab or a closed question; tally maths shared with the results bars

This commit is contained in:
2026-11-19 01:01:54 +01:00
parent 3ebbb67817
commit 41b4ac1a78
5 changed files with 258 additions and 18 deletions
+7 -10
View File
@@ -1,3 +1,6 @@
import { tally, pct } from "./export.js";
export { pct };
export const $ = (sel, root = document) => root.querySelector(sel);
// tiny element builder, children are always text nodes or elements so no html injection
@@ -103,9 +106,6 @@ export function drawQR(canvas, modules, px) {
}
}
export function pct(n, d) {
return d ? Math.round((n / d) * 1000) / 10 : 0;
}
// CSSOM write, a style="" attribute would be blocked by the CSP
export function fill(percent, cls = "bar-fill") {
@@ -115,16 +115,13 @@ export function fill(percent, cls = "bar-fill") {
}
export function resultsView(q) {
const r = q.results;
if (!r) return null;
if (!q.results) return null;
// 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 { phone, extra, tot, ballots, blank, base, exBallots } = tally(q);
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);
seg("bar-fill", phone[i]), extra[i] ? seg("bar-extra", extra[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),
@@ -137,7 +134,7 @@ export function resultsView(q) {
h("p", { class: "results-foot" },
`${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`) : "",
exBallots ? h("span", { class: "extra-note" }, `, dont ${exBallots} ajouté${exBallots > 1 ? "s" : ""} à la main`) : "",
),
);
}