feat(results): lap chart per qualifying heat and final in the race overview, print and PDF (1.89.32)
This commit is contained in:
1 parent
01998952a7
commit
6a036899ab
15 files changed
+245
-14
No files matched your search
@@ -195,6 +195,12 @@ function createWriter(pageWidth, pageHeight, title) {
|
||||
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 });
|
||||
},
|
||||
// An open line through points [[x, y], ...]; dashed draws it dotted.
|
||||
polyline(points, color, width = 1, { dashed = false } = {}) {
|
||||
if (points.length < 2) return;
|
||||
const path = points.map(([px, py], index) => `${n(px)} ${n(py)} ${index ? "l" : "m"}`).join(" ");
|
||||
writer.page.push(`q ${rgb(color)} RG ${width} w 1 J 1 j ${dashed ? "[1.5 2.5] 0 d " : ""}${path} S Q`);
|
||||
},
|
||||
image(x, y, w, h) {
|
||||
writer.page.push(`q ${n(w)} 0 0 ${n(h)} ${n(x)} ${n(y)} cm /Im1 Do Q`);
|
||||
},
|
||||
@@ -309,6 +315,40 @@ function drawTable(writer, section, theme) {
|
||||
writer.y -= 10;
|
||||
}
|
||||
|
||||
// The lap chart under a heat: place 1 on top, a line per driver, names at their finish place.
|
||||
function drawLapChart(writer, chart) {
|
||||
const rows = chart.series.length;
|
||||
const rowH = rows > 14 ? 11 : 14;
|
||||
const height = 18 + rows * rowH + 22;
|
||||
writer.ensure(height);
|
||||
writer.text(MARGIN, writer.y - 10, fitText(chart.title, 10, true, writer.width), 10, { bold: true });
|
||||
const top = writer.y - 18;
|
||||
const left = MARGIN + 16;
|
||||
const plotW = writer.width - 16 - 120;
|
||||
const x = (lap) => left + ((lap - 1) / (chart.laps - 1)) * plotW;
|
||||
const y = (place) => top - (place - 0.5) * rowH;
|
||||
for (let place = 1; place <= rows; place += 1) {
|
||||
writer.line(left, y(place), left + plotW, y(place), RULE, 0.4);
|
||||
writer.text(MARGIN, y(place) - 2.5, String(place), 7, { color: MUTED, align: "right", width: 11 });
|
||||
}
|
||||
const step = chart.laps <= 12 ? 1 : chart.laps <= 30 ? 2 : chart.laps <= 60 ? 5 : chart.laps <= 150 ? 10 : 25;
|
||||
for (let lap = 1; lap <= chart.laps; lap += 1) {
|
||||
if (lap === 1 || lap === chart.laps || (lap % step === 0 && chart.laps - lap >= step / 2)) {
|
||||
writer.text(x(lap) - 10, top - rows * rowH - 10, String(lap), 7, { color: MUTED, align: "center", width: 20 });
|
||||
}
|
||||
}
|
||||
writer.text(left + plotW - 60, top - rows * rowH - 20, chart.lapLabel, 7, { color: MUTED, align: "right", width: 60 });
|
||||
chart.series.forEach((serie, index) => {
|
||||
const points = serie.positions.map((place, lap) => (place ? [x(lap + 1), y(place)] : null)).filter(Boolean);
|
||||
if (!points.length) return;
|
||||
writer.polyline(points, serie.color, 1.6);
|
||||
const last = points[points.length - 1];
|
||||
writer.polyline([last, [left + plotW + 6, y(index + 1)]], serie.color, 0.7, { dashed: true });
|
||||
writer.text(left + plotW + 9, y(index + 1) - 2.5, fitText(`${index + 1}. ${serie.name}`, 7.5, true, 110), 7.5, { bold: true, color: serie.color });
|
||||
});
|
||||
writer.y -= height + 8;
|
||||
}
|
||||
|
||||
function drawParagraphs(writer, section) {
|
||||
section.rows.forEach((row) => row.forEach((value) => {
|
||||
wrapText(value, 10, false, writer.width).forEach((line) => {
|
||||
@@ -449,6 +489,7 @@ function buildStyledPdf(payload) {
|
||||
if (section.title) drawSectionTitle(writer, section.title, theme);
|
||||
if (section.headers.length) drawTable(writer, section, theme);
|
||||
else drawParagraphs(writer, section);
|
||||
if (section.chart) drawLapChart(writer, section.chart);
|
||||
});
|
||||
drawFooters(writer, pages, payload, theme, pageWidth);
|
||||
|
||||
|
||||
Reference in new issue
Block a user