@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.
- package/CHANGELOG.md +129 -0
- package/LICENSE +21 -0
- package/NOTICE.md +293 -0
- package/README.md +600 -2
- package/dist/annotate.d.ts +47 -0
- package/dist/annotate.js +349 -0
- package/dist/atlas-entry.d.ts +4 -0
- package/dist/atlas-entry.js +3 -0
- package/dist/atlas.d.ts +131 -0
- package/dist/atlas.js +149 -0
- package/dist/background.d.ts +56 -0
- package/dist/background.js +127 -0
- package/dist/ballpark.d.ts +48 -0
- package/dist/ballpark.js +129 -0
- package/dist/canvas-entry.d.ts +2 -0
- package/dist/canvas-entry.js +2 -0
- package/dist/canvas.d.ts +85 -0
- package/dist/canvas.js +279 -0
- package/dist/charts-entry.d.ts +10 -0
- package/dist/charts-entry.js +8 -0
- package/dist/charts.baseball.d.ts +30 -0
- package/dist/charts.baseball.js +152 -0
- package/dist/charts.curling.d.ts +52 -0
- package/dist/charts.curling.js +196 -0
- package/dist/charts.d.ts +172 -0
- package/dist/charts.js +508 -0
- package/dist/charts.network.d.ts +66 -0
- package/dist/charts.network.js +64 -0
- package/dist/charts.soccer.d.ts +43 -0
- package/dist/charts.soccer.js +191 -0
- package/dist/charts.types.d.ts +396 -0
- package/dist/charts.types.js +1 -0
- package/dist/colour.d.ts +29 -0
- package/dist/colour.js +97 -0
- package/dist/common.d.ts +14 -0
- package/dist/common.js +32 -0
- package/dist/court.d.ts +89 -0
- package/dist/court.js +248 -0
- package/dist/courts.style.d.ts +20 -0
- package/dist/courts.style.js +54 -0
- package/dist/cricket.board.d.ts +18 -0
- package/dist/cricket.board.js +67 -0
- package/dist/curling.board.d.ts +24 -0
- package/dist/curling.board.js +147 -0
- package/dist/d3-entry.d.ts +3 -0
- package/dist/d3-entry.js +2 -0
- package/dist/d3.d.ts +45 -0
- package/dist/d3.js +56 -0
- package/dist/draw.d.ts +52 -0
- package/dist/draw.js +705 -0
- package/dist/element-define.d.ts +2 -0
- package/dist/element-define.js +4 -0
- package/dist/element-entry.d.ts +1 -0
- package/dist/element-entry.js +2 -0
- package/dist/element.d.ts +39 -0
- package/dist/element.js +321 -0
- package/dist/eras-entry.d.ts +2 -0
- package/dist/eras-entry.js +2 -0
- package/dist/eras.d.ts +204 -0
- package/dist/eras.js +396 -0
- package/dist/events-entry.d.ts +3 -0
- package/dist/events-entry.js +3 -0
- package/dist/events.d.ts +54 -0
- package/dist/events.data.d.ts +59 -0
- package/dist/events.data.js +297 -0
- package/dist/events.js +127 -0
- package/dist/features.d.ts +31 -0
- package/dist/features.js +284 -0
- package/dist/field.score.d.ts +5 -0
- package/dist/field.score.js +33 -0
- package/dist/fields/afl.d.ts +11 -0
- package/dist/fields/afl.js +103 -0
- package/dist/fields/cricket.d.ts +9 -0
- package/dist/fields/cricket.js +81 -0
- package/dist/fields/fieldhockey.d.ts +6 -0
- package/dist/fields/fieldhockey.js +81 -0
- package/dist/fields/gaelic.d.ts +10 -0
- package/dist/fields/gaelic.js +86 -0
- package/dist/fields/handball.d.ts +6 -0
- package/dist/fields/handball.js +85 -0
- package/dist/fields/lacrosse.d.ts +17 -0
- package/dist/fields/lacrosse.js +169 -0
- package/dist/fields/rugby.d.ts +10 -0
- package/dist/fields/rugby.js +130 -0
- package/dist/fields.d.ts +12 -0
- package/dist/fields.js +44 -0
- package/dist/fields.kit.d.ts +63 -0
- package/dist/fields.kit.js +108 -0
- package/dist/fields.style.d.ts +4 -0
- package/dist/fields.style.js +19 -0
- package/dist/fields.types.d.ts +155 -0
- package/dist/fields.types.js +1 -0
- package/dist/format.d.ts +10 -0
- package/dist/format.js +28 -0
- package/dist/formations.d.ts +18 -0
- package/dist/formations.js +211 -0
- package/dist/frames-entry.d.ts +8 -0
- package/dist/frames-entry.js +7 -0
- package/dist/frames.d.ts +199 -0
- package/dist/frames.js +271 -0
- package/dist/frames.providers.d.ts +16 -0
- package/dist/frames.providers.js +302 -0
- package/dist/geojson-entry.d.ts +2 -0
- package/dist/geojson-entry.js +2 -0
- package/dist/geojson.d.ts +79 -0
- package/dist/geojson.js +147 -0
- package/dist/geometry-entry.d.ts +7 -0
- package/dist/geometry-entry.js +5 -0
- package/dist/geometry.d.ts +295 -0
- package/dist/geometry.js +361 -0
- package/dist/grounds-entry.d.ts +4 -0
- package/dist/grounds-entry.js +3 -0
- package/dist/grounds.d.ts +134 -0
- package/dist/grounds.data.d.ts +2 -0
- package/dist/grounds.data.js +1849 -0
- package/dist/grounds.js +74 -0
- package/dist/heat.colour.d.ts +37 -0
- package/dist/heat.colour.js +54 -0
- package/dist/heat.d.ts +43 -0
- package/dist/heat.js +614 -0
- package/dist/heat.stats.d.ts +123 -0
- package/dist/heat.stats.js +413 -0
- package/dist/heat.types.d.ts +145 -0
- package/dist/heat.types.js +1 -0
- package/dist/heat.zones.d.ts +54 -0
- package/dist/heat.zones.js +424 -0
- package/dist/homeside.d.ts +16 -0
- package/dist/homeside.js +43 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +29 -0
- package/dist/layers-entry.d.ts +19 -0
- package/dist/layers-entry.js +11 -0
- package/dist/layers.d.ts +41 -0
- package/dist/layers.env.d.ts +72 -0
- package/dist/layers.env.js +79 -0
- package/dist/layers.js +533 -0
- package/dist/layers.marks.d.ts +45 -0
- package/dist/layers.marks.js +168 -0
- package/dist/layers.types.d.ts +226 -0
- package/dist/layers.types.js +1 -0
- package/dist/layout.d.ts +97 -0
- package/dist/layout.js +381 -0
- package/dist/layout.style.d.ts +6 -0
- package/dist/layout.style.js +17 -0
- package/dist/layouts-entry.d.ts +5 -0
- package/dist/layouts-entry.js +4 -0
- package/dist/leagues/aussie.d.ts +57 -0
- package/dist/leagues/aussie.js +36 -0
- package/dist/leagues/baseball.d.ts +58 -0
- package/dist/leagues/baseball.js +171 -0
- package/dist/leagues/basketball.d.ts +67 -0
- package/dist/leagues/basketball.js +128 -0
- package/dist/leagues/courts.d.ts +212 -0
- package/dist/leagues/courts.js +114 -0
- package/dist/leagues/cricket.d.ts +45 -0
- package/dist/leagues/cricket.js +34 -0
- package/dist/leagues/curling.d.ts +64 -0
- package/dist/leagues/curling.js +53 -0
- package/dist/leagues/fieldhockey.d.ts +48 -0
- package/dist/leagues/fieldhockey.js +29 -0
- package/dist/leagues/fields.d.ts +10 -0
- package/dist/leagues/fields.js +6 -0
- package/dist/leagues/football.d.ts +8 -0
- package/dist/leagues/football.js +82 -0
- package/dist/leagues/gaelic.d.ts +50 -0
- package/dist/leagues/gaelic.js +29 -0
- package/dist/leagues/handball.d.ts +45 -0
- package/dist/leagues/handball.js +32 -0
- package/dist/leagues/hockey.d.ts +63 -0
- package/dist/leagues/hockey.js +166 -0
- package/dist/leagues/lacrosse.d.ts +103 -0
- package/dist/leagues/lacrosse.js +175 -0
- package/dist/leagues/rugby.d.ts +59 -0
- package/dist/leagues/rugby.js +72 -0
- package/dist/leagues/sources.d.ts +18 -0
- package/dist/leagues/sources.js +95 -0
- package/dist/leagues/types.d.ts +43 -0
- package/dist/leagues/types.js +5 -0
- package/dist/leagues-entry.d.ts +23 -0
- package/dist/leagues-entry.js +15 -0
- package/dist/leagues.d.ts +172 -0
- package/dist/leagues.js +462 -0
- package/dist/look.d.ts +50 -0
- package/dist/look.js +186 -0
- package/dist/mark.d.ts +35 -0
- package/dist/mark.js +59 -0
- package/dist/mount-entry.d.ts +2 -0
- package/dist/mount-entry.js +2 -0
- package/dist/mount.d.ts +63 -0
- package/dist/mount.js +167 -0
- package/dist/mow.d.ts +36 -0
- package/dist/mow.js +111 -0
- package/dist/names.d.ts +77 -0
- package/dist/names.js +97 -0
- package/dist/outline.d.ts +25 -0
- package/dist/outline.js +112 -0
- package/dist/parks-entry.d.ts +4 -0
- package/dist/parks-entry.js +3 -0
- package/dist/parks.d.ts +200 -0
- package/dist/parks.data.d.ts +2 -0
- package/dist/parks.data.js +4489 -0
- package/dist/parks.js +92 -0
- package/dist/plot-entry.d.ts +2 -0
- package/dist/plot-entry.js +2 -0
- package/dist/plot.d.ts +74 -0
- package/dist/plot.js +68 -0
- package/dist/png-entry.d.ts +2 -0
- package/dist/png-entry.js +2 -0
- package/dist/png.d.ts +26 -0
- package/dist/png.js +46 -0
- package/dist/ranges.d.ts +33 -0
- package/dist/ranges.js +178 -0
- package/dist/ranges.names.d.ts +31 -0
- package/dist/ranges.names.js +65 -0
- package/dist/react-entry.d.ts +2 -0
- package/dist/react-entry.js +2 -0
- package/dist/react.d.ts +53 -0
- package/dist/react.js +58 -0
- package/dist/replay-entry.d.ts +5 -0
- package/dist/replay-entry.js +4 -0
- package/dist/replay.control.d.ts +47 -0
- package/dist/replay.control.js +184 -0
- package/dist/replay.d.ts +170 -0
- package/dist/replay.dom.d.ts +21 -0
- package/dist/replay.dom.js +388 -0
- package/dist/replay.js +579 -0
- package/dist/replay.types.d.ts +152 -0
- package/dist/replay.types.js +1 -0
- package/dist/restyle.d.ts +21 -0
- package/dist/restyle.js +70 -0
- package/dist/road.d.ts +26 -0
- package/dist/road.draw.d.ts +6 -0
- package/dist/road.draw.js +269 -0
- package/dist/road.js +59 -0
- package/dist/road.model.d.ts +63 -0
- package/dist/road.model.js +215 -0
- package/dist/road.style.d.ts +7 -0
- package/dist/road.style.js +26 -0
- package/dist/road.types.d.ts +122 -0
- package/dist/road.types.js +1 -0
- package/dist/scene-entry.d.ts +7 -0
- package/dist/scene-entry.js +5 -0
- package/dist/scene.css.d.ts +44 -0
- package/dist/scene.css.js +296 -0
- package/dist/scene.d.ts +27 -0
- package/dist/scene.fit.d.ts +12 -0
- package/dist/scene.fit.js +18 -0
- package/dist/scene.flat.d.ts +38 -0
- package/dist/scene.flat.js +167 -0
- package/dist/scene.js +420 -0
- package/dist/scene.path.d.ts +40 -0
- package/dist/scene.path.js +357 -0
- package/dist/scene.types.d.ts +172 -0
- package/dist/scene.types.js +1 -0
- package/dist/scene.xml.d.ts +31 -0
- package/dist/scene.xml.js +81 -0
- package/dist/score.d.ts +70 -0
- package/dist/score.js +212 -0
- package/dist/sets.board.d.ts +22 -0
- package/dist/sets.board.js +89 -0
- package/dist/sheet.d.ts +18 -0
- package/dist/sheet.js +38 -0
- package/dist/special.d.ts +44 -0
- package/dist/special.js +204 -0
- package/dist/special.style.d.ts +8 -0
- package/dist/special.style.js +36 -0
- package/dist/strings.d.ts +581 -0
- package/dist/strings.js +411 -0
- package/dist/style.d.ts +35 -0
- package/dist/style.js +177 -0
- package/dist/surfaces/baseball.d.ts +33 -0
- package/dist/surfaces/baseball.js +208 -0
- package/dist/surfaces/baseball.walls.d.ts +16 -0
- package/dist/surfaces/baseball.walls.js +150 -0
- package/dist/surfaces/basketball.d.ts +8 -0
- package/dist/surfaces/basketball.js +199 -0
- package/dist/surfaces/curling.d.ts +23 -0
- package/dist/surfaces/curling.js +128 -0
- package/dist/surfaces/field.d.ts +12 -0
- package/dist/surfaces/field.js +163 -0
- package/dist/surfaces/football.d.ts +12 -0
- package/dist/surfaces/football.js +208 -0
- package/dist/surfaces/hockey.d.ts +10 -0
- package/dist/surfaces/hockey.js +166 -0
- package/dist/surfaces/net.d.ts +7 -0
- package/dist/surfaces/net.js +151 -0
- package/dist/surfaces/soccer-providers.d.ts +124 -0
- package/dist/surfaces/soccer-providers.js +334 -0
- package/dist/surfaces/soccer-spec.d.ts +138 -0
- package/dist/surfaces/soccer-spec.js +175 -0
- package/dist/surfaces/soccer.d.ts +25 -0
- package/dist/surfaces/soccer.js +270 -0
- package/dist/surfaces/surface.d.ts +180 -0
- package/dist/surfaces/surface.js +49 -0
- package/dist/team.common.d.ts +75 -0
- package/dist/team.common.js +97 -0
- package/dist/team.formation.d.ts +24 -0
- package/dist/team.formation.js +121 -0
- package/dist/team.geometry.d.ts +66 -0
- package/dist/team.geometry.js +304 -0
- package/dist/team.layers.d.ts +16 -0
- package/dist/team.layers.js +32 -0
- package/dist/team.motion.d.ts +9 -0
- package/dist/team.motion.js +325 -0
- package/dist/team.network.d.ts +43 -0
- package/dist/team.network.js +215 -0
- package/dist/team.shape.d.ts +12 -0
- package/dist/team.shape.js +217 -0
- package/dist/team.types.d.ts +189 -0
- package/dist/team.types.js +1 -0
- package/dist/text.d.ts +31 -0
- package/dist/text.js +88 -0
- package/dist/themes.d.ts +14 -0
- package/dist/themes.js +24 -0
- package/dist/types.d.ts +565 -0
- package/dist/types.js +1 -0
- package/dist/units.d.ts +45 -0
- package/dist/units.js +90 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +234 -4
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { Attacking, Frame, Landmark, SurfaceSize } from "./frames.ts";
|
|
2
|
+
import type { Unit } from "./units.ts";
|
|
3
|
+
/** What a tracked object is. `home` and `away` are players; the rest are drawn smaller and in the layer's plain colours. */
|
|
4
|
+
export type ReplayTeam = "home" | "away" | "ball" | "puck" | "official";
|
|
5
|
+
/** One tracked object in one frame of the data. */
|
|
6
|
+
export interface ReplayObject {
|
|
7
|
+
/** Who it is, the same in every frame it is in: `h7`, `ball`. */
|
|
8
|
+
id: string;
|
|
9
|
+
team: ReplayTeam;
|
|
10
|
+
/** Where it is, in the timeline's frame (`from`) and unit. */
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
/** A name for the tooltip: "Rivera". */
|
|
14
|
+
label?: string;
|
|
15
|
+
/** A shirt number, written on the mark of a player. */
|
|
16
|
+
number?: number | string;
|
|
17
|
+
}
|
|
18
|
+
/** The positions at one time. */
|
|
19
|
+
export interface ReplayFrame {
|
|
20
|
+
/** Seconds. The frames of a timeline run forward in time (they are sorted if they do not). */
|
|
21
|
+
t: number;
|
|
22
|
+
objects: readonly ReplayObject[];
|
|
23
|
+
/**
|
|
24
|
+
* Who has the ball or the puck, when the data says: the `id` of an object, or `home` or `away` for a team without a named player.
|
|
25
|
+
* `null` says nobody does (a loose ball, a pass in flight). It holds until a later frame says otherwise.
|
|
26
|
+
*/
|
|
27
|
+
possession?: string | null;
|
|
28
|
+
}
|
|
29
|
+
/** The standard kinds of event. Any other word is an event of your own; its `label` is what is said. */
|
|
30
|
+
export type ReplayEventKind = "pass" | "shot" | "goal" | "whistle" | (string & {});
|
|
31
|
+
/** Something that happened at a time: a pass, a shot, a goal, a whistle. */
|
|
32
|
+
export interface ReplayEvent {
|
|
33
|
+
/** Seconds, on the same clock as the frames. */
|
|
34
|
+
t: number;
|
|
35
|
+
kind: ReplayEventKind;
|
|
36
|
+
/** The team it belongs to; it colours the mark. */
|
|
37
|
+
team?: "home" | "away";
|
|
38
|
+
/** Where it began, in the timeline's frame; else the place of the object `by` at `t`; else the ball's or the puck's at `t`. */
|
|
39
|
+
x?: number;
|
|
40
|
+
y?: number;
|
|
41
|
+
/** Where it ended (a pass's receiver, a shot's end), in the timeline's frame; else the place of the object `to` at `until`. A mark with no end is a point. */
|
|
42
|
+
x2?: number;
|
|
43
|
+
y2?: number;
|
|
44
|
+
/** The object that made it. */
|
|
45
|
+
by?: string;
|
|
46
|
+
/** The object that received it. */
|
|
47
|
+
to?: string;
|
|
48
|
+
/** When it ended, for `to` and for how long the mark stays: seconds. `t` by default. */
|
|
49
|
+
until?: number;
|
|
50
|
+
/** What is said of it, over the standard words: "Goal, Rivera". */
|
|
51
|
+
label?: string;
|
|
52
|
+
}
|
|
53
|
+
/** Tracking data over time on a surface. Do not change a timeline after it has been used: make a new one. */
|
|
54
|
+
export interface ReplayTimeline {
|
|
55
|
+
/** The positions, from the first moment to the last. */
|
|
56
|
+
frames: readonly ReplayFrame[];
|
|
57
|
+
/** What happened, by time. */
|
|
58
|
+
events?: readonly ReplayEvent[];
|
|
59
|
+
/** The frame the positions are in (a name in `FRAMES`, or a `Frame`), as for a layer. Without it they are the surface's own: feet from the top left of the surface as drawn wide. */
|
|
60
|
+
from?: Frame | string;
|
|
61
|
+
/** The unit of the positions, as for a layer. */
|
|
62
|
+
units?: Unit | "rulebook";
|
|
63
|
+
/** The end the home team attacks, as for a layer, for a frame fixed to the surface. */
|
|
64
|
+
attacking?: Attacking;
|
|
65
|
+
/** The surface's size, for a frame that fits any size. */
|
|
66
|
+
surfaceSize?: SurfaceSize;
|
|
67
|
+
/** Landmarks of your own for an axis of the frame. */
|
|
68
|
+
anchors?: {
|
|
69
|
+
x?: readonly Landmark[];
|
|
70
|
+
y?: readonly Landmark[];
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** How a frame is drawn. */
|
|
74
|
+
export interface ReplayLook {
|
|
75
|
+
/** Seconds of trail behind the objects named in `trailOf`; 0 for none. 2 by default. */
|
|
76
|
+
trail?: number;
|
|
77
|
+
/** Whose trail is drawn. The ball and the puck by default. */
|
|
78
|
+
trailOf?: readonly ReplayTeam[];
|
|
79
|
+
/** Round the corners of the path between frames: `true` for a Catmull-Rom curve through the frames, or a share from 0 (straight lines, the default) to 1. */
|
|
80
|
+
smooth?: boolean | number;
|
|
81
|
+
/** Seconds an event's mark stays on the surface after it. 3 by default. */
|
|
82
|
+
hold?: number;
|
|
83
|
+
/** Write the shirt numbers on the players. On by default. */
|
|
84
|
+
numbers?: boolean;
|
|
85
|
+
/** A multiple of the size of the players' marks. 1 by default. */
|
|
86
|
+
scale?: number;
|
|
87
|
+
}
|
|
88
|
+
/** What the controller and the controls can be told, over how a frame is drawn. */
|
|
89
|
+
export interface ReplaySettings extends ReplayLook {
|
|
90
|
+
/** The speed of play: 0.25 to 4. 1 by default. */
|
|
91
|
+
speed?: number;
|
|
92
|
+
/** Start again at the end. */
|
|
93
|
+
loop?: boolean;
|
|
94
|
+
/** Play when the replay is attached. Ignored for a reader who prefers reduced motion, and while the page is hidden. */
|
|
95
|
+
autoplay?: boolean;
|
|
96
|
+
/** The bar of controls under the drawing (play, step, speed, loop, position). On by default; the keyboard works without it. */
|
|
97
|
+
controls?: boolean;
|
|
98
|
+
/** Announce goals, shots and the other events to a screen reader as they pass. On by default. */
|
|
99
|
+
announce?: boolean;
|
|
100
|
+
/** `auto` (the default) follows the reader's `prefers-reduced-motion`: with reduced motion nothing plays by itself and play steps instead. `smooth` and `step` force one. */
|
|
101
|
+
motion?: "auto" | "smooth" | "step";
|
|
102
|
+
/** In step mode, how many seconds a step moves. 1 by default. */
|
|
103
|
+
stepSeconds?: number;
|
|
104
|
+
/** The time to begin at, in seconds from the first frame. 0 by default. */
|
|
105
|
+
start?: number;
|
|
106
|
+
}
|
|
107
|
+
/** A tracked object at a moment, and the trail behind it. */
|
|
108
|
+
export interface ReplayTrail {
|
|
109
|
+
id: string;
|
|
110
|
+
team: ReplayTeam;
|
|
111
|
+
/** The places over the last seconds, oldest first, the last the object's place now. */
|
|
112
|
+
points: [number, number][];
|
|
113
|
+
}
|
|
114
|
+
/** An event that is on the surface now, with its places worked out. */
|
|
115
|
+
export interface ActiveEvent {
|
|
116
|
+
/** Its place in the timeline's `events`. */
|
|
117
|
+
index: number;
|
|
118
|
+
event: ReplayEvent;
|
|
119
|
+
x?: number;
|
|
120
|
+
y?: number;
|
|
121
|
+
x2?: number;
|
|
122
|
+
y2?: number;
|
|
123
|
+
}
|
|
124
|
+
/** Who has the ball, when the data says. */
|
|
125
|
+
export interface Possession {
|
|
126
|
+
holder?: string;
|
|
127
|
+
team?: "home" | "away";
|
|
128
|
+
}
|
|
129
|
+
/** What the controller is doing. */
|
|
130
|
+
export interface ReplayState {
|
|
131
|
+
/** Seconds on the timeline's clock. */
|
|
132
|
+
t: number;
|
|
133
|
+
/** The first and last moments of the timeline. */
|
|
134
|
+
start: number;
|
|
135
|
+
end: number;
|
|
136
|
+
playing: boolean;
|
|
137
|
+
/** Stopped at the end (and not looping). */
|
|
138
|
+
ended: boolean;
|
|
139
|
+
speed: number;
|
|
140
|
+
loop: boolean;
|
|
141
|
+
/** `step` for a reader who prefers reduced motion: play moves a step, never by itself. */
|
|
142
|
+
motion: "smooth" | "step";
|
|
143
|
+
}
|
|
144
|
+
/** Why the controller told its listeners. */
|
|
145
|
+
export type ReplayReason = "play" | "pause" | "seek" | "step" | "tick" | "speed" | "loop" | "motion";
|
|
146
|
+
/** What a listener of the controller is told. */
|
|
147
|
+
export interface ReplayChange {
|
|
148
|
+
state: Readonly<ReplayState>;
|
|
149
|
+
reason: ReplayReason;
|
|
150
|
+
/** The events that went by in this move (moving forward only), for the live region. */
|
|
151
|
+
crossed: readonly ReplayEvent[];
|
|
152
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Unit } from "./units.ts";
|
|
2
|
+
import type { SurfaceOptions } from "./types.ts";
|
|
3
|
+
/** What the options ask of the lines, in the units of the markup they are applied to. */
|
|
4
|
+
export interface LineLook {
|
|
5
|
+
scale: number;
|
|
6
|
+
dash: readonly number[] | undefined;
|
|
7
|
+
opacity: number | undefined;
|
|
8
|
+
}
|
|
9
|
+
/** How wide the surface's ordinary line is drawn, in the units of its markup, and how many feet one of them is (`Surface.lineRef`). */
|
|
10
|
+
export interface LineRef {
|
|
11
|
+
width: number;
|
|
12
|
+
feet: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The look of the lines the options ask for, or `undefined` when they ask for none of it. A width is a multiple of the width the lines are drawn at (`2`,
|
|
16
|
+
* `{ scale: 2 }`) or an absolute width in `units` (`{ width: 0.5 }`), turned into a multiple here; a value that cannot be read is left out, as the other options'
|
|
17
|
+
* are, so that a page's markup cannot break a drawing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function lineLook(o: Pick<SurfaceOptions, "lineWidth" | "lineDash" | "lineOpacity">, ref: LineRef | undefined, unit: Unit): LineLook | undefined;
|
|
20
|
+
/** The markup of a surface's lines with the look applied. */
|
|
21
|
+
export declare function restyleLines(markup: string, look: LineLook): string;
|
package/dist/restyle.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The width, the dashes and the opacity of a surface's painted lines (`lineWidth`, `lineDash`, `lineOpacity`): the lines are written by the surface at the
|
|
2
|
+
// widths its rules give, and these options are laid over what it wrote, element by element, by class. The marks that are fixtures (the posts, the rims, the
|
|
3
|
+
// nets, the fence) and the filled marks (the plates, the bases, the hog lines) keep their size; a line that is dashed by its rules keeps its own dashes.
|
|
4
|
+
import { num } from "./format.js";
|
|
5
|
+
import { FEET_PER, isUnit } from "./units.js";
|
|
6
|
+
/** The classes that are painted lines: they take a width, a dash and an opacity. */
|
|
7
|
+
const LINES = new Set(["ky-line", "ky-red", "ky-blue", "ky-band", "ky-crease"]);
|
|
8
|
+
/** The dashes in the centre line of a rink are lines too, but they are dashes already. */
|
|
9
|
+
const WIDTH = new Set([...LINES, "ky-dash"]);
|
|
10
|
+
/** The classes of marks painted as a fill, which take an opacity. */
|
|
11
|
+
const FILLS = new Set(["ky-fill-line", "ky-red-fill", "ky-blue-fill", "ky-num"]);
|
|
12
|
+
const finitePositive = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
13
|
+
/**
|
|
14
|
+
* The look of the lines the options ask for, or `undefined` when they ask for none of it. A width is a multiple of the width the lines are drawn at (`2`,
|
|
15
|
+
* `{ scale: 2 }`) or an absolute width in `units` (`{ width: 0.5 }`), turned into a multiple here; a value that cannot be read is left out, as the other options'
|
|
16
|
+
* are, so that a page's markup cannot break a drawing.
|
|
17
|
+
*/
|
|
18
|
+
export function lineLook(o, ref, unit) {
|
|
19
|
+
if (ref === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
const width = o.lineWidth;
|
|
22
|
+
let scale = 1;
|
|
23
|
+
if (finitePositive(width))
|
|
24
|
+
scale = width;
|
|
25
|
+
else if (typeof width === "object" && width !== null && "scale" in width && finitePositive(width.scale))
|
|
26
|
+
scale = width.scale;
|
|
27
|
+
else if (typeof width === "object" && width !== null && "width" in width && finitePositive(width.width) && isUnit(unit))
|
|
28
|
+
scale = (width.width * FEET_PER[unit]) / ref.feet / ref.width;
|
|
29
|
+
scale = Math.min(Math.max(scale, 0.05), 40);
|
|
30
|
+
const drawn = ref.width * scale;
|
|
31
|
+
const dashed = o.lineDash;
|
|
32
|
+
let dash;
|
|
33
|
+
if (dashed === "dashed")
|
|
34
|
+
dash = [6 * drawn, 4 * drawn];
|
|
35
|
+
else if (dashed === "dotted")
|
|
36
|
+
dash = [drawn, 2 * drawn];
|
|
37
|
+
else if (dashed === "dash-dot")
|
|
38
|
+
dash = [6 * drawn, 3 * drawn, drawn, 3 * drawn];
|
|
39
|
+
else if (Array.isArray(dashed) && dashed.length > 0 && dashed.every(finitePositive) && isUnit(unit))
|
|
40
|
+
dash = dashed.map((length) => (length * FEET_PER[unit]) / ref.feet);
|
|
41
|
+
const opacity = typeof o.lineOpacity === "number" && Number.isFinite(o.lineOpacity) && o.lineOpacity < 1 ? Math.max(0, o.lineOpacity) : undefined;
|
|
42
|
+
if (scale === 1 && dash === undefined && opacity === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
return { scale, dash, opacity };
|
|
45
|
+
}
|
|
46
|
+
const SHAPE = /<(path|rect|circle|ellipse|line|text)\b([^>]*?)(\/?)>/g;
|
|
47
|
+
/** The markup of a surface's lines with the look applied. */
|
|
48
|
+
export function restyleLines(markup, look) {
|
|
49
|
+
return markup.replace(SHAPE, (whole, tag, attrs, close) => {
|
|
50
|
+
const cls = /\sclass="([^"]*)"/.exec(attrs)?.[1].split(/\s+/) ?? [];
|
|
51
|
+
const line = cls.some((c) => LINES.has(c));
|
|
52
|
+
const filled = cls.some((c) => FILLS.has(c));
|
|
53
|
+
const wide = cls.some((c) => WIDTH.has(c));
|
|
54
|
+
if (!line && !filled && !wide)
|
|
55
|
+
return whole;
|
|
56
|
+
let out = attrs;
|
|
57
|
+
if (wide && look.scale !== 1)
|
|
58
|
+
out = out.replace(/(\sstroke-width=")([^"]*)(")/, (_m, a, v, b) => `${a}${num(Number(v) * look.scale)}${b}`);
|
|
59
|
+
let extra = "";
|
|
60
|
+
if (line && look.dash !== undefined && !/\sstroke-dasharray=/.test(out))
|
|
61
|
+
extra += ` stroke-dasharray="${look.dash.map(num).join(" ")}"`;
|
|
62
|
+
if (look.opacity !== undefined) {
|
|
63
|
+
if (line || cls.includes("ky-dash"))
|
|
64
|
+
extra += ` stroke-opacity="${num(look.opacity)}"`;
|
|
65
|
+
else if (filled)
|
|
66
|
+
extra += ` fill-opacity="${num(look.opacity)}"`;
|
|
67
|
+
}
|
|
68
|
+
return `<${tag}${out}${extra}${close}>`;
|
|
69
|
+
});
|
|
70
|
+
}
|
package/dist/road.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RoadChart, RoadFinalist, RoadOptions } from "./road.types.ts";
|
|
2
|
+
export { ROAD_SIZES } from "./road.draw.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The road to the final: the two finalists as large round marks with their names at the top, each one's matches on its side (the round mark of both teams with the
|
|
5
|
+
* score between them, and FT, AET or the shoot-out under it), the round names down the middle, and the group stage as a compact row of small marks, codes and scores.
|
|
6
|
+
* A finalist is a team (`name`, `abbr`, `logo` for the flag or the crest, `color`) with its `path`, the matches before the final, the earliest first, and optionally its
|
|
7
|
+
* `group`. A match is `{ round, opponent, score: [for, against], decidedBy, pens }`; a round is a key (`quarter-final`) with words in English and Japanese, or any
|
|
8
|
+
* key you name in `labels`, so a series (`First round`, `4-2`) draws as well as a knockout. A team with no `logo` is drawn as its initials on its colour. The side that won
|
|
9
|
+
* each match is brighter; the sizes are `card` (1080 by 1350), `square`, `wide` (1200 by 675) and `phone` (390 wide). `table()` lists every match as text.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { roadToFinal, type RoadFinalist } from "@johnmorrisdotca/kyogijo-stadiums/charts";
|
|
13
|
+
* const owls: RoadFinalist = { name: "Northern Owls", abbr: "NOW", color: "#3a2d6b", path: [
|
|
14
|
+
* { round: "quarter-final", opponent: { name: "Coastal Pines", abbr: "CPN" }, score: [2, 0] },
|
|
15
|
+
* { round: "semi-final", opponent: { name: "Valley Stars", abbr: "VAL" }, score: [1, 1], decidedBy: "pens", pens: [4, 3] },
|
|
16
|
+
* ] };
|
|
17
|
+
* const gulls: RoadFinalist = { name: "Harbour City Gulls", abbr: "HCG", color: "#1d4f91", path: [
|
|
18
|
+
* { round: "quarter-final", opponent: { name: "Summit Peaks", abbr: "SMT" }, score: [3, 1] },
|
|
19
|
+
* { round: "semi-final", opponent: { name: "Metro Bolts", abbr: "MTB" }, score: [2, 1], decidedBy: "aet" },
|
|
20
|
+
* ] };
|
|
21
|
+
* const chart = roadToFinal([owls, gulls], { title: "Northern Cup 2030", size: "square" });
|
|
22
|
+
* console.log(chart.totals.rounds.join(" "), chart.draw().startsWith("<svg"), chart.table().includes("Semi-final"));
|
|
23
|
+
* // quarter-final semi-final true true
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function roadToFinal(finalists: readonly [RoadFinalist, RoadFinalist], options?: RoadOptions): RoadChart;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Model } from "./road.model.ts";
|
|
2
|
+
import type { RoadOptions, RoadSize, RoadSizeInfo } from "./road.types.ts";
|
|
3
|
+
/** The sizes in pixels: `card` 1080 by 1350, `square` 1080 by 1080, `wide` 1200 by 675 and `phone` 390 wide and as tall as the rounds need. */
|
|
4
|
+
export declare const ROAD_SIZES: Readonly<Record<RoadSize, RoadSizeInfo>>;
|
|
5
|
+
/** Draw the chart as an SVG string. `gid` is the prefix of its ids. */
|
|
6
|
+
export declare function drawRoad(model: Model, o: RoadOptions, gid: string): string;
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// The road chart, drawn: the two finalists' big round marks with their names, the round names down the middle on a dotted road, each finalist's matches on its side as
|
|
2
|
+
// the round marks of both teams with the score between them, and the group stage as a compact row at the foot. Each size has its own arrangement: `card`, `square` and
|
|
3
|
+
// `phone` stack the finalists over the rounds; `wide` puts them at the two ends. Nothing is measured in a browser: type is set by estimates (`textWidth`).
|
|
4
|
+
import { safeColour, safeLogo } from "./colour.js";
|
|
5
|
+
import { safeClass } from "./common.js";
|
|
6
|
+
import { el, esc, num } from "./format.js";
|
|
7
|
+
import { KYOGIJO_MARK_STYLE, roundMarkup } from "./mark.js";
|
|
8
|
+
import { codeOf, decidedWords, nameOf, summaryOf } from "./road.model.js";
|
|
9
|
+
import { KYOGIJO_ROAD_STYLE } from "./road.style.js";
|
|
10
|
+
import { capitals, fitLines, textWidth } from "./text.js";
|
|
11
|
+
import { VERSION } from "./version.js";
|
|
12
|
+
/** The sizes in pixels: `card` 1080 by 1350, `square` 1080 by 1080, `wide` 1200 by 675 and `phone` 390 wide and as tall as the rounds need. */
|
|
13
|
+
export const ROAD_SIZES = Object.freeze({
|
|
14
|
+
card: { width: 1080, height: 1350, about: "1080 by 1350, a tall post" },
|
|
15
|
+
square: { width: 1080, height: 1080, about: "1080 by 1080, a square post" },
|
|
16
|
+
wide: { width: 1200, height: 675, about: "1200 by 675, a wide card with the finalists at the two ends" },
|
|
17
|
+
phone: { width: 390, height: undefined, about: "390 wide, as tall as the rounds need" },
|
|
18
|
+
});
|
|
19
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
20
|
+
/** A text centred on `y`, `size` high. */
|
|
21
|
+
const text = (cls, x, y, size, content, anchor = "middle") => el("text", { class: cls, x: num(x), y: num(y + size * 0.36), "font-size": num(size), "text-anchor": anchor }, esc(content));
|
|
22
|
+
/** The width of a match's score block in ems of its number size: the two numbers and the dash. */
|
|
23
|
+
const scoreEms = (v) => (v.whole !== undefined ? textWidth(v.whole) : textWidth(v.mine) + textWidth(v.theirs) + 1.1);
|
|
24
|
+
/** The group stage's score as one text. */
|
|
25
|
+
const sub0 = (v) => v.note !== undefined ? v.note !== "" : v.says;
|
|
26
|
+
const groupScore = (v) => v.whole ?? `${v.mine}–${v.theirs}`;
|
|
27
|
+
/** Draw the chart as an SVG string. `gid` is the prefix of its ids. */
|
|
28
|
+
export function drawRoad(model, o, gid) {
|
|
29
|
+
const size = o.size !== undefined && Object.prototype.hasOwnProperty.call(ROAD_SIZES, o.size) ? o.size : "card";
|
|
30
|
+
const info = ROAD_SIZES[size];
|
|
31
|
+
const w = model.words.road;
|
|
32
|
+
const W = info.width;
|
|
33
|
+
const phone = size === "phone";
|
|
34
|
+
const wide = size === "wide";
|
|
35
|
+
const [fa, fb] = model.finalists;
|
|
36
|
+
const rounds = [...model.rounds].reverse();
|
|
37
|
+
const R = rounds.length;
|
|
38
|
+
const nGroup = Math.max(model.group[0].length, model.group[1].length);
|
|
39
|
+
const emphasis = o.winner !== "none";
|
|
40
|
+
const codes = o.codes !== false;
|
|
41
|
+
const theme = o.theme === "light" || o.theme === "dark" ? o.theme : undefined;
|
|
42
|
+
let marks = 0;
|
|
43
|
+
const markOf = (team, cx, cy, r, cls) => roundMarkup({
|
|
44
|
+
id: `${gid}-m${marks++}`,
|
|
45
|
+
cx,
|
|
46
|
+
cy,
|
|
47
|
+
r,
|
|
48
|
+
href: safeLogo(team.logo),
|
|
49
|
+
fit: team.markFit === "contain" ? "contain" : undefined,
|
|
50
|
+
initials: codeOf(team).slice(0, 3),
|
|
51
|
+
color: safeColour(team.color),
|
|
52
|
+
ink: safeColour(team.textColor),
|
|
53
|
+
title: team.name,
|
|
54
|
+
className: cls,
|
|
55
|
+
});
|
|
56
|
+
// ---- The type and the room round the edge. ----
|
|
57
|
+
const tall = info.height ?? 1e9;
|
|
58
|
+
const pad = phone ? 16 : Math.round(Math.min(W * 0.045, tall * 0.05));
|
|
59
|
+
const ts = clamp(Math.min(W * 0.044, tall * 0.056), 17, 48);
|
|
60
|
+
const es = clamp(Math.min(W * 0.0185, tall * 0.022), 9, 20);
|
|
61
|
+
const room = W - 2 * pad;
|
|
62
|
+
const titleFit = fitLines(model.title, room * 0.94, ts * 2.3, ts);
|
|
63
|
+
const subSize = model.subtitle === undefined ? 0 : Math.min(ts * 0.5, (room * 0.94) / Math.max(1, textWidth(model.subtitle)));
|
|
64
|
+
const headH = titleFit.height + (model.subtitle === undefined ? 0 : subSize * 1.5) + ts * 0.45;
|
|
65
|
+
const note = o.endnote === undefined ? "" : String(o.endnote).trim();
|
|
66
|
+
const endSize = note === "" ? 0 : Math.min(es, room / Math.max(1, textWidth(note, false)));
|
|
67
|
+
const footH = endSize === 0 ? 0 : endSize * 2.4;
|
|
68
|
+
// ---- The columns: the middle one holds the rounds' names; a wide chart has a column for each finalist at its end. ----
|
|
69
|
+
const cl = phone ? 70 : wide ? W * 0.12 : W * 0.175;
|
|
70
|
+
const fc = wide ? W * 0.17 : 0;
|
|
71
|
+
const sideW = (W - 2 * pad - cl - 2 * fc) / 2;
|
|
72
|
+
const lanes = [
|
|
73
|
+
{ x0: pad + fc, x1: pad + fc + sideW },
|
|
74
|
+
{ x0: W - pad - fc - sideW, x1: W - pad - fc },
|
|
75
|
+
];
|
|
76
|
+
const cx = W / 2;
|
|
77
|
+
// ---- The group stage: how many marks in a row, and how large. ----
|
|
78
|
+
const maxCols = Math.max(1, Math.floor(sideW / (phone ? 46 : W * 0.062)));
|
|
79
|
+
const cols = nGroup === 0 ? 1 : Math.min(maxCols, nGroup <= 4 ? nGroup : Math.ceil(nGroup / 2));
|
|
80
|
+
const groupRows = nGroup === 0 ? 0 : Math.ceil(nGroup / cols);
|
|
81
|
+
const cw = sideW / cols;
|
|
82
|
+
const dm = Math.min(cw * 0.56, phone ? 36 : Math.min(W * 0.052, tall * 0.065));
|
|
83
|
+
const cellH = dm * 2.08;
|
|
84
|
+
const groupBlock = nGroup === 0 ? 0 : groupRows * cellH + (groupRows - 1) * dm * 0.2 + (phone ? 26 : dm * 0.1);
|
|
85
|
+
// ---- The big marks, the rows and the vertical room. ----
|
|
86
|
+
const rowLabelH = phone ? 22 : 0;
|
|
87
|
+
let H = info.height ?? 0;
|
|
88
|
+
let D = wide ? Math.min(fc * 0.8, H * 0.36) : Math.min(sideW * 0.68, (info.height ?? 1e9) * 0.19);
|
|
89
|
+
const names = (d) => [fa, fb].map((t) => fitLines(capitals(t.name), (wide ? fc : sideW) * 0.96, d * 0.17 * 2.3, d * 0.17));
|
|
90
|
+
const slots = wide ? R + 1 : R;
|
|
91
|
+
const minRow = W * 0.085;
|
|
92
|
+
let rowH = phone ? 76 : 0;
|
|
93
|
+
let bandH = 0;
|
|
94
|
+
let regionTop = 0;
|
|
95
|
+
let regionBottom = 0;
|
|
96
|
+
const gapS = phone ? 14 : (info.height ?? 1000) * 0.016;
|
|
97
|
+
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
98
|
+
bandH = D + D * 0.08 + Math.max(...names(D).map((n) => n.height));
|
|
99
|
+
if (phone) {
|
|
100
|
+
regionTop = pad + headH + bandH + gapS;
|
|
101
|
+
regionBottom = regionTop + R * (rowH + rowLabelH);
|
|
102
|
+
H = regionBottom + (nGroup > 0 ? gapS + groupBlock : 0) + footH + pad;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
regionTop = pad + headH + (wide ? 0 : bandH + gapS);
|
|
106
|
+
regionBottom = H - pad - footH - (nGroup > 0 ? groupBlock + gapS : 0);
|
|
107
|
+
rowH = slots > 0 ? (regionBottom - regionTop) / slots : 0;
|
|
108
|
+
if (wide || rowH >= minRow || D < sideW * 0.25)
|
|
109
|
+
break;
|
|
110
|
+
D *= 0.86;
|
|
111
|
+
}
|
|
112
|
+
rowH = Math.min(rowH, W * 0.2);
|
|
113
|
+
// ---- The pieces of a row: the marks, the numbers, the gaps. ----
|
|
114
|
+
const subRatio = 0.42;
|
|
115
|
+
let ns = rowH * 0.34;
|
|
116
|
+
let d = rowH * 0.58;
|
|
117
|
+
let ems = 2.2;
|
|
118
|
+
for (const key of rounds) {
|
|
119
|
+
for (const i of [0, 1]) {
|
|
120
|
+
const v = model.path[i].get(key);
|
|
121
|
+
if (v !== undefined)
|
|
122
|
+
ems = Math.max(ems, scoreEms(v), textWidth(decidedWords(v, w, true), false) * subRatio);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const fit = Math.min(1, (sideW * 0.97) / (2 * d + 2 * d * 0.14 + ems * ns));
|
|
126
|
+
ns *= fit;
|
|
127
|
+
d *= fit;
|
|
128
|
+
const pair = 2 * d + 2 * d * 0.14 + ems * ns;
|
|
129
|
+
// The top of a row, the first being the last round. A wide chart's first slot is the final.
|
|
130
|
+
const rowTop = (i) => {
|
|
131
|
+
if (phone)
|
|
132
|
+
return regionTop + i * (rowH + rowLabelH) + rowLabelH;
|
|
133
|
+
return regionTop + (regionBottom - regionTop - slots * rowH) / 2 + (wide ? i + 1 : i) * rowH;
|
|
134
|
+
};
|
|
135
|
+
const dimOf = (result, forFinalist) => (emphasis && ((forFinalist && result === "loss") || (!forFinalist && result === "win")) ? " ky-r-dim" : "");
|
|
136
|
+
// The round's name: a panel in the middle column, or a line over the row on a phone.
|
|
137
|
+
const panel = (words, yc, height, width) => {
|
|
138
|
+
const fitted = fitLines(words, width * 0.88, height * 0.74, height * 0.54);
|
|
139
|
+
const lines = fitted.lines.map((line, i) => text("ky-r-lab", cx, yc + (i - (fitted.lines.length - 1) / 2) * fitted.size * 1.1, fitted.size, line));
|
|
140
|
+
return el("rect", { class: "ky-r-panel", x: num(cx - width / 2), y: num(yc - height / 2), width: num(width), height: num(height), rx: num(height / 2) }) + lines.join("");
|
|
141
|
+
};
|
|
142
|
+
const label = (key, yc) => {
|
|
143
|
+
const words = model.label(key);
|
|
144
|
+
if (!phone)
|
|
145
|
+
return panel(words, yc, Math.min(rowH * 0.34, cl * 0.2), cl * 0.94);
|
|
146
|
+
const y = yc - rowH / 2 - rowLabelH / 2;
|
|
147
|
+
const width = textWidth(words) * 11.5 + 20;
|
|
148
|
+
return el("rect", { class: "ky-r-panel", x: num(cx - width / 2), y: num(y - 9), width: num(width), height: 18, rx: 9 }) + text("ky-r-lab", cx, y, 11.5, words);
|
|
149
|
+
};
|
|
150
|
+
// One finalist's match in a row: the two marks and the score between them.
|
|
151
|
+
const matchMarkup = (lane, side, yc, v) => {
|
|
152
|
+
const left = v.homeFirst !== undefined ? v.homeFirst : side === 0;
|
|
153
|
+
const xc = (lane.x0 + lane.x1) / 2;
|
|
154
|
+
const y = yc - rowH * 0.04;
|
|
155
|
+
const lx = xc - pair / 2 + d / 2;
|
|
156
|
+
const rx = xc + pair / 2 - d / 2;
|
|
157
|
+
let out = markOf(model.finalists[side], left ? lx : rx, y, d / 2, `${side === 0 ? "ky-r-left" : "ky-r-right"}${dimOf(v.result, true)}`);
|
|
158
|
+
out += markOf(v.opponent, left ? rx : lx, y, d / 2, `ky-r-plain${dimOf(v.result, false)}`);
|
|
159
|
+
if (codes)
|
|
160
|
+
out += text(`ky-r-code${dimOf(v.result, false)}`, left ? rx : lx, y + d / 2 + d * 0.2, d * 0.2, codeOf(v.opponent));
|
|
161
|
+
out += scoreMarkup(v, xc, y, ns, left);
|
|
162
|
+
const sub = decidedWords(v, w, left);
|
|
163
|
+
return sub === "" ? out : out + text("ky-r-sub", xc, y + ns * 0.82, ns * subRatio, sub);
|
|
164
|
+
};
|
|
165
|
+
// The score: the two numbers either side of a dash, the loser's quiet. The first side's number is on the left when `left`.
|
|
166
|
+
const scoreMarkup = (v, x, y, n, left) => {
|
|
167
|
+
if (v.whole !== undefined)
|
|
168
|
+
return text("ky-r-n", x, y, n * 0.9, v.whole);
|
|
169
|
+
const [a, b, lowA, lowB] = left ? [v.mine, v.theirs, v.result === "loss", v.result === "win"] : [v.theirs, v.mine, v.result === "win", v.result === "loss"];
|
|
170
|
+
return (text(`ky-r-n${emphasis && lowA ? " ky-r-low" : ""}`, x - n * 0.4, y, n, a, "end") +
|
|
171
|
+
text("ky-r-dash", x, y, n * 0.8, "–") +
|
|
172
|
+
text(`ky-r-n${emphasis && lowB ? " ky-r-low" : ""}`, x + n * 0.4, y, n, b, "start"));
|
|
173
|
+
};
|
|
174
|
+
let body = "";
|
|
175
|
+
for (const [i, key] of rounds.entries()) {
|
|
176
|
+
const yc = rowTop(i) + rowH / 2;
|
|
177
|
+
body += label(key, yc);
|
|
178
|
+
for (const side of [0, 1]) {
|
|
179
|
+
const v = model.path[side].get(key);
|
|
180
|
+
if (v !== undefined)
|
|
181
|
+
body += matchMarkup(lanes[side], side, yc, v);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// ---- The finalists. ----
|
|
185
|
+
const final = model.final;
|
|
186
|
+
const lost = (side) => emphasis && final !== undefined && (side === 0 ? final.result === "loss" : final.result === "win");
|
|
187
|
+
const named = names(D);
|
|
188
|
+
const flagX = wide ? [pad + fc / 2, W - pad - fc / 2] : [(lanes[0].x0 + lanes[0].x1) / 2, (lanes[1].x0 + lanes[1].x1) / 2];
|
|
189
|
+
const flagY = wide ? (regionTop + regionBottom) / 2 - (D * 0.08 + Math.max(...named.map((n) => n.height))) / 2 : pad + headH + (phone ? 0 : (info.height ?? 1000) * 0.008) + D / 2;
|
|
190
|
+
let band = "";
|
|
191
|
+
for (const side of [0, 1]) {
|
|
192
|
+
const dim = lost(side) ? " ky-r-dim" : "";
|
|
193
|
+
band += markOf(model.finalists[side], flagX[side], flagY, D / 2, `${side === 0 ? "ky-r-left" : "ky-r-right"}${dim}`);
|
|
194
|
+
const nb = named[side];
|
|
195
|
+
const top = flagY + D / 2 + D * 0.08;
|
|
196
|
+
band += nb.lines.map((line, k) => text(`ky-r-name${dim}`, flagX[side], top + nb.size * 0.55 + k * nb.size * 1.1, nb.size, line)).join("");
|
|
197
|
+
}
|
|
198
|
+
// The final between them: its name over its score, or "v" when it is not played.
|
|
199
|
+
const fy = wide ? rowTop(-1) + rowH / 2 : flagY;
|
|
200
|
+
const labelSize = clamp(cl * 0.13, 9, 26);
|
|
201
|
+
const fs = wide ? Math.min(clamp(cl * 0.27, 14, 58), rowH * 0.36) : clamp(cl * 0.27, 14, 58);
|
|
202
|
+
let middle = text("ky-r-sub", cx, fy - (wide ? fs * 0.95 : Math.min(D * 0.3, cl * 0.34)), labelSize, model.label("final"));
|
|
203
|
+
if (final === undefined)
|
|
204
|
+
middle += text("ky-r-vs", cx, fy + labelSize * 0.2, fs * 0.9, w.vs);
|
|
205
|
+
else {
|
|
206
|
+
middle += scoreMarkup(final, cx, fy, fs, true);
|
|
207
|
+
const sub = decidedWords(final, w, true);
|
|
208
|
+
if (sub !== "")
|
|
209
|
+
middle += text("ky-r-sub", cx, fy + fs * 0.85, fs * 0.4, sub);
|
|
210
|
+
}
|
|
211
|
+
// ---- The road: a dotted line down the middle, behind the round names, from the final down to the group stage. ----
|
|
212
|
+
const groupTop = phone ? regionBottom + gapS : H - pad - footH - groupBlock;
|
|
213
|
+
const roadTop = wide ? fy + rowH * 0.42 : fy + (final === undefined ? labelSize * 1.6 : fs * (sub0(final) ? 1.5 : 1.0));
|
|
214
|
+
const roadEnd = nGroup > 0 ? groupTop + (phone ? 0 : cellH / 2) : R > 0 ? rowTop(R - 1) + rowH / 2 : roadTop;
|
|
215
|
+
const spine = R > 0 && roadEnd > roadTop
|
|
216
|
+
? el("path", { class: "ky-r-spine", d: `M${num(cx)} ${num(roadTop)}V${num(roadEnd)}`, "stroke-width": num(clamp(W * 0.004, 1.5, 4)), "stroke-dasharray": `0.1 ${num(clamp(W * 0.014, 5, 16))}`, fill: "none" })
|
|
217
|
+
: "";
|
|
218
|
+
// ---- The group stage: small round marks with their codes and scores. ----
|
|
219
|
+
let groupMarkup = "";
|
|
220
|
+
if (nGroup > 0) {
|
|
221
|
+
const gy = groupTop + (phone ? 26 : 0);
|
|
222
|
+
if (phone) {
|
|
223
|
+
const width = textWidth(model.groupLabel) * 11.5 + 20;
|
|
224
|
+
groupMarkup += el("rect", { class: "ky-r-panel", x: num(cx - width / 2), y: num(groupTop + 1), width: num(width), height: 18, rx: 9 }) + text("ky-r-lab", cx, groupTop + 10, 11.5, model.groupLabel);
|
|
225
|
+
}
|
|
226
|
+
else
|
|
227
|
+
groupMarkup += panel(model.groupLabel, gy + cellH / 2, Math.min(cellH * 0.42, cl * 0.2), cl * 0.94);
|
|
228
|
+
for (const side of [0, 1]) {
|
|
229
|
+
const lane = lanes[side];
|
|
230
|
+
model.group[side].forEach((v, k) => {
|
|
231
|
+
const row = Math.floor(k / cols);
|
|
232
|
+
const inRow = Math.min(cols, model.group[side].length - row * cols);
|
|
233
|
+
const x = (lane.x0 + lane.x1) / 2 - (inRow * cw) / 2 + (k % cols) * cw + cw / 2;
|
|
234
|
+
const y = gy + row * (cellH + dm * 0.2);
|
|
235
|
+
const dim = dimOf(v.result, false);
|
|
236
|
+
groupMarkup += markOf(v.opponent, x, y + dm / 2, dm / 2, `ky-r-plain${dim}`);
|
|
237
|
+
if (codes)
|
|
238
|
+
groupMarkup += text(`ky-r-code${dim}`, x, y + dm * 1.27, dm * 0.3, codeOf(v.opponent));
|
|
239
|
+
groupMarkup += text(`ky-r-n${emphasis && v.result === "loss" ? " ky-r-low" : ""}`, x, y + dm * 1.78, dm * 0.44, groupScore(v));
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// ---- The head and the foot. ----
|
|
244
|
+
let head = titleFit.lines.map((line, k) => text("ky-r-t", cx, pad + titleFit.size * 0.55 + k * titleFit.size * 1.1, titleFit.size, line)).join("");
|
|
245
|
+
if (model.subtitle !== undefined)
|
|
246
|
+
head += text("ky-r-s", cx, pad + titleFit.height + subSize * 0.7, subSize, model.subtitle);
|
|
247
|
+
const foot = endSize === 0 ? "" : text("ky-r-e", cx, H - pad - endSize * 0.2, endSize, note);
|
|
248
|
+
const sheet = o.style === "none" ? "" : `${KYOGIJO_MARK_STYLE}\n${KYOGIJO_ROAD_STYLE}`;
|
|
249
|
+
const extra = safeClass(o.className);
|
|
250
|
+
return el("svg", {
|
|
251
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
252
|
+
class: `kyogijo kyogijo-road${extra === "" ? "" : ` ${extra}`}`,
|
|
253
|
+
viewBox: `0 0 ${num(W)} ${num(H)}`,
|
|
254
|
+
role: "img",
|
|
255
|
+
"aria-labelledby": `${gid}-t ${gid}-d`,
|
|
256
|
+
"data-size": size,
|
|
257
|
+
"data-theme": theme,
|
|
258
|
+
"data-version": VERSION,
|
|
259
|
+
}, `<title id="${gid}-t">${esc(nameOf(model))}</title><desc id="${gid}-d">${esc(summaryOf(model))}</desc>` +
|
|
260
|
+
(sheet === "" ? "" : `<style>${sheet}</style>`) +
|
|
261
|
+
el("rect", { class: "ky-r-bg", x: 0, y: 0, width: num(W), height: num(H) }) +
|
|
262
|
+
head +
|
|
263
|
+
spine +
|
|
264
|
+
band +
|
|
265
|
+
middle +
|
|
266
|
+
body +
|
|
267
|
+
groupMarkup +
|
|
268
|
+
foot);
|
|
269
|
+
}
|
package/dist/road.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The road-to-the-final chart: the two finalists of a tournament with the matches each played on the way, as round flags (or crests) of both teams with the score between
|
|
2
|
+
// them, the rounds named down the middle, and the group stage as a compact row at the foot. The idea is that of the "road to the final" graphics that sports sites post
|
|
3
|
+
// for a World Cup or a Stanley Cup; the arrangement, the type and the code are this package's own, and no one's artwork is used: the marks are the caller's flags and
|
|
4
|
+
// logos, or the team's initials on its colour.
|
|
5
|
+
import { hash } from "./format.js";
|
|
6
|
+
import { safeClass } from "./common.js";
|
|
7
|
+
import { drawRoad } from "./road.draw.js";
|
|
8
|
+
import { nameOf, readModel, summaryOf, tableOf, totalsOf } from "./road.model.js";
|
|
9
|
+
import { VERSION } from "./version.js";
|
|
10
|
+
export { ROAD_SIZES } from "./road.draw.js";
|
|
11
|
+
const SIZES = ["card", "square", "wide", "phone"];
|
|
12
|
+
/**
|
|
13
|
+
* The road to the final: the two finalists as large round marks with their names at the top, each one's matches on its side (the round mark of both teams with the
|
|
14
|
+
* score between them, and FT, AET or the shoot-out under it), the round names down the middle, and the group stage as a compact row of small marks, codes and scores.
|
|
15
|
+
* A finalist is a team (`name`, `abbr`, `logo` for the flag or the crest, `color`) with its `path`, the matches before the final, the earliest first, and optionally its
|
|
16
|
+
* `group`. A match is `{ round, opponent, score: [for, against], decidedBy, pens }`; a round is a key (`quarter-final`) with words in English and Japanese, or any
|
|
17
|
+
* key you name in `labels`, so a series (`First round`, `4-2`) draws as well as a knockout. A team with no `logo` is drawn as its initials on its colour. The side that won
|
|
18
|
+
* each match is brighter; the sizes are `card` (1080 by 1350), `square`, `wide` (1200 by 675) and `phone` (390 wide). `table()` lists every match as text.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { roadToFinal, type RoadFinalist } from "@johnmorrisdotca/kyogijo-stadiums/charts";
|
|
22
|
+
* const owls: RoadFinalist = { name: "Northern Owls", abbr: "NOW", color: "#3a2d6b", path: [
|
|
23
|
+
* { round: "quarter-final", opponent: { name: "Coastal Pines", abbr: "CPN" }, score: [2, 0] },
|
|
24
|
+
* { round: "semi-final", opponent: { name: "Valley Stars", abbr: "VAL" }, score: [1, 1], decidedBy: "pens", pens: [4, 3] },
|
|
25
|
+
* ] };
|
|
26
|
+
* const gulls: RoadFinalist = { name: "Harbour City Gulls", abbr: "HCG", color: "#1d4f91", path: [
|
|
27
|
+
* { round: "quarter-final", opponent: { name: "Summit Peaks", abbr: "SMT" }, score: [3, 1] },
|
|
28
|
+
* { round: "semi-final", opponent: { name: "Metro Bolts", abbr: "MTB" }, score: [2, 1], decidedBy: "aet" },
|
|
29
|
+
* ] };
|
|
30
|
+
* const chart = roadToFinal([owls, gulls], { title: "Northern Cup 2030", size: "square" });
|
|
31
|
+
* console.log(chart.totals.rounds.join(" "), chart.draw().startsWith("<svg"), chart.table().includes("Semi-final"));
|
|
32
|
+
* // quarter-final semi-final true true
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function roadToFinal(finalists, options = {}) {
|
|
36
|
+
if (typeof options !== "object" || options === null)
|
|
37
|
+
throw new TypeError("options is an object");
|
|
38
|
+
const check = (o) => {
|
|
39
|
+
if (o.size !== undefined && !SIZES.includes(o.size))
|
|
40
|
+
throw new RangeError(`Unknown size "${String(o.size)}": use one of ${SIZES.join(", ")}`);
|
|
41
|
+
};
|
|
42
|
+
check(options);
|
|
43
|
+
const model = readModel(finalists, options);
|
|
44
|
+
const build = (extra = {}) => {
|
|
45
|
+
const merged = { ...options, ...extra };
|
|
46
|
+
check(merged);
|
|
47
|
+
const m = readModel(finalists, merged);
|
|
48
|
+
const gid = safeClass(merged.id).replace(/ /g, "-") || `kr-${hash(JSON.stringify([finalists, merged, VERSION]))}`;
|
|
49
|
+
return drawRoad(m, merged, gid);
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
options: { ...options },
|
|
53
|
+
title: nameOf(model),
|
|
54
|
+
summary: summaryOf(model),
|
|
55
|
+
totals: totalsOf(model),
|
|
56
|
+
draw: build,
|
|
57
|
+
table: (tableOptions = {}) => tableOf(tableOptions.language === undefined ? model : readModel(finalists, { ...options, language: tableOptions.language }), tableOptions),
|
|
58
|
+
};
|
|
59
|
+
}
|