Function: add_coord_transforms()
add_coord_transforms(
pbp):Row[]
Defined in: src/analytics/hockeytech.ts:474
Add the ten derived coordinate columns (*_original, *_neutral, *_fixed, *_right,
*_vertical) from raw x_coord / y_coord (canvas pixels, 600x300, top-left origin).
Parameters
pbp
Row[]
Play-by-play rows with raw x_coord / y_coord (numbers or numeric strings;
anything else becomes null), team_id, and optionally home_team_id (added by
enrich_pbp).
Returns
Row[]
A new array of copied rows with x_coord_original / y_coord_original (the raw
values as floats), *_neutral (origin moved to canvas centre: x - 300, y - 150), and
three rotations of the rink-feet frame x = x_coord / 3 - 100 (-100..100),
y = 42.5 - y_coord * 85 / 300 (-42.5..42.5, positive = top of the canvas):
*_fixed = (-x, -y) for every event (the home team shoots right, +x);
*_right = (-x, -y) for home events and (x, y) for visitor events (every team shoots
right); *_vertical = (-y_coord_right, x_coord_right) (every team shoots up). Null
coordinates stay null in every derived column.
Example
import { add_coord_transforms } from "sportsdataverse/dist/analytics/hockeytech.js";
const [r] = add_coord_transforms([{ x_coord: 450, y_coord: 75, team_id: "1", home_team_id: "2" }]);
r.x_coord_right; // 50 (visitor: unchanged feet)
r.y_coord_vertical; // 50
Remarks
The feed's home team attacks raw x = 0 and the visitor x = 600 in every period, so the
180-degree rotation (-x, -y) points the home team right. Home / away is decided by comparing
String(team_id) to String(home_team_id); when either is null or '' (faceoffs carry no
team, and home_team_id is '' without game metadata) the side is unknown and the *_right
and *_vertical columns are null, never the visitor's. Divisions by a float literal are
computed as a * (1 / c) so the feet match sdv-py's polars output bit-for-bit. Ported from
fastRhockey R/hockeytech_analytics.R; definitions in sdv-internal-refs hockeytech/CANVAS.md.