@johnmorrisdotca/kyogijo-stadiums 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE.md +293 -0
  4. package/README.md +600 -2
  5. package/dist/annotate.d.ts +47 -0
  6. package/dist/annotate.js +349 -0
  7. package/dist/atlas-entry.d.ts +4 -0
  8. package/dist/atlas-entry.js +3 -0
  9. package/dist/atlas.d.ts +131 -0
  10. package/dist/atlas.js +149 -0
  11. package/dist/background.d.ts +56 -0
  12. package/dist/background.js +127 -0
  13. package/dist/ballpark.d.ts +48 -0
  14. package/dist/ballpark.js +129 -0
  15. package/dist/canvas-entry.d.ts +2 -0
  16. package/dist/canvas-entry.js +2 -0
  17. package/dist/canvas.d.ts +85 -0
  18. package/dist/canvas.js +279 -0
  19. package/dist/charts-entry.d.ts +10 -0
  20. package/dist/charts-entry.js +8 -0
  21. package/dist/charts.baseball.d.ts +30 -0
  22. package/dist/charts.baseball.js +152 -0
  23. package/dist/charts.curling.d.ts +52 -0
  24. package/dist/charts.curling.js +196 -0
  25. package/dist/charts.d.ts +172 -0
  26. package/dist/charts.js +508 -0
  27. package/dist/charts.network.d.ts +66 -0
  28. package/dist/charts.network.js +64 -0
  29. package/dist/charts.soccer.d.ts +43 -0
  30. package/dist/charts.soccer.js +191 -0
  31. package/dist/charts.types.d.ts +396 -0
  32. package/dist/charts.types.js +1 -0
  33. package/dist/colour.d.ts +29 -0
  34. package/dist/colour.js +97 -0
  35. package/dist/common.d.ts +14 -0
  36. package/dist/common.js +32 -0
  37. package/dist/court.d.ts +89 -0
  38. package/dist/court.js +248 -0
  39. package/dist/courts.style.d.ts +20 -0
  40. package/dist/courts.style.js +54 -0
  41. package/dist/cricket.board.d.ts +18 -0
  42. package/dist/cricket.board.js +67 -0
  43. package/dist/curling.board.d.ts +24 -0
  44. package/dist/curling.board.js +147 -0
  45. package/dist/d3-entry.d.ts +3 -0
  46. package/dist/d3-entry.js +2 -0
  47. package/dist/d3.d.ts +45 -0
  48. package/dist/d3.js +56 -0
  49. package/dist/draw.d.ts +52 -0
  50. package/dist/draw.js +705 -0
  51. package/dist/element-define.d.ts +2 -0
  52. package/dist/element-define.js +4 -0
  53. package/dist/element-entry.d.ts +1 -0
  54. package/dist/element-entry.js +2 -0
  55. package/dist/element.d.ts +39 -0
  56. package/dist/element.js +321 -0
  57. package/dist/eras-entry.d.ts +2 -0
  58. package/dist/eras-entry.js +2 -0
  59. package/dist/eras.d.ts +204 -0
  60. package/dist/eras.js +396 -0
  61. package/dist/events-entry.d.ts +3 -0
  62. package/dist/events-entry.js +3 -0
  63. package/dist/events.d.ts +54 -0
  64. package/dist/events.data.d.ts +59 -0
  65. package/dist/events.data.js +297 -0
  66. package/dist/events.js +127 -0
  67. package/dist/features.d.ts +31 -0
  68. package/dist/features.js +284 -0
  69. package/dist/field.score.d.ts +5 -0
  70. package/dist/field.score.js +33 -0
  71. package/dist/fields/afl.d.ts +11 -0
  72. package/dist/fields/afl.js +103 -0
  73. package/dist/fields/cricket.d.ts +9 -0
  74. package/dist/fields/cricket.js +81 -0
  75. package/dist/fields/fieldhockey.d.ts +6 -0
  76. package/dist/fields/fieldhockey.js +81 -0
  77. package/dist/fields/gaelic.d.ts +10 -0
  78. package/dist/fields/gaelic.js +86 -0
  79. package/dist/fields/handball.d.ts +6 -0
  80. package/dist/fields/handball.js +85 -0
  81. package/dist/fields/lacrosse.d.ts +17 -0
  82. package/dist/fields/lacrosse.js +169 -0
  83. package/dist/fields/rugby.d.ts +10 -0
  84. package/dist/fields/rugby.js +130 -0
  85. package/dist/fields.d.ts +12 -0
  86. package/dist/fields.js +44 -0
  87. package/dist/fields.kit.d.ts +63 -0
  88. package/dist/fields.kit.js +108 -0
  89. package/dist/fields.style.d.ts +4 -0
  90. package/dist/fields.style.js +19 -0
  91. package/dist/fields.types.d.ts +155 -0
  92. package/dist/fields.types.js +1 -0
  93. package/dist/format.d.ts +10 -0
  94. package/dist/format.js +28 -0
  95. package/dist/formations.d.ts +18 -0
  96. package/dist/formations.js +211 -0
  97. package/dist/frames-entry.d.ts +8 -0
  98. package/dist/frames-entry.js +7 -0
  99. package/dist/frames.d.ts +199 -0
  100. package/dist/frames.js +271 -0
  101. package/dist/frames.providers.d.ts +16 -0
  102. package/dist/frames.providers.js +302 -0
  103. package/dist/geojson-entry.d.ts +2 -0
  104. package/dist/geojson-entry.js +2 -0
  105. package/dist/geojson.d.ts +79 -0
  106. package/dist/geojson.js +147 -0
  107. package/dist/geometry-entry.d.ts +7 -0
  108. package/dist/geometry-entry.js +5 -0
  109. package/dist/geometry.d.ts +295 -0
  110. package/dist/geometry.js +361 -0
  111. package/dist/grounds-entry.d.ts +4 -0
  112. package/dist/grounds-entry.js +3 -0
  113. package/dist/grounds.d.ts +134 -0
  114. package/dist/grounds.data.d.ts +2 -0
  115. package/dist/grounds.data.js +1849 -0
  116. package/dist/grounds.js +74 -0
  117. package/dist/heat.colour.d.ts +37 -0
  118. package/dist/heat.colour.js +54 -0
  119. package/dist/heat.d.ts +43 -0
  120. package/dist/heat.js +614 -0
  121. package/dist/heat.stats.d.ts +123 -0
  122. package/dist/heat.stats.js +413 -0
  123. package/dist/heat.types.d.ts +145 -0
  124. package/dist/heat.types.js +1 -0
  125. package/dist/heat.zones.d.ts +54 -0
  126. package/dist/heat.zones.js +424 -0
  127. package/dist/homeside.d.ts +16 -0
  128. package/dist/homeside.js +43 -0
  129. package/dist/index.d.ts +47 -0
  130. package/dist/index.js +29 -0
  131. package/dist/layers-entry.d.ts +19 -0
  132. package/dist/layers-entry.js +11 -0
  133. package/dist/layers.d.ts +41 -0
  134. package/dist/layers.env.d.ts +72 -0
  135. package/dist/layers.env.js +79 -0
  136. package/dist/layers.js +533 -0
  137. package/dist/layers.marks.d.ts +45 -0
  138. package/dist/layers.marks.js +168 -0
  139. package/dist/layers.types.d.ts +226 -0
  140. package/dist/layers.types.js +1 -0
  141. package/dist/layout.d.ts +97 -0
  142. package/dist/layout.js +381 -0
  143. package/dist/layout.style.d.ts +6 -0
  144. package/dist/layout.style.js +17 -0
  145. package/dist/layouts-entry.d.ts +5 -0
  146. package/dist/layouts-entry.js +4 -0
  147. package/dist/leagues/aussie.d.ts +57 -0
  148. package/dist/leagues/aussie.js +36 -0
  149. package/dist/leagues/baseball.d.ts +58 -0
  150. package/dist/leagues/baseball.js +171 -0
  151. package/dist/leagues/basketball.d.ts +67 -0
  152. package/dist/leagues/basketball.js +128 -0
  153. package/dist/leagues/courts.d.ts +212 -0
  154. package/dist/leagues/courts.js +114 -0
  155. package/dist/leagues/cricket.d.ts +45 -0
  156. package/dist/leagues/cricket.js +34 -0
  157. package/dist/leagues/curling.d.ts +64 -0
  158. package/dist/leagues/curling.js +53 -0
  159. package/dist/leagues/fieldhockey.d.ts +48 -0
  160. package/dist/leagues/fieldhockey.js +29 -0
  161. package/dist/leagues/fields.d.ts +10 -0
  162. package/dist/leagues/fields.js +6 -0
  163. package/dist/leagues/football.d.ts +8 -0
  164. package/dist/leagues/football.js +82 -0
  165. package/dist/leagues/gaelic.d.ts +50 -0
  166. package/dist/leagues/gaelic.js +29 -0
  167. package/dist/leagues/handball.d.ts +45 -0
  168. package/dist/leagues/handball.js +32 -0
  169. package/dist/leagues/hockey.d.ts +63 -0
  170. package/dist/leagues/hockey.js +166 -0
  171. package/dist/leagues/lacrosse.d.ts +103 -0
  172. package/dist/leagues/lacrosse.js +175 -0
  173. package/dist/leagues/rugby.d.ts +59 -0
  174. package/dist/leagues/rugby.js +72 -0
  175. package/dist/leagues/sources.d.ts +18 -0
  176. package/dist/leagues/sources.js +95 -0
  177. package/dist/leagues/types.d.ts +43 -0
  178. package/dist/leagues/types.js +5 -0
  179. package/dist/leagues-entry.d.ts +23 -0
  180. package/dist/leagues-entry.js +15 -0
  181. package/dist/leagues.d.ts +172 -0
  182. package/dist/leagues.js +462 -0
  183. package/dist/look.d.ts +50 -0
  184. package/dist/look.js +186 -0
  185. package/dist/mark.d.ts +35 -0
  186. package/dist/mark.js +59 -0
  187. package/dist/mount-entry.d.ts +2 -0
  188. package/dist/mount-entry.js +2 -0
  189. package/dist/mount.d.ts +63 -0
  190. package/dist/mount.js +167 -0
  191. package/dist/mow.d.ts +36 -0
  192. package/dist/mow.js +111 -0
  193. package/dist/names.d.ts +77 -0
  194. package/dist/names.js +97 -0
  195. package/dist/outline.d.ts +25 -0
  196. package/dist/outline.js +112 -0
  197. package/dist/parks-entry.d.ts +4 -0
  198. package/dist/parks-entry.js +3 -0
  199. package/dist/parks.d.ts +200 -0
  200. package/dist/parks.data.d.ts +2 -0
  201. package/dist/parks.data.js +4489 -0
  202. package/dist/parks.js +92 -0
  203. package/dist/plot-entry.d.ts +2 -0
  204. package/dist/plot-entry.js +2 -0
  205. package/dist/plot.d.ts +74 -0
  206. package/dist/plot.js +68 -0
  207. package/dist/png-entry.d.ts +2 -0
  208. package/dist/png-entry.js +2 -0
  209. package/dist/png.d.ts +26 -0
  210. package/dist/png.js +46 -0
  211. package/dist/ranges.d.ts +33 -0
  212. package/dist/ranges.js +178 -0
  213. package/dist/ranges.names.d.ts +31 -0
  214. package/dist/ranges.names.js +65 -0
  215. package/dist/react-entry.d.ts +2 -0
  216. package/dist/react-entry.js +2 -0
  217. package/dist/react.d.ts +53 -0
  218. package/dist/react.js +58 -0
  219. package/dist/replay-entry.d.ts +5 -0
  220. package/dist/replay-entry.js +4 -0
  221. package/dist/replay.control.d.ts +47 -0
  222. package/dist/replay.control.js +184 -0
  223. package/dist/replay.d.ts +170 -0
  224. package/dist/replay.dom.d.ts +21 -0
  225. package/dist/replay.dom.js +388 -0
  226. package/dist/replay.js +579 -0
  227. package/dist/replay.types.d.ts +152 -0
  228. package/dist/replay.types.js +1 -0
  229. package/dist/restyle.d.ts +21 -0
  230. package/dist/restyle.js +70 -0
  231. package/dist/road.d.ts +26 -0
  232. package/dist/road.draw.d.ts +6 -0
  233. package/dist/road.draw.js +269 -0
  234. package/dist/road.js +59 -0
  235. package/dist/road.model.d.ts +63 -0
  236. package/dist/road.model.js +215 -0
  237. package/dist/road.style.d.ts +7 -0
  238. package/dist/road.style.js +26 -0
  239. package/dist/road.types.d.ts +122 -0
  240. package/dist/road.types.js +1 -0
  241. package/dist/scene-entry.d.ts +7 -0
  242. package/dist/scene-entry.js +5 -0
  243. package/dist/scene.css.d.ts +44 -0
  244. package/dist/scene.css.js +296 -0
  245. package/dist/scene.d.ts +27 -0
  246. package/dist/scene.fit.d.ts +12 -0
  247. package/dist/scene.fit.js +18 -0
  248. package/dist/scene.flat.d.ts +38 -0
  249. package/dist/scene.flat.js +167 -0
  250. package/dist/scene.js +420 -0
  251. package/dist/scene.path.d.ts +40 -0
  252. package/dist/scene.path.js +357 -0
  253. package/dist/scene.types.d.ts +172 -0
  254. package/dist/scene.types.js +1 -0
  255. package/dist/scene.xml.d.ts +31 -0
  256. package/dist/scene.xml.js +81 -0
  257. package/dist/score.d.ts +70 -0
  258. package/dist/score.js +212 -0
  259. package/dist/sets.board.d.ts +22 -0
  260. package/dist/sets.board.js +89 -0
  261. package/dist/sheet.d.ts +18 -0
  262. package/dist/sheet.js +38 -0
  263. package/dist/special.d.ts +44 -0
  264. package/dist/special.js +204 -0
  265. package/dist/special.style.d.ts +8 -0
  266. package/dist/special.style.js +36 -0
  267. package/dist/strings.d.ts +581 -0
  268. package/dist/strings.js +411 -0
  269. package/dist/style.d.ts +35 -0
  270. package/dist/style.js +177 -0
  271. package/dist/surfaces/baseball.d.ts +33 -0
  272. package/dist/surfaces/baseball.js +208 -0
  273. package/dist/surfaces/baseball.walls.d.ts +16 -0
  274. package/dist/surfaces/baseball.walls.js +150 -0
  275. package/dist/surfaces/basketball.d.ts +8 -0
  276. package/dist/surfaces/basketball.js +199 -0
  277. package/dist/surfaces/curling.d.ts +23 -0
  278. package/dist/surfaces/curling.js +128 -0
  279. package/dist/surfaces/field.d.ts +12 -0
  280. package/dist/surfaces/field.js +163 -0
  281. package/dist/surfaces/football.d.ts +12 -0
  282. package/dist/surfaces/football.js +208 -0
  283. package/dist/surfaces/hockey.d.ts +10 -0
  284. package/dist/surfaces/hockey.js +166 -0
  285. package/dist/surfaces/net.d.ts +7 -0
  286. package/dist/surfaces/net.js +151 -0
  287. package/dist/surfaces/soccer-providers.d.ts +124 -0
  288. package/dist/surfaces/soccer-providers.js +334 -0
  289. package/dist/surfaces/soccer-spec.d.ts +138 -0
  290. package/dist/surfaces/soccer-spec.js +175 -0
  291. package/dist/surfaces/soccer.d.ts +25 -0
  292. package/dist/surfaces/soccer.js +270 -0
  293. package/dist/surfaces/surface.d.ts +180 -0
  294. package/dist/surfaces/surface.js +49 -0
  295. package/dist/team.common.d.ts +75 -0
  296. package/dist/team.common.js +97 -0
  297. package/dist/team.formation.d.ts +24 -0
  298. package/dist/team.formation.js +121 -0
  299. package/dist/team.geometry.d.ts +66 -0
  300. package/dist/team.geometry.js +304 -0
  301. package/dist/team.layers.d.ts +16 -0
  302. package/dist/team.layers.js +32 -0
  303. package/dist/team.motion.d.ts +9 -0
  304. package/dist/team.motion.js +325 -0
  305. package/dist/team.network.d.ts +43 -0
  306. package/dist/team.network.js +215 -0
  307. package/dist/team.shape.d.ts +12 -0
  308. package/dist/team.shape.js +217 -0
  309. package/dist/team.types.d.ts +189 -0
  310. package/dist/team.types.js +1 -0
  311. package/dist/text.d.ts +31 -0
  312. package/dist/text.js +88 -0
  313. package/dist/themes.d.ts +14 -0
  314. package/dist/themes.js +24 -0
  315. package/dist/types.d.ts +565 -0
  316. package/dist/types.js +1 -0
  317. package/dist/units.d.ts +45 -0
  318. package/dist/units.js +90 -0
  319. package/dist/version.d.ts +2 -0
  320. package/dist/version.js +2 -0
  321. package/package.json +234 -4
