@talabes/football-lineup-generator
Version:
A TypeScript library for generating visual football lineup diagrams from team positioning data. Fork of ncamaa/football-lineup-generator with bug fixes and improvements.
41 lines (40 loc) • 2.26 kB
JavaScript
import { Position, LayoutType } from '../types.js';
export function getPositionCoordinates(width, height, layoutType, fieldOffsetX = 0, isFullField = true) {
const actualWidth = layoutType === LayoutType.SPLIT_PITCH ? width : width;
const fieldMargin = 50;
const fieldWidth = actualWidth - 2 * fieldMargin;
// Improved spacing to reduce overlaps
const baseCoords = {
// Goalkeeper
[]: { x: fieldMargin + fieldWidth * 0.08, y: height / 2 },
// Defenders - better vertical spacing
[]: { x: fieldMargin + fieldWidth * 0.25, y: height * 0.2 },
[]: { x: fieldMargin + fieldWidth * 0.25, y: height * 0.5 },
[]: { x: fieldMargin + fieldWidth * 0.25, y: height * 0.8 },
// Defensive Midfielders
[]: { x: fieldMargin + fieldWidth * 0.4, y: height / 2 },
// Midfielders - improved spacing
[]: { x: fieldMargin + fieldWidth * 0.55, y: height * 0.25 },
[]: { x: fieldMargin + fieldWidth * 0.55, y: height / 2 },
[]: { x: fieldMargin + fieldWidth * 0.55, y: height * 0.75 },
[]: { x: fieldMargin + fieldWidth * 0.7, y: height / 2 },
// Wingers
[]: { x: fieldMargin + fieldWidth * 0.75, y: height * 0.2 },
[]: { x: fieldMargin + fieldWidth * 0.75, y: height * 0.8 },
// Forwards - better spacing
[]: { x: fieldMargin + fieldWidth * 0.88, y: height * 0.35 },
[]: { x: fieldMargin + fieldWidth * 0.88, y: height / 2 },
[]: { x: fieldMargin + fieldWidth * 0.88, y: height * 0.65 },
// Substitutes (off-field)
[]: { x: actualWidth + 20, y: height / 2 },
};
// Apply field offset for split pitch layout
const offsetCoords = {};
for (const [position, coords] of Object.entries(baseCoords)) {
offsetCoords[position] = {
x: coords.x + fieldOffsetX,
y: coords.y
};
}
return offsetCoords;
}