Function: passNetwork()
passNetwork(
rows,o):PassNetwork
Defined in: packages/sdvplot/src/cytoscape.ts:290
A passing network as Cytoscape elements and stylesheet: one node per player, one directed edge per passer to
receiver pair, weighted by its passes (a row is a pass; weight sums a column instead) and as wide as that weight
(edgeWidth px for the heaviest pair, the others in proportion), stroked in the passing team's colour with an arrow at
the receiver. A player whose headshot resolves is drawn as it (background-image), with the name below; any other is
a node in the team's colour with the name's initials, the clean fallback, with one warning naming those players
(soccer has no headshots, so every soccer player is this node; headshots: false asks for none). With x, y, xend and
yend, each node sits at the mean of where the player passed from and received (y up, flipped for Cytoscape's y-down
model, scale px per unit): draw it with the preset layout. Without them, use a layout such as cose. A row with
no passer, no receiver or a missing coordinate is left out with one warning. The stylesheet is teamStylesheet's.
Parameters
rows
readonly Row[]
o
Returns
Example
import { loadLeague } from "@sportsdataverse/sdvplot";
import { passNetwork } from "@sportsdataverse/sdvplot/cytoscape";
await loadLeague("nfl");
// Patrick Mahomes to Xavier Worthy, a Super Bowl LIX touchdown (ESPN athlete ids)
const pass = { from: 3139477, from_name: "Patrick Mahomes", to: 4683062, to_name: "Xavier Worthy", team: "KC" };
const { elements, style } = passNetwork([pass], {
from: "from",
to: "to",
fromName: "from_name",
toName: "to_name",
team: "team",
league: "nfl",
});
// in the browser: cytoscape({ container, elements, style, layout: { name: "cose" } })
elements.nodes[0]?.data.image;