@@ -0,0 +1,325 @@
1
+ // The layers that read movements (passes, carries, runs): a flow field, which draws the average direction of the movements that start in each cell of a
2
+ // grid as an arrow (a quiver plot), and a sonar, which draws a rose of how many movements go each way (or how long they are on average), for the whole
3
+ // surface, for each player, for each cell of a grid or for each zone. Written for this package from the plain arithmetic of vectors and angles; the
4
+ // ideas are those of mplsoccer's pass-flow and pass-sonar examples (MIT), and no code of it is used.
5
+ import { esc, num } from "./format.js";
6
+ import { buildZoneSet } from "./heat.zones.js";
7
+ import { isNum, newMade, opacityOf, place, placeBack, toArray, unitOfLayer } from "./layers.env.js";
8
+ import { headPath } from "./layers.marks.js";
9
+ import { fill } from "./strings.js";
10
+ import { attrs, frameNote, labelOf, round, teamClass, teamKey, teamLabel, titled, unitWord } from "./team.common.js";
11
+ import { FEET_PER } from "./units.js";
12
+ /** The movements of a layer that have a start and a way to go, put on the surface. A movement with no length is kept (it has no direction, and counts for nothing in a flow or a rose). */
13
+ function movesOf(layer, env, unit) {
14
+ const data = toArray(layer.data, `a ${layer.kind} layer`);
15
+ const keep = [];
16
+ const raw = [];
17
+ let skipped = 0;
18
+ for (const d of data) {
19
+ if (typeof d !== "object" || d === null || !isNum(d.x) || !isNum(d.y)) {
20
+ skipped += 1;
21
+ continue;
22
+ }
23
+ const end = isNum(d.x2) && isNum(d.y2) ? [d.x2, d.y2] : isNum(d.dx) && isNum(d.dy) ? [d.x + d.dx, d.y + d.dy] : undefined;
24
+ if (end === undefined) {
25
+ skipped += 1;
26
+ continue;
27
+ }
28
+ keep.push(d);
29
+ raw.push([d.x, d.y], end);
30
+ }
31
+ const at = place(layer, env, raw, unit);
32
+ const moves = keep.map((d, i) => {
33
+ const dx = at[2 * i + 1][0] - at[2 * i][0];
34
+ const dy = at[2 * i + 1][1] - at[2 * i][1];
35
+ return { d, x: at[2 * i][0], y: at[2 * i][1], dx, dy, len: Math.hypot(dx, dy) };
36
+ });
37
+ return { moves, skipped };
38
+ }
39
+ /** The team that colours a layer: the one it names, else the one all its movements share. */
40
+ function teamOf(layer, moves) {
41
+ if (typeof layer.team === "string")
42
+ return layer.team;
43
+ const teams = new Set(moves.map((m) => teamKey(m.d.team)));
44
+ return teams.size === 1 ? [...teams][0] : "";
45
+ }
46
+ /** The grid of a layer: the cells across and down, laid over the surface's box. */
47
+ function gridOf(bins, env, fallback) {
48
+ const { box } = env.outline;
49
+ let nx;
50
+ let ny;
51
+ if (Array.isArray(bins) && bins.length === 2 && isNum(bins[0]) && isNum(bins[1])) {
52
+ nx = Math.max(1, Math.min(200, Math.floor(bins[0])));
53
+ ny = Math.max(1, Math.min(200, Math.floor(bins[1])));
54
+ }
55
+ else {
56
+ const across = isNum(bins) && bins >= 1 ? Math.min(200, Math.floor(bins)) : fallback;
57
+ const side = Math.max(box.w, box.h) / across;
58
+ nx = Math.max(1, Math.ceil(box.w / side - 1e-9));
59
+ ny = Math.max(1, Math.ceil(box.h / side - 1e-9));
60
+ }
61
+ return { nx, ny, w: box.w / nx, h: box.h / ny };
62
+ }
63
+ const cellOf = (g, env, x, y) => {
64
+ const { box } = env.outline;
65
+ const i = Math.floor((x - box.x) / g.w);
66
+ const j = Math.floor((y - box.y) / g.h);
67
+ return i < 0 || j < 0 || i >= g.nx || j >= g.ny ? -1 : j * g.nx + i;
68
+ };
69
+ function computeFlow(layer, env) {
70
+ const unit = unitOfLayer(layer, env);
71
+ const { moves, skipped } = movesOf(layer, env, unit);
72
+ const grid = gridOf(layer.bins, env, 12);
73
+ const minCount = isNum(layer.minCount) && layer.minCount >= 1 ? Math.floor(layer.minCount) : 2;
74
+ const sums = Array.from({ length: grid.nx * grid.ny }, () => ({ n: 0, sx: 0, sy: 0, sl: 0 }));
75
+ for (const m of moves) {
76
+ if (m.len === 0)
77
+ continue;
78
+ const c = cellOf(grid, env, m.x, m.y);
79
+ if (c < 0)
80
+ continue;
81
+ sums[c].n += 1;
82
+ sums[c].sx += m.dx;
83
+ sums[c].sy += m.dy;
84
+ sums[c].sl += m.len;
85
+ }
86
+ const { box } = env.outline;
87
+ const cells = [];
88
+ sums.forEach((s, c) => {
89
+ if (s.n < minCount)
90
+ return;
91
+ const cx = box.x + ((c % grid.nx) + 0.5) * grid.w;
92
+ const cy = box.y + (Math.floor(c / grid.nx) + 0.5) * grid.h;
93
+ if (!env.outline.contains(cx, cy))
94
+ return;
95
+ const mx = s.sx / s.n;
96
+ const my = s.sy / s.n;
97
+ cells.push({ cx, cy, n: s.n, mx, my, length: s.sl / s.n, steady: s.sl === 0 ? 0 : Math.hypot(s.sx, s.sy) / s.sl });
98
+ });
99
+ return { cells, moves, skipped, grid, team: teamOf(layer, moves), longest: Math.max(0, ...cells.map((c) => Math.hypot(c.mx, c.my))) };
100
+ }
101
+ export function drawFlow(layer, env) {
102
+ const made = newMade();
103
+ const words = env.words.team;
104
+ const c = computeFlow(layer, env);
105
+ const unit = unitOfLayer(layer, env);
106
+ const k = FEET_PER[unit];
107
+ made.drawn = c.moves.length;
108
+ made.skipped = c.skipped;
109
+ made.cls = "ky-tm";
110
+ made.opacity = opacityOf(layer.opacity);
111
+ const fixed = layer.lengths === "fixed";
112
+ const cell = Math.min(c.grid.w, c.grid.h);
113
+ const width = env.base * 0.28;
114
+ made.style = `stroke-width:${num(width)}`;
115
+ // Arrows are written in a path each for shafts and heads, for each level of opacity.
116
+ const levels = new Map();
117
+ for (const f of c.cells) {
118
+ const m = Math.hypot(f.mx, f.my);
119
+ if (m === 0)
120
+ continue;
121
+ const u = [f.mx / m, f.my / m];
122
+ const len = fixed ? cell * 0.75 : Math.max(cell * 0.25, cell * 0.9 * (m / c.longest));
123
+ const a = [f.cx - (u[0] * len) / 2, f.cy - (u[1] * len) / 2];
124
+ const b = [f.cx + (u[0] * len) / 2, f.cy + (u[1] * len) / 2];
125
+ const hl = Math.min(len * 0.5, Math.max(width * 3.2, cell * 0.22));
126
+ const level = fixed ? Math.round((0.35 + 0.65 * f.steady) * 10) / 10 : 0.9;
127
+ const list = levels.get(level) ?? { shafts: [], heads: [] };
128
+ list.shafts.push(`M${num(a[0])} ${num(a[1])}L${num(b[0] - u[0] * hl * 0.8)} ${num(b[1] - u[1] * hl * 0.8)}`);
129
+ list.heads.push(headPath(b, u, hl, hl * 0.45, false));
130
+ levels.set(level, list);
131
+ }
132
+ const cls = teamClass(c.team);
133
+ const out = [];
134
+ for (const [level, list] of [...levels.entries()].sort((x, y) => x[0] - y[0]))
135
+ out.push(`<g${attrs(cls, "", level)}><path class="ky-ln" d="${list.shafts.join("")}"/><path class="ky-ah" d="${list.heads.join("")}"/></g>`);
136
+ made.marks = out.join("");
137
+ made.title = fill(words.flowTitle, { n: c.moves.length, cells: c.cells.length });
138
+ const parts = [];
139
+ if (c.cells.length > 0)
140
+ parts.push(fill(words.flowNote, { len: round(Math.max(...c.cells.map((f) => f.length)) / k, 1), unit: unitWord(unit, env) }));
141
+ if (c.skipped > 0)
142
+ parts.push(fill(env.words.layers.skipped, { n: c.skipped }));
143
+ made.text = parts.join(env.words.said.gap);
144
+ return made;
145
+ }
146
+ /** The direction of a vector on the surface, in degrees: 0 toward the right end as the surface is drawn wide, 90 toward the top edge, from 0 up to 360. */
147
+ export const degreesOf = (dx, dy) => {
148
+ const d = (Math.atan2(-dy, dx) * 180) / Math.PI;
149
+ return (d + 360) % 360;
150
+ };
151
+ export function flowTable(layer, env) {
152
+ const w = env.words.team;
153
+ const l = env.words.layers;
154
+ const c = computeFlow(layer, env);
155
+ const unit = unitOfLayer(layer, env);
156
+ const k = FEET_PER[unit];
157
+ const back = placeBack(layer, env, c.cells.map((f) => [f.cx, f.cy]), unit);
158
+ return [
159
+ {
160
+ head: [l.tableNo, l.tableX, l.tableY, l.tableCount, w.tableDirection, w.tableLength, w.tableSteady],
161
+ rows: c.cells.map((f, i) => [i + 1, round(back[i][0], 2), round(back[i][1], 2), f.n, Math.round(degreesOf(f.mx, f.my)), round(f.length / k, 2), Math.round(100 * f.steady)]),
162
+ title: typeof layer.title === "string" && layer.title !== "" ? layer.title : fill(w.flowTitle, { n: c.moves.length, cells: c.cells.length }),
163
+ note: [frameNote(layer, env), fill(w.tableUnit, { unit: unitWord(unit, env) })].filter((t) => t !== "").join(env.words.said.gap),
164
+ },
165
+ ];
166
+ }
167
+ function computeSonar(layer, env) {
168
+ const unit = unitOfLayer(layer, env);
169
+ const k = FEET_PER[unit];
170
+ const { moves, skipped: bad } = movesOf(layer, env, unit);
171
+ const by = layer.by === "player" || layer.by === "grid" || layer.by === "zone" ? layer.by : "all";
172
+ const angles = isNum(layer.angles) ? Math.max(3, Math.min(72, Math.floor(layer.angles))) : 12;
173
+ const statistic = layer.statistic === "mean" ? "mean" : "count";
174
+ const minCount = isNum(layer.minCount) && layer.minCount >= 1 ? Math.floor(layer.minCount) : 1;
175
+ const { box } = env.outline;
176
+ let skipped = bad;
177
+ let outside = 0;
178
+ const groups = new Map();
179
+ const add = (key, name, move, at) => {
180
+ const g = groups.get(key) ?? { name, moves: [], at };
181
+ g.moves.push(move);
182
+ groups.set(key, g);
183
+ };
184
+ let radius = Math.min(box.w, box.h) * 0.3;
185
+ if (by === "all")
186
+ for (const m of moves)
187
+ add("all", "", m);
188
+ else if (by === "player") {
189
+ radius = Math.min(box.w, box.h) * 0.1;
190
+ for (const m of moves) {
191
+ const id = m.d.id;
192
+ if (typeof id !== "string" && !isNum(id))
193
+ skipped += 1;
194
+ else
195
+ add(String(id), labelOf(m.d), m);
196
+ }
197
+ }
198
+ else if (by === "grid") {
199
+ const grid = gridOf(layer.bins, env, 6);
200
+ radius = Math.min(grid.w, grid.h) * 0.45;
201
+ for (const m of moves) {
202
+ const c = cellOf(grid, env, m.x, m.y);
203
+ if (c < 0)
204
+ outside += 1;
205
+ else
206
+ add(String(c), String(c + 1), m, [box.x + ((c % grid.nx) + 0.5) * grid.w, box.y + (Math.floor(c / grid.nx) + 0.5) * grid.h]);
207
+ }
208
+ }
209
+ else {
210
+ if (layer.zones === undefined)
211
+ throw new RangeError("a sonar by zone needs `zones`: the set of zones");
212
+ radius = Math.min(box.w, box.h) * 0.08;
213
+ const los = isNum(layer.los) ? place({ ...layer, limits: undefined }, env, [[layer.los, 0]], unit)[0][0] : undefined;
214
+ const set = buildZoneSet(layer.zones, { o: env.o, outline: env.outline, direction: layer.direction === "left" ? "left" : "right", end: layer.end === "left" || layer.end === "right" ? layer.end : "both", los, bats: layer.bats === "none" ? undefined : layer.bats === "L" ? "L" : "R", words: env.words.layers.zones });
215
+ for (const m of moves) {
216
+ const z = set.which(m.x, m.y);
217
+ if (z < 0)
218
+ outside += 1;
219
+ else
220
+ add(String(z), set.zones[z].name, m, [set.zones[z].label[0], set.zones[z].label[1]]);
221
+ }
222
+ }
223
+ if (isNum(layer.radius) && layer.radius > 0)
224
+ radius = layer.radius * k;
225
+ const step = 360 / angles;
226
+ const roses = [];
227
+ for (const g of groups.values()) {
228
+ const real = g.moves.filter((m) => m.len > 0);
229
+ if (real.length < minCount)
230
+ continue;
231
+ const bars = new Array(angles).fill(0);
232
+ const sums = new Array(angles).fill(0);
233
+ for (const m of real) {
234
+ const bin = Math.floor(((degreesOf(m.dx, m.dy) + step / 2) % 360) / step);
235
+ bars[bin] += 1;
236
+ sums[bin] += m.len / k;
237
+ }
238
+ const values = statistic === "mean" ? bars.map((n, i) => (n === 0 ? 0 : sums[i] / n)) : bars;
239
+ const centre = g.at ?? [real.reduce((s, m) => s + m.x, 0) / real.length, real.reduce((s, m) => s + m.y, 0) / real.length];
240
+ roses.push({ name: g.name, cx: centre[0], cy: centre[1], moves: real, radius, bars: values, count: real.length, mean: real.reduce((s, m) => s + m.len, 0) / real.length / k });
241
+ }
242
+ const peak = Math.max(0, ...roses.flatMap((r) => r.bars));
243
+ return { roses, moves, skipped, outside, angles, team: teamOf(layer, moves), peak, unit };
244
+ }
245
+ const wedge = (cx, cy, r, from, to) => {
246
+ const a = (from * Math.PI) / 180;
247
+ const b = (to * Math.PI) / 180;
248
+ const p = (t) => `${num(cx + r * Math.cos(t))} ${num(cy - r * Math.sin(t))}`;
249
+ // The surface's y runs down, so a larger angle is a turn to the left as seen: the arc's sweep flag is 0.
250
+ return `M${num(cx)} ${num(cy)}L${p(a)}A${num(r)} ${num(r)} 0 ${to - from > 180 ? 1 : 0} 0 ${p(b)}Z`;
251
+ };
252
+ export function drawSonar(layer, env) {
253
+ const made = newMade();
254
+ const words = env.words.team;
255
+ const c = computeSonar(layer, env);
256
+ made.drawn = c.moves.length;
257
+ made.skipped = c.skipped;
258
+ made.cls = "ky-tm";
259
+ made.opacity = opacityOf(layer.opacity);
260
+ made.style = `--w:${num(env.base * 0.1)}`;
261
+ const step = 360 / c.angles;
262
+ const cls = teamClass(c.team);
263
+ const out = [];
264
+ let commonest = { deg: 0, n: 0 };
265
+ for (const r of c.roses) {
266
+ const bars = [];
267
+ let best = 0;
268
+ r.bars.forEach((v, i) => {
269
+ if (v > r.bars[best])
270
+ best = i;
271
+ if (v <= 0 || c.peak === 0)
272
+ return;
273
+ const from = i * step - step / 2;
274
+ const to = i * step + step / 2;
275
+ bars.push(titled("path", ` class="ky-ro" d="${wedge(r.cx, r.cy, (v / c.peak) * r.radius, from, to)}"`, fill(words.barTitle, { from: round(((from % 360) + 360) % 360, 0), to: round(to % 360, 0), value: round(v, 1) })));
276
+ });
277
+ const deg = Math.round(best * step);
278
+ if (r.bars[best] > commonest.n)
279
+ commonest = { deg, n: Math.round(r.bars[best]) };
280
+ const title = fill(words.roseTitle, { name: r.name === "" ? env.words.team.hullAll : r.name, n: r.count, deg });
281
+ out.push(`<g${attrs(cls, "")}><title>${esc(title)}</title><circle class="ky-ro-r" cx="${num(r.cx)}" cy="${num(r.cy)}" r="${num(r.radius)}"/>${bars.join("")}</g>`);
282
+ }
283
+ made.marks = out.join("");
284
+ made.title = fill(words.sonarTitle, { n: c.moves.length, roses: c.roses.length, angles: c.angles });
285
+ const parts = [];
286
+ if (c.roses.length > 0)
287
+ parts.push(fill(words.sonarNote, { deg: commonest.deg, n: commonest.n }), words.sonarAngles);
288
+ if (c.skipped > 0)
289
+ parts.push(fill(env.words.layers.skipped, { n: c.skipped }));
290
+ if (c.outside > 0)
291
+ parts.push(fill(env.words.layers.outside, { n: c.outside }));
292
+ made.text = parts.join(env.words.said.gap);
293
+ return made;
294
+ }
295
+ export function sonarTables(layer, env) {
296
+ const w = env.words.team;
297
+ const l = env.words.layers;
298
+ const c = computeSonar(layer, env);
299
+ const unit = c.unit;
300
+ const step = 360 / c.angles;
301
+ const back = placeBack(layer, env, c.roses.map((r) => [r.cx, r.cy]), unit);
302
+ const title = typeof layer.title === "string" && layer.title !== "" ? layer.title : fill(w.sonarTitle, { n: c.moves.length, roses: c.roses.length, angles: c.angles });
303
+ const named = (r, i) => (r.name !== "" ? r.name : c.roses.length > 1 ? String(i + 1) : teamLabel(c.team, env));
304
+ const rows = [];
305
+ c.roses.forEach((r, i) => {
306
+ r.bars.forEach((v, bin) => {
307
+ if (v > 0)
308
+ rows.push([named(r, i), round(((bin * step - step / 2 + 360) % 360), 1), round(bin * step + step / 2, 1) % 360, round(v, 2)]);
309
+ });
310
+ });
311
+ return [
312
+ {
313
+ head: [l.tableNo, w.tableRose, w.tableFromAngle, w.tableToAngle, layer.statistic === "mean" ? w.tableLength : l.tableCount],
314
+ rows: rows.map((r, i) => [i + 1, ...r]),
315
+ title,
316
+ note: [frameNote(layer, env), fill(w.tableUnit, { unit: unitWord(unit, env) }), w.sonarAngles].filter((t) => t !== "").join(env.words.said.gap),
317
+ },
318
+ {
319
+ head: [l.tableNo, w.tableRose, l.tableX, l.tableY, l.tableCount, w.tableLength],
320
+ rows: c.roses.map((r, i) => [i + 1, named(r, i), round(back[i][0], 2), round(back[i][1], 2), r.count, round(r.mean, 2)]),
321
+ title: `${title}${env.words.said.colon}${w.tableRose}`,
322
+ note: "",
323
+ },
324
+ ];
325
+ }
@@ -0,0 +1,43 @@
1
+ import { type Env, type Made } from "./layers.env.ts";
2
+ import { type P } from "./layers.marks.ts";
3
+ import { type TeamTable } from "./team.common.ts";
4
+ import type { NetworkLayer } from "./team.types.ts";
5
+ /** A player of the network. */
6
+ export interface Node {
7
+ key: string;
8
+ id: string | number;
9
+ team: string;
10
+ name: string;
11
+ number: string;
12
+ made: number;
13
+ received: number;
14
+ touches: number;
15
+ /** Where he is, on the surface (feet), or undefined with no place to average. */
16
+ at: P | undefined;
17
+ /** Where he is, in the layer's own numbers. */
18
+ given: P | undefined;
19
+ }
20
+ /** A link between two players. */
21
+ export interface Link {
22
+ a: Node;
23
+ b: Node;
24
+ n: number;
25
+ team: string;
26
+ }
27
+ /** What a network worked out from its passes. */
28
+ export interface Network {
29
+ nodes: Node[];
30
+ links: Link[];
31
+ passes: number;
32
+ skipped: number;
33
+ /** Passes between players with no place, which no link can be drawn for. */
34
+ unplaced: number;
35
+ minPasses: number;
36
+ directed: boolean;
37
+ }
38
+ /** Count the passes into nodes and links, average the places and put them on the surface. */
39
+ export declare function computeNetwork(layer: NetworkLayer, env: Env): Network;
40
+ /** What a player is called in a sentence: his name, else his number, else his id. */
41
+ export declare const nodeName: (n: Node) => string;
42
+ export declare function drawNetwork(layer: NetworkLayer, env: Env): Made;
43
+ export declare function networkTables(layer: NetworkLayer, env: Env): TeamTable[];
@@ -0,0 +1,215 @@
1
+ // The pass network: a node for each player at the average place of the passes he made and received, sized by touches, and a link for each pair of
2
+ // players sized and shaded by the passes between them. Written for this package from the plain arithmetic of counting and averaging; the idea
3
+ // is that of mplsoccer's pass-network example (MIT), and no code of it is used.
4
+ import { esc, num } from "./format.js";
5
+ import { isNum, newMade, opacityOf, place, toArray, unitOfLayer } from "./layers.env.js";
6
+ import { curveBetween, curvePath, headPath } from "./layers.marks.js";
7
+ import { fill } from "./strings.js";
8
+ import { attrs, frameNote, round, teamClass, teamKey, titled } from "./team.common.js";
9
+ import { FEET_PER } from "./units.js";
10
+ const idText = (id) => String(id);
11
+ /** Count the passes into nodes and links, average the places and put them on the surface. */
12
+ export function computeNetwork(layer, env) {
13
+ const unit = unitOfLayer(layer, env);
14
+ const data = toArray(layer.data, "a network layer");
15
+ const directed = layer.directed === true;
16
+ const minPasses = isNum(layer.minPasses) && layer.minPasses > 1 ? Math.floor(layer.minPasses) : 1;
17
+ const nodes = new Map();
18
+ const nodeFor = (team, id) => {
19
+ const key = `${team}\u0000${idText(id)}`;
20
+ let n = nodes.get(key);
21
+ if (n === undefined) {
22
+ n = { key, id, team, name: "", number: "", made: 0, received: 0, touches: 0, at: undefined, given: undefined };
23
+ nodes.set(key, n);
24
+ }
25
+ return n;
26
+ };
27
+ const counts = new Map();
28
+ const raw = [];
29
+ const owner = [];
30
+ let passes = 0;
31
+ let skipped = 0;
32
+ for (const d of data) {
33
+ const ok = typeof d === "object" && d !== null && (typeof d.from === "string" || isNum(d.from)) && (typeof d.to === "string" || isNum(d.to)) && idText(d.from) !== idText(d.to);
34
+ if (!ok) {
35
+ skipped += 1;
36
+ continue;
37
+ }
38
+ const team = teamKey(d.team);
39
+ const a = nodeFor(team, d.from);
40
+ const b = nodeFor(team, d.to);
41
+ passes += 1;
42
+ a.made += 1;
43
+ b.received += 1;
44
+ if (typeof d.fromName === "string" && d.fromName !== "")
45
+ a.name = d.fromName;
46
+ if (typeof d.toName === "string" && d.toName !== "")
47
+ b.name = d.toName;
48
+ if (d.fromNumber !== undefined)
49
+ a.number = String(d.fromNumber);
50
+ if (d.toNumber !== undefined)
51
+ b.number = String(d.toNumber);
52
+ if (isNum(d.x) && isNum(d.y)) {
53
+ raw.push([d.x, d.y]);
54
+ owner.push(a);
55
+ }
56
+ if (isNum(d.x2) && isNum(d.y2)) {
57
+ raw.push([d.x2, d.y2]);
58
+ owner.push(b);
59
+ }
60
+ const [lo, hi] = directed || idText(d.from) <= idText(d.to) ? [a, b] : [b, a];
61
+ const key = `${lo.key}\u0001${hi.key}`;
62
+ const link = counts.get(key);
63
+ if (link === undefined)
64
+ counts.set(key, { a: lo, b: hi, n: 1, team });
65
+ else
66
+ link.n += 1;
67
+ }
68
+ const at = place(layer, env, raw, unit);
69
+ const sums = new Map();
70
+ raw.forEach((r, i) => {
71
+ const s = sums.get(owner[i]) ?? { x: 0, y: 0, n: 0, gx: 0, gy: 0 };
72
+ s.x += at[i][0];
73
+ s.y += at[i][1];
74
+ s.gx += r[0];
75
+ s.gy += r[1];
76
+ s.n += 1;
77
+ sums.set(owner[i], s);
78
+ });
79
+ for (const [node, s] of sums) {
80
+ node.at = [s.x / s.n, s.y / s.n];
81
+ node.given = [s.gx / s.n, s.gy / s.n];
82
+ }
83
+ // Places given for some players win over the averages.
84
+ const given = (layer.nodes ?? []).filter((n) => typeof n === "object" && n !== null && isNum(n.x) && isNum(n.y) && (typeof n.id === "string" || isNum(n.id)));
85
+ if (given.length > 0) {
86
+ const placed = place(layer, env, given.map((n) => [n.x, n.y]), unit);
87
+ given.forEach((n, i) => {
88
+ const node = nodes.get(`${teamKey(n.team)}\u0000${idText(n.id)}`);
89
+ if (node === undefined)
90
+ return;
91
+ node.at = placed[i];
92
+ node.given = [n.x, n.y];
93
+ if (typeof n.name === "string" && n.name !== "")
94
+ node.name = n.name;
95
+ if (n.number !== undefined)
96
+ node.number = String(n.number);
97
+ });
98
+ }
99
+ for (const n of nodes.values())
100
+ n.touches = n.made + n.received;
101
+ const all = [...counts.values()];
102
+ const unplaced = all.filter((l) => l.a.at === undefined || l.b.at === undefined).reduce((s, l) => s + l.n, 0);
103
+ const links = all.filter((l) => l.n >= minPasses && l.a.at !== undefined && l.b.at !== undefined);
104
+ const placedNodes = [...nodes.values()].filter((n) => n.at !== undefined);
105
+ return { nodes: placedNodes, links, passes, skipped, unplaced, minPasses, directed };
106
+ }
107
+ /** What a player is called in a sentence: his name, else his number, else his id. */
108
+ export const nodeName = (n) => (n.name !== "" ? n.name : n.number !== "" ? n.number : idText(n.id));
109
+ /** The most touches of any node, and the strongest link. */
110
+ function leaders(net) {
111
+ let busiest;
112
+ for (const n of net.nodes)
113
+ if (busiest === undefined || n.touches > busiest.touches)
114
+ busiest = n;
115
+ let strongest;
116
+ for (const l of net.links)
117
+ if (strongest === undefined || l.n > strongest.n)
118
+ strongest = l;
119
+ return { busiest, strongest };
120
+ }
121
+ /** A value of `[low, high]` the given fraction of the way through, by area (the square root of the squares) for a width. */
122
+ const between = (range, t, byArea) => (byArea ? Math.sqrt(range[0] ** 2 + (range[1] ** 2 - range[0] ** 2) * t) : range[0] + (range[1] - range[0]) * t);
123
+ const rangeOf = (given, fallback, k) => Array.isArray(given) && given.length === 2 && isNum(given[0]) && isNum(given[1]) && given[0] > 0 && given[1] > 0 ? [Math.min(given[0], given[1]) * k, Math.max(given[0], given[1]) * k] : [fallback[0], fallback[1]];
124
+ export function drawNetwork(layer, env) {
125
+ const made = newMade();
126
+ const words = env.words.team;
127
+ const net = computeNetwork(layer, env);
128
+ const k = FEET_PER[unitOfLayer(layer, env)];
129
+ const base = env.base;
130
+ const size = rangeOf(layer.nodeSize, [base * 1.3, base * 3.2], k);
131
+ const width = rangeOf(layer.linkWidth, [base * 0.1, base * 0.5], k);
132
+ const alpha = Array.isArray(layer.linkOpacity) && layer.linkOpacity.length === 2 && isNum(layer.linkOpacity[0]) && isNum(layer.linkOpacity[1]) ? [Math.max(0, Math.min(1, layer.linkOpacity[0])), Math.max(0, Math.min(1, layer.linkOpacity[1]))] : [0.3, 0.9];
133
+ const touchLo = Math.min(...net.nodes.map((n) => n.touches));
134
+ const touchHi = Math.max(...net.nodes.map((n) => n.touches));
135
+ const passLo = Math.min(...net.links.map((l) => l.n));
136
+ const passHi = Math.max(...net.links.map((l) => l.n));
137
+ const nodeWidth = (n) => between(size, touchHi === touchLo ? 0.5 : (n.touches - touchLo) / (touchHi - touchLo), true);
138
+ const linkT = (l) => (passHi === passLo ? 0.5 : (l.n - passLo) / (passHi - passLo));
139
+ made.drawn = net.passes;
140
+ made.skipped = net.skipped;
141
+ made.cls = "ky-tm";
142
+ made.opacity = opacityOf(layer.opacity);
143
+ made.style = `--w:${num(base * 0.12)}`;
144
+ const links = [];
145
+ for (const l of net.links) {
146
+ const a = l.a.at;
147
+ const b = l.b.at;
148
+ if (a[0] === b[0] && a[1] === b[1])
149
+ continue;
150
+ const w = between(width, linkT(l), false);
151
+ const cls = teamClass(l.team);
152
+ const o = between(alpha, linkT(l), false);
153
+ const names = { a: nodeName(l.a), b: nodeName(l.b), n: l.n };
154
+ if (net.directed) {
155
+ const curve = curveBetween(a, b, 0.14);
156
+ const hl = Math.max(w * 3.4, base * 0.9);
157
+ const stop = nodeWidth(l.b) / 2;
158
+ const shaft = curve.trim(stop + hl * 0.9);
159
+ const head = headPath(curve.at(Math.max(0, curve.length - stop)), curve.tangent(Math.max(0, curve.length - stop)), hl, hl * 0.5, false);
160
+ links.push(`<g${attrs(cls, "", o)}><title>${esc(fill(words.linkTitleDirected, names))}</title><path class="ky-ln" stroke-width="${num(w)}" d="${curvePath(shaft)}"/><path class="ky-ah" d="${head}"/></g>`);
161
+ }
162
+ else
163
+ links.push(titled("path", `${attrs(`ky-ln${cls === "" ? "" : ` ${cls}`}`, "", o)} stroke-width="${num(w)}" d="M${num(a[0])} ${num(a[1])}L${num(b[0])} ${num(b[1])}"`, fill(words.linkTitle, names)));
164
+ }
165
+ const nodes = net.nodes.map((n) => {
166
+ const at = n.at;
167
+ const cls = teamClass(n.team);
168
+ return titled("circle", `${attrs(cls, "")} cx="${num(at[0])}" cy="${num(at[1])}" r="${num(nodeWidth(n) / 2)}"`, fill(words.nodeTitle, { name: nodeName(n), touches: n.touches, made: n.made, received: n.received }));
169
+ });
170
+ const mode = layer.labels === "name" || layer.labels === "id" || layer.labels === "none" || layer.labels === "number" ? layer.labels : "number";
171
+ const text = [];
172
+ if (mode !== "none") {
173
+ for (const n of net.nodes) {
174
+ const at = n.at;
175
+ const label = mode === "name" ? (n.name !== "" ? n.name : idText(n.id)) : mode === "id" ? idText(n.id) : n.number !== "" ? n.number : idText(n.id);
176
+ const r = nodeWidth(n) / 2;
177
+ const fs = Math.min(r * 1.15, (r * 2 * 0.9) / Math.max(1.2, label.length * 0.62));
178
+ const angle = env.turned ? ` transform="rotate(-90 ${num(at[0])} ${num(at[1])})"` : "";
179
+ text.push(`<text class="ky-lt" style="font-size:${num(fs)}px" x="${num(at[0])}" y="${num(at[1] + fs * 0.36)}"${angle}>${esc(label)}</text>`);
180
+ }
181
+ }
182
+ made.marks = `<g class="ky-nl">${links.join("")}</g>${nodes.length === 0 ? "" : `<g class="ky-pts">${nodes.join("")}</g>`}${text.length === 0 ? "" : `<g text-anchor="middle">${text.join("")}</g>`}`;
183
+ made.title = fill(words.networkTitle, { players: net.nodes.length, links: net.links.length, passes: net.passes });
184
+ const { busiest, strongest } = leaders(net);
185
+ const parts = [];
186
+ if (busiest !== undefined && strongest !== undefined)
187
+ parts.push(fill(net.directed ? words.networkNoteDirected : words.networkNote, { name: nodeName(busiest), touches: busiest.touches, a: nodeName(strongest.a), b: nodeName(strongest.b), n: strongest.n }));
188
+ if (net.minPasses > 1)
189
+ parts.push(fill(words.networkMin, { n: net.minPasses }));
190
+ if (net.skipped > 0)
191
+ parts.push(fill(env.words.layers.skipped, { n: net.skipped }));
192
+ made.text = parts.join(env.words.said.gap);
193
+ return made;
194
+ }
195
+ export function networkTables(layer, env) {
196
+ const w = env.words.team;
197
+ const l = env.words.layers;
198
+ const net = computeNetwork(layer, env);
199
+ const title = typeof layer.title === "string" && layer.title !== "" ? layer.title : fill(w.networkTitle, { players: net.nodes.length, links: net.links.length, passes: net.passes });
200
+ const ranked = [...net.nodes].sort((a, b) => b.touches - a.touches);
201
+ return [
202
+ {
203
+ head: [l.tableNo, w.tablePlayer, l.tableTeam, w.tableTouches, w.tableMade, w.tableReceived, l.tableX, l.tableY],
204
+ rows: ranked.map((n, i) => [i + 1, nodeName(n), n.team, n.touches, n.made, n.received, n.given === undefined ? null : round(n.given[0], 2), n.given === undefined ? null : round(n.given[1], 2)]),
205
+ title,
206
+ note: [frameNote(layer, env), net.minPasses > 1 ? fill(w.networkMin, { n: net.minPasses }) : ""].filter((t) => t !== "").join(env.words.said.gap),
207
+ },
208
+ {
209
+ head: [l.tableNo, w.tableFrom, w.tableTo, l.tableTeam, w.tablePasses],
210
+ rows: [...net.links].sort((a, b) => b.n - a.n).map((link, i) => [i + 1, nodeName(link.a), nodeName(link.b), link.team, link.n]),
211
+ title: `${title}${env.words.said.colon}${w.tablePasses}`,
212
+ note: "",
213
+ },
214
+ ];
215
+ }
@@ -0,0 +1,12 @@
1
+ import { type Env, type Made } from "./layers.env.ts";
2
+ import type { P } from "./layers.marks.ts";
3
+ import { type TeamTable } from "./team.common.ts";
4
+ import type { DelaunayLayer, HullLayer, VoronoiLayer } from "./team.types.ts";
5
+ /** The share of the surface (0 to 1) nearer each site than any other, counted on a grid of cells laid over the surface and kept where the surface is. A repeated site has nothing. */
6
+ export declare function surfaceShares(sites: readonly P[], env: Env, across?: number): number[];
7
+ export declare function drawVoronoi(layer: VoronoiLayer, env: Env): Made;
8
+ export declare function voronoiTable(layer: VoronoiLayer, env: Env): TeamTable[];
9
+ export declare function drawDelaunay(layer: DelaunayLayer, env: Env): Made;
10
+ export declare function delaunayTable(layer: DelaunayLayer, env: Env): TeamTable[];
11
+ export declare function drawHull(layer: HullLayer, env: Env): Made;
12
+ export declare function hullTable(layer: HullLayer, env: Env): TeamTable[];