@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.
31 lines (30 loc) • 1.84 kB
JavaScript
import { Position } from '../types.js';
export function getHalfPitchCoordinates(width, height, isHomeTeam) {
const fieldMargin = 50;
const fieldWidth = width - 2 * fieldMargin;
const halfWidth = fieldWidth / 2;
const baseX = isHomeTeam ? fieldMargin : fieldMargin + halfWidth;
// Much better spacing for half pitch to avoid overlaps
return {
// Goalkeeper
[]: { x: baseX + halfWidth * 0.15, y: height / 2 },
// Defenders - distributed better vertically
[]: { x: baseX + halfWidth * 0.4, y: height * 0.15 },
[]: { x: baseX + halfWidth * 0.4, y: height * 0.5 },
[]: { x: baseX + halfWidth * 0.4, y: height * 0.85 },
// Midfielders - staggered formation to avoid overlaps
[]: { x: baseX + halfWidth * 0.6, y: height * 0.35 },
[]: { x: baseX + halfWidth * 0.75, y: height * 0.2 },
[]: { x: baseX + halfWidth * 0.6, y: height * 0.65 },
[]: { x: baseX + halfWidth * 0.75, y: height * 0.8 },
[]: { x: baseX + halfWidth * 0.85, y: height * 0.5 },
// Wingers and Forwards - better distribution
[]: { x: baseX + halfWidth * 0.9, y: height * 0.15 },
[]: { x: baseX + halfWidth * 0.9, y: height * 0.85 },
[]: { x: baseX + halfWidth * 0.95, y: height * 0.35 },
[]: { x: baseX + halfWidth * 0.95, y: height * 0.5 },
[]: { x: baseX + halfWidth * 0.95, y: height * 0.65 },
// Substitutes
[]: { x: width + 20, y: height / 2 },
};
}