feat(export): lap times table with best and fastest laps marked in a heat's print and PDF (1.89.52)

This commit is contained in:
larssand committed 2026-11-16 23:18:31 +01:00
1 parent fbc4246a60
commit afe884d2fe
12 files changed
+141 -7

No files matched your search

+50
View File
@@ -349,6 +349,55 @@ function drawLapChart(writer, chart) {
writer.y -= height + 8;
}
// The lap times under a heat: a row per lap, a column per driver in finish order. Each driver's
// best lap is bold on green, the fastest lap of the heat bold on purple.
const BEST_LAP_FILL = "#dcf5e3";
const FASTEST_LAP_FILL = "#eadcfb";
const FASTEST_LAP_TEXT = "#5b21b6";
function drawLapTable(writer, table, theme) {
const cols = table.names.length;
const lapW = 24;
const colW = (writer.width - lapW) / cols;
const size = cols > 10 ? 6.5 : 7.5;
const rowH = cols > 10 ? 11 : 12.5;
const headLines = table.names.map((name, index) => wrapText(`${index + 1}. ${name}`, size, true, colW - 4).slice(0, 2));
const headH = 6 + Math.max(1, ...headLines.map((lines) => lines.length)) * (size + 2.5);
const baseline = (top) => top - rowH + (rowH - size) / 2 + 1.2;
const drawHead = () => {
writer.rect(MARGIN, writer.y - headH, writer.width, headH, theme.headFill);
writer.text(MARGIN + 3, writer.y - 4 - size, fitText(table.lapLabel, size, true, lapW - 4), size, { bold: true, color: theme.headText });
headLines.forEach((lines, col) => lines.forEach((line, index) => {
writer.text(MARGIN + lapW + col * colW + 2, writer.y - 4 - size - index * (size + 2.5), line, size, { bold: true, color: theme.headText, align: "center", width: colW - 4 });
}));
writer.y -= headH;
};
writer.ensure(18 + headH + rowH * 3);
writer.text(MARGIN, writer.y - 10, fitText(table.title, 10, true, writer.width), 10, { bold: true });
writer.y -= 16;
drawHead();
table.rows.forEach((row, rowIndex) => {
if (writer.ensure(rowH)) drawHead();
const top = writer.y;
if (rowIndex % 2 === 1) writer.rect(MARGIN, top - rowH, writer.width, rowH, theme.zebra);
writer.text(MARGIN + 3, baseline(top), String(rowIndex + 1), size, { color: MUTED });
row.forEach((value, col) => {
const x = MARGIN + lapW + col * colW;
const fastest = Boolean(table.fastest && table.fastest.row === rowIndex && table.fastest.col === col);
const best = table.best[col] === rowIndex;
if (fastest || best) writer.rect(x + 1, top - rowH + 0.6, colW - 2, rowH - 1.2, fastest ? FASTEST_LAP_FILL : BEST_LAP_FILL);
writer.text(x + 2, baseline(top), fitText(value, size, fastest || best, colW - 4), size, { bold: fastest || best, color: fastest ? FASTEST_LAP_TEXT : TEXT, align: "center", width: colW - 4 });
});
writer.line(MARGIN, top - rowH, MARGIN + writer.width, top - rowH, RULE, 0.3);
writer.y -= rowH;
});
if (table.legend) {
writer.ensure(14);
writer.text(MARGIN, writer.y - 9, fitText(table.legend, 7, false, writer.width), 7, { color: MUTED });
writer.y -= 14;
}
writer.y -= 6;
}
function drawParagraphs(writer, section) {
section.rows.forEach((row) => row.forEach((value) => {
wrapText(value, 10, false, writer.width).forEach((line) => {
@@ -490,6 +539,7 @@ function buildStyledPdf(payload) {
if (section.headers.length) drawTable(writer, section, theme);
else drawParagraphs(writer, section);
if (section.chart) drawLapChart(writer, section.chart);
if (section.lapTable) drawLapTable(writer, section.lapTable, theme);
});
drawFooters(writer, pages, payload, theme, pageWidth);