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:
1 parent
fbc4246a60
commit
afe884d2fe
12 files changed
+141
-7
No files matched your search
@@ -984,6 +984,21 @@ function normalizePdfLapChart(chart) {
|
||||
return { title: String(chart.title || "").slice(0, 80), lapLabel: String(chart.lapLabel || "").slice(0, 20), laps, series };
|
||||
}
|
||||
|
||||
// A heat's lap times: a row per lap, a column per driver (finish order), best laps marked.
|
||||
function normalizePdfLapTable(table) {
|
||||
if (!table || !Array.isArray(table.names) || !Array.isArray(table.rows)) return null;
|
||||
const names = table.names.slice(0, 24).map((name) => String(name || "-").slice(0, 60));
|
||||
if (!names.length) return null;
|
||||
const rows = table.rows.slice(0, 400).map((row) => names.map((_n, col) => String((Array.isArray(row) ? row[col] : "") ?? "").slice(0, 12)));
|
||||
if (!rows.length) return null;
|
||||
const index = (value, max) => { const n = Math.floor(Number(value)); return Number.isInteger(n) && n >= 0 && n < max ? n : -1; };
|
||||
const best = names.map((_n, col) => index(Array.isArray(table.best) ? table.best[col] : -1, rows.length));
|
||||
const fastest = table.fastest && index(table.fastest.row, rows.length) >= 0 && index(table.fastest.col, names.length) >= 0
|
||||
? { row: index(table.fastest.row, rows.length), col: index(table.fastest.col, names.length) }
|
||||
: null;
|
||||
return { title: String(table.title || "").slice(0, 80), lapLabel: String(table.lapLabel || "").slice(0, 20), legend: String(table.legend || "").slice(0, 160), names, rows, best, fastest };
|
||||
}
|
||||
|
||||
function normalizePdfExportPayload(input = {}) {
|
||||
const title = String(input.title || "RC RaceCore").trim();
|
||||
const subtitle = String(input.subtitle || "").trim();
|
||||
@@ -1006,6 +1021,7 @@ function normalizePdfExportPayload(input = {}) {
|
||||
// A country code per row for the flag before the driver's name ("SE", "GB-ENG"); anything else is dropped.
|
||||
flags: Array.isArray(section?.flags) ? section.flags.map((code) => (/^[A-Z]{2}(-[A-Z]{3})?$/.test(String(code || "")) ? String(code) : "")) : [],
|
||||
chart: normalizePdfLapChart(section?.chart),
|
||||
lapTable: normalizePdfLapTable(section?.lapTable),
|
||||
}))
|
||||
: [];
|
||||
|
||||
|
||||
Reference in new issue
Block a user