feat(results): qualifying place (TQ) next to final results and podium bands for the top three (1.74.0)
This commit is contained in:
1 parent
41043a990d
commit
fee9f8073d
12 files changed
+149
-38
No files matched your search
+28
-8
@@ -14,6 +14,7 @@ const MEDALS = {
|
||||
2: ["#7d8691", "#cfd5dc", "#ffffff", "#33383f"],
|
||||
3: ["#84491a", "#d38a4c", "#ffd7b0", "#3d2109"],
|
||||
};
|
||||
const PODIUM_TINT = { 1: "#fbeebf", 2: "#e9edf1", 3: "#f5dcc6" };
|
||||
const TEXT = "#1d2330";
|
||||
const MUTED = "#6b7486";
|
||||
const RULE = "#d8dde6";
|
||||
@@ -60,6 +61,8 @@ function wrapText(text, size, bold, maxWidth) {
|
||||
return lines.length ? lines : [""];
|
||||
}
|
||||
|
||||
// Blend two #rrggbb colours; amount 0 gives the first, 1 the second.
|
||||
const mix = (from, to, amount) => `#${[1, 3, 5].map((index) => Math.round(parseInt(from.slice(index, index + 2), 16) * (1 - amount) + parseInt(to.slice(index, index + 2), 16) * amount).toString(16).padStart(2, "0")).join("")}`;
|
||||
const rgb = (hex) => [1, 3, 5].map((index) => (parseInt(hex.slice(index, index + 2), 16) / 255).toFixed(3)).join(" ");
|
||||
const escapePdfText = (text) => String(text || "").replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)");
|
||||
const n = (value) => Number(value.toFixed(2));
|
||||
@@ -161,13 +164,14 @@ function createWriter(pageWidth, pageHeight, title) {
|
||||
writer.page.push(`${rgb(color)} rg ${n(cx + r)} ${n(cy)} m ${n(cx + r)} ${n(cy + k)} ${n(cx + k)} ${n(cy + r)} ${n(cx)} ${n(cy + r)} c ${n(cx - k)} ${n(cy + r)} ${n(cx - r)} ${n(cy + k)} ${n(cx - r)} ${n(cy)} c ${n(cx - r)} ${n(cy - k)} ${n(cx - k)} ${n(cy - r)} ${n(cx)} ${n(cy - r)} c ${n(cx + k)} ${n(cy - r)} ${n(cx + r)} ${n(cy - k)} ${n(cx + r)} ${n(cy)} c f`);
|
||||
},
|
||||
// A gold/silver/bronze medal: rim, face, a soft highlight and the place in bold.
|
||||
medal(cx, cy, place) {
|
||||
medal(cx, cy, place, label = String(place)) {
|
||||
const [rim, face, light, ink] = MEDALS[place];
|
||||
writer.circle(cx, cy, 7, rim);
|
||||
writer.circle(cx, cy, 5.8, face);
|
||||
writer.circle(cx - 1.6, cy + 1.8, 2.4, light);
|
||||
writer.circle(cx - 0.3, cy + 0.3, 4.1, face);
|
||||
writer.text(cx - 6, cy - 2.6, String(place), 7.5, { bold: true, color: ink, align: "center", width: 12 });
|
||||
const size = label.length > 1 ? 6 : 7.5;
|
||||
writer.text(cx - 6, cy - size / 3, label, size, { bold: true, color: ink, align: "center", width: 12 });
|
||||
},
|
||||
image(x, y, w, h) {
|
||||
writer.page.push(`q ${n(w)} 0 0 ${n(h)} ${n(x)} ${n(y)} cm /Im1 Do Q`);
|
||||
@@ -227,7 +231,13 @@ function drawTable(writer, section, theme) {
|
||||
return values.length > 0 && values.every((value) => NUMERIC.test(value));
|
||||
});
|
||||
const hasPos = POS_HEADER.test(String(section.headers[0] || "").trim());
|
||||
const align = (index) => (index === 0 && numeric[0] ? "center" : numeric[index] ? "right" : "left");
|
||||
const placeColumn = section.headers.map((_h, index) => {
|
||||
const values = section.rows.map((row) => String(row[index] || "").trim()).filter(Boolean);
|
||||
return values.length > 0 && values.every((value) => /^(TQ|[A-Z]?\d+|-)$/.test(value));
|
||||
});
|
||||
// The driver name is the first column that is not a place or a number; podium rows make it bold.
|
||||
const nameIndex = section.headers.findIndex((_h, index) => index > 0 && !numeric[index] && !placeColumn[index]);
|
||||
const align = (index) => (placeColumn[index] && index < 3 ? "center" : numeric[index] ? "right" : "left");
|
||||
const headHeight = 19;
|
||||
const rowHeight = 16.5;
|
||||
|
||||
@@ -247,17 +257,27 @@ function drawTable(writer, section, theme) {
|
||||
if (writer.ensure(rowHeight)) drawHead();
|
||||
const top = writer.y;
|
||||
if (rowIndex % 2 === 1) writer.rect(MARGIN, top - rowHeight, writer.width, rowHeight, theme.zebra);
|
||||
const podium = hasPos ? PODIUM[String(row[0] || "").trim()] : null;
|
||||
if (podium) writer.rect(MARGIN, top - rowHeight, 3.5, rowHeight, podium);
|
||||
const place = hasPos ? /^A?([1-3])$/.exec(String(row[0] || "").trim())?.[1] : null;
|
||||
const podium = place ? PODIUM[place] : null;
|
||||
if (podium) {
|
||||
// Tinted band fading out to the right, like House of RC's result lists.
|
||||
const steps = 14;
|
||||
const bandWidth = writer.width * 0.7;
|
||||
for (let step = 0; step < steps; step += 1) {
|
||||
writer.rect(MARGIN + (bandWidth / steps) * step, top - rowHeight, bandWidth / steps + 0.5, rowHeight, mix(PODIUM_TINT[place], rowIndex % 2 ? theme.zebra : "#ffffff", step / steps));
|
||||
}
|
||||
writer.rect(MARGIN, top - rowHeight, 3.5, rowHeight, podium);
|
||||
}
|
||||
let x = MARGIN;
|
||||
section.headers.forEach((_h, index) => {
|
||||
const bold = Boolean(podium) && index <= 1;
|
||||
const bold = Boolean(podium) && index === nameIndex;
|
||||
if (podium && index === 0) {
|
||||
writer.medal(x + widths[0] / 2, top - rowHeight / 2, Number(String(row[0]).trim()));
|
||||
writer.medal(x + widths[0] / 2, top - rowHeight / 2, Number(place), String(row[0]).trim());
|
||||
x += widths[0];
|
||||
return;
|
||||
}
|
||||
writer.text(x + PAD, top - 11.5, fitText(row[index], CELL_SIZE, bold, widths[index] - PAD * 2), CELL_SIZE, { bold, align: align(index), width: widths[index] - PAD * 2 });
|
||||
const tq = String(row[index] || "").trim() === "TQ";
|
||||
writer.text(x + PAD, top - 11.5, fitText(row[index], CELL_SIZE, bold || tq, widths[index] - PAD * 2), CELL_SIZE, { bold: bold || tq, color: tq ? "#b07d00" : TEXT, align: align(index), width: widths[index] - PAD * 2 });
|
||||
x += widths[index];
|
||||
});
|
||||
writer.line(MARGIN, top - rowHeight, MARGIN + writer.width, top - rowHeight, RULE, 0.4);
|
||||
|
||||
Reference in new issue
Block a user