@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
package/dist/grounds.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { GROUND_DATA } from "./grounds.data.js";
|
|
2
|
+
import { officialName, placesNamed } from "./names.js";
|
|
3
|
+
const METRES_PER_YARD = 0.9144;
|
|
4
|
+
const centimetres = (metres) => Math.round(metres * 100) / 100;
|
|
5
|
+
const toGround = (data) => {
|
|
6
|
+
const { pitch, ...rest } = data;
|
|
7
|
+
if (pitch === undefined)
|
|
8
|
+
return { ...rest, pitch: { length: 105, width: 68 }, pitchUnit: "m" };
|
|
9
|
+
const k = pitch.unit === "yd" ? METRES_PER_YARD : 1;
|
|
10
|
+
return { ...rest, pitch: { length: centimetres(pitch.length * k), width: centimetres(pitch.width * k) }, pitchUnit: pitch.unit };
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Every ground by its key: the venues of the men's World Cup finals and of the 2026 tournament, of the Women's World Cup finals,
|
|
14
|
+
* and well-known club grounds, each with its pitch at its own size where the English article publishes one.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { GROUNDS, GROUND_IDS } from "@johnmorrisdotca/kyogijo-stadiums/grounds";
|
|
18
|
+
* const { name, city, pitch, pitchSize } = GROUNDS["old-trafford"];
|
|
19
|
+
* console.log(name, city, pitch.length, pitch.width, pitchSize, GROUND_IDS.length);
|
|
20
|
+
* // Old Trafford Manchester 105 68 published 64
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const GROUNDS = Object.freeze(Object.fromEntries(GROUND_DATA.map((data) => [data.id, toGround(data)])));
|
|
24
|
+
/** The keys of `GROUNDS`: the men's World Cup final venues in order of the tournaments, the other venues of 2026, the Women's final venues not among them, then club grounds. */
|
|
25
|
+
export const GROUND_IDS = Object.freeze(GROUND_DATA.map((data) => data.id));
|
|
26
|
+
/** The ground with a key, or `undefined`. */
|
|
27
|
+
export const groundById = (id) => (id !== undefined && Object.prototype.hasOwnProperty.call(GROUNDS, id) ? GROUNDS[id] : undefined);
|
|
28
|
+
/**
|
|
29
|
+
* The grounds that answer to a name, best match first: the everyday names, then the official and cited names, the sponsors' and the names the ground had in some years, then the
|
|
30
|
+
* former names and the nicknames. A name is compared without case, accents, spaces or punctuation, in full-width or half-width, and in Japanese with hiragana or katakana and with
|
|
31
|
+
* or without the long vowel mark.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { groundByName, groundsByName } from "@johnmorrisdotca/kyogijo-stadiums/grounds";
|
|
35
|
+
* console.log(groundByName("Giuseppe Meazza Stadium")?.id, groundByName("日産スタジアム")?.id, groundByName("Estadio Jornalista Mario Filho")?.id, groundsByName("stadium australia").length);
|
|
36
|
+
* // san-siro nissan-stadium-yokohama maracana 1
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export const groundsByName = (name) => placesNamed(Object.values(GROUNDS), name);
|
|
40
|
+
/** The ground a name belongs to (see `groundsByName`; the best match when several answer to it), or `undefined`. */
|
|
41
|
+
export const groundByName = (name) => groundsByName(name)[0];
|
|
42
|
+
/** The name a ground officially has in a language, when it is not the everyday name (`Parc Olympique Lyonnais` for `Groupama Stadium`), in the year given or today; else `undefined`. */
|
|
43
|
+
export function groundOfficialName(ground, language = "en", year) {
|
|
44
|
+
const shown = groundNameIn(ground, year, language);
|
|
45
|
+
// A name the ground had for some years (the one FIFA gave it for a World Cup) is not followed by what it is officially today.
|
|
46
|
+
if (year !== undefined && Number.isFinite(year) && language === "en" && shown !== ground.name)
|
|
47
|
+
return undefined;
|
|
48
|
+
return officialName(ground, language, shown, Number.isFinite(year) ? year : undefined);
|
|
49
|
+
}
|
|
50
|
+
/** The ground whose Wikidata item is `Q155174`, or `undefined`. */
|
|
51
|
+
export const groundByWikidata = (wikidata) => Object.values(GROUNDS).find((ground) => ground.wikidata === wikidata);
|
|
52
|
+
/**
|
|
53
|
+
* A ground's name in a year: the name it had then, or its everyday name, in English. In Japanese there is one name for every year.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { GROUNDS, groundNameIn } from "@johnmorrisdotca/kyogijo-stadiums/grounds";
|
|
57
|
+
* console.log(groundNameIn(GROUNDS["soccer-city"], 2010), "/", groundNameIn(GROUNDS["soccer-city"], 2012));
|
|
58
|
+
* // Soccer City / FNB Stadium
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function groundNameIn(ground, year, language = "en") {
|
|
62
|
+
if (language === "ja")
|
|
63
|
+
return ground.nameJa;
|
|
64
|
+
if (year === undefined || !Number.isFinite(year))
|
|
65
|
+
return ground.name;
|
|
66
|
+
const periods = (ground.names ?? []).filter((period) => period.from <= year && year <= period.to);
|
|
67
|
+
return periods.length === 0 ? ground.name : periods[periods.length - 1].name;
|
|
68
|
+
}
|
|
69
|
+
/** The grounds of this list that staged matches of a World Cup, in the order of `GROUND_IDS`. */
|
|
70
|
+
export const groundsHosting = (competition, year) => Object.values(GROUNDS).filter((ground) => ground.tournaments.some((t) => t.competition === competition && t.year === year));
|
|
71
|
+
/** The address of the revision of an article that a ground's facts were read from. */
|
|
72
|
+
export function groundSourceUrl(source, language = "en") {
|
|
73
|
+
return `https://${language}.wikipedia.org/w/index.php?title=${encodeURIComponent(source.title.replace(/ /g, "_"))}&oldid=${source.revision}`;
|
|
74
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** The built-in ramps. The sequential ones go from the least to the most; the diverging ones from the lowest through a neutral middle to the highest. */
|
|
2
|
+
export type HeatRampName = "ember" | "ocean" | "mono" | "balance" | "tide";
|
|
3
|
+
/** A built-in ramp: nine stops for a light page and nine for a dark one. */
|
|
4
|
+
export interface HeatRampDef {
|
|
5
|
+
kind: "sequential" | "diverging";
|
|
6
|
+
light: readonly string[];
|
|
7
|
+
dark: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The built-in ramps. On a light page a sequential ramp runs from a pale colour to a dark one, because the more there is the more ink it takes;
|
|
11
|
+
* on a dark page it runs from near the ground to a bright one, because the more there is the more light it gives. A diverging ramp has its neutral
|
|
12
|
+
* middle at the ground's colour and its two ends at full strength.
|
|
13
|
+
*/
|
|
14
|
+
export declare const HEAT_RAMPS: Readonly<Record<HeatRampName, HeatRampDef>>;
|
|
15
|
+
/** Names of the built-in ramps. */
|
|
16
|
+
export declare const HEAT_RAMP_NAMES: readonly HeatRampName[];
|
|
17
|
+
/**
|
|
18
|
+
* A ramp for a layer: the name of a built-in one, a list of colour stops (the same on a light and a dark page), or a `light` and a `dark` list.
|
|
19
|
+
* Stops are anything `safeColour` accepts.
|
|
20
|
+
*/
|
|
21
|
+
export type HeatRamp = HeatRampName | readonly string[] | {
|
|
22
|
+
light: readonly string[];
|
|
23
|
+
dark?: readonly string[];
|
|
24
|
+
};
|
|
25
|
+
/** A ramp, resolved: the stops for a light page, and for a dark one when it differs. */
|
|
26
|
+
export interface ResolvedRamp {
|
|
27
|
+
name: HeatRampName | undefined;
|
|
28
|
+
kind: "sequential" | "diverging";
|
|
29
|
+
light: string[];
|
|
30
|
+
dark: string[] | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The ramp a layer asks for; `ember` when it asks for none (`fallback` for a diverging statistic). */
|
|
33
|
+
export declare function resolveRamp(ramp: HeatRamp | undefined, fallback?: HeatRampName): ResolvedRamp;
|
|
34
|
+
/** The colour of step `k` of `steps` (0 to `steps - 1`) of some stops, as a hex colour (or the nearest stop for a colour that cannot be read without a browser). */
|
|
35
|
+
export declare function stepColour(stops: readonly string[], k: number, steps: number): string;
|
|
36
|
+
/** The step (0 to `steps - 1`) a value falls in, on a domain: the share of the way through it, to the nearest step. */
|
|
37
|
+
export declare function stepOf(value: number, domain: readonly [number, number], steps: number): number;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// The colour ramps of the heat maps: a few built-in ramps with a light set and a dark set, a ramp run through steps, and a value mapped to a step. The
|
|
2
|
+
// ramps were chosen by luminance, so that they read in order without their colour (see heat.colour.test.ts, which checks the contrast of each against the
|
|
3
|
+
// ground the layer paints), and they are written here as plain numbers: no palette of any plotting package is copied.
|
|
4
|
+
import { safeColour } from "./colour.js";
|
|
5
|
+
import { rampColour } from "./layers.marks.js";
|
|
6
|
+
const split = (text) => text.split(" ");
|
|
7
|
+
/**
|
|
8
|
+
* The built-in ramps. On a light page a sequential ramp runs from a pale colour to a dark one, because the more there is the more ink it takes;
|
|
9
|
+
* on a dark page it runs from near the ground to a bright one, because the more there is the more light it gives. A diverging ramp has its neutral
|
|
10
|
+
* middle at the ground's colour and its two ends at full strength.
|
|
11
|
+
*/
|
|
12
|
+
export const HEAT_RAMPS = Object.freeze({
|
|
13
|
+
ember: { kind: "sequential", light: split("#fff3c4 #fddc8a #fbb860 #f58f42 #d9561f #bf3a1f #8f1f1c #5e1219 #3a0b14"), dark: split("#2a1d24 #52263a #82304a #ac3f4a #cf573a #e97a2e #f79e2c #fcc84a #fff08a") },
|
|
14
|
+
ocean: { kind: "sequential", light: split("#e6f3fa #bfe0f0 #8fc6e3 #5fa8d3 #3478b0 #25689f #174c80 #0e3460 #08213f"), dark: split("#14222e #1b3d58 #1f5a82 #2677a8 #3396c8 #5db3dd #8accee #bfe6f8 #eaf8ff") },
|
|
15
|
+
mono: { kind: "sequential", light: split("#f1f1ee #d9d9d4 #bfbfb8 #a4a49c #7e7e76 #6d6d66 #53534d #3a3a36 #22221f"), dark: split("#1f221f #3a3e3a #555a54 #70756e #8d928a #a9ada5 #c3c6bf #dcded8 #f5f6f2") },
|
|
16
|
+
balance: { kind: "diverging", light: split("#0f3f7a #2a6ab0 #5f9bd3 #a9cdea #f2f0eb #f3c9a0 #e69a5b #b85a22 #84340c"), dark: split("#8cc4ff #5a9fe6 #3a78bd #264f80 #1d2220 #6a4326 #a8642f #e08a42 #ffb66e") },
|
|
17
|
+
tide: { kind: "diverging", light: split("#4a1d6e #7b4aa3 #a98bc8 #d3c4e3 #f1f0ec #c3e1cb #86c397 #2a8a52 #0f5f33"), dark: split("#cfa8f0 #a47bd1 #7a53a8 #4d3170 #1d2220 #1f4a30 #2f7d4c #52b277 #8fe0aa") },
|
|
18
|
+
});
|
|
19
|
+
/** Names of the built-in ramps. */
|
|
20
|
+
export const HEAT_RAMP_NAMES = Object.freeze(Object.keys(HEAT_RAMPS));
|
|
21
|
+
const clean = (stops, what) => {
|
|
22
|
+
if (stops === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (!Array.isArray(stops))
|
|
25
|
+
throw new TypeError(`${what} is a list of colours`);
|
|
26
|
+
const out = stops.map((stop) => safeColour(stop)).filter((stop) => stop !== undefined);
|
|
27
|
+
if (out.length === 0)
|
|
28
|
+
throw new RangeError(`${what} has no colour that can be drawn`);
|
|
29
|
+
return out;
|
|
30
|
+
};
|
|
31
|
+
/** The ramp a layer asks for; `ember` when it asks for none (`fallback` for a diverging statistic). */
|
|
32
|
+
export function resolveRamp(ramp, fallback = "ember") {
|
|
33
|
+
const given = ramp ?? fallback;
|
|
34
|
+
if (typeof given === "string") {
|
|
35
|
+
if (!Object.prototype.hasOwnProperty.call(HEAT_RAMPS, given))
|
|
36
|
+
throw new RangeError(`Unknown ramp "${given}": use ${HEAT_RAMP_NAMES.join(", ")}, or a list of colours`);
|
|
37
|
+
const def = HEAT_RAMPS[given];
|
|
38
|
+
return { name: given, kind: def.kind, light: [...def.light], dark: [...def.dark] };
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(given))
|
|
41
|
+
return { name: undefined, kind: "sequential", light: clean(given, "ramp"), dark: undefined };
|
|
42
|
+
const object = given;
|
|
43
|
+
return { name: undefined, kind: "sequential", light: clean(object.light, "ramp.light"), dark: clean(object.dark, "ramp.dark") };
|
|
44
|
+
}
|
|
45
|
+
/** The colour of step `k` of `steps` (0 to `steps - 1`) of some stops, as a hex colour (or the nearest stop for a colour that cannot be read without a browser). */
|
|
46
|
+
export function stepColour(stops, k, steps) {
|
|
47
|
+
return rampColour(stops, steps <= 1 ? 1 : k / (steps - 1)) ?? stops[0];
|
|
48
|
+
}
|
|
49
|
+
/** The step (0 to `steps - 1`) a value falls in, on a domain: the share of the way through it, to the nearest step. */
|
|
50
|
+
export function stepOf(value, domain, steps) {
|
|
51
|
+
const [a, b] = domain;
|
|
52
|
+
const t = b === a ? 0.5 : (value - a) / (b - a);
|
|
53
|
+
return Math.max(0, Math.min(steps - 1, Math.round(t * (steps - 1))));
|
|
54
|
+
}
|
package/dist/heat.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ResolvedRamp } from "./heat.colour.ts";
|
|
2
|
+
import type { ContourLayer, HeatmapLayer, HexbinLayer, LegendLayer, ZonesLayer } from "./heat.types.ts";
|
|
3
|
+
import { type Env, type Made } from "./layers.env.ts";
|
|
4
|
+
/** The layers this file draws, except the legend. */
|
|
5
|
+
export type HeatLayer = HeatmapLayer | HexbinLayer | ZonesLayer | ContourLayer;
|
|
6
|
+
/** A ramp cut into steps over a domain. */
|
|
7
|
+
interface Colours {
|
|
8
|
+
ramp: ResolvedRamp;
|
|
9
|
+
steps: number;
|
|
10
|
+
domain: [number, number];
|
|
11
|
+
/** True when the ramp's pale end is left unused (a sequential ramp). */
|
|
12
|
+
floor: boolean;
|
|
13
|
+
/** True when the domain is symmetric about a value (so the ramp diverges). */
|
|
14
|
+
centre: number | undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Draw a heat layer. `gid` is the id of its group, which the dark colours of its ramp are scoped to. */
|
|
17
|
+
export declare function drawHeat(layer: HeatLayer, env: Env, gid: string, known?: Map<string, LegendInfo>): Made;
|
|
18
|
+
/** The marks counted into each zone of a zone chart, without drawing it: for each zone its id, its name (in the drawing's language), the marks in it, those whose outcome is a success and its value. */
|
|
19
|
+
export declare function zoneCounts(layer: ZonesLayer, env: Env): {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
n: number;
|
|
23
|
+
hits: number;
|
|
24
|
+
value: number | null;
|
|
25
|
+
}[];
|
|
26
|
+
/** What a legend takes from the layer it is for. */
|
|
27
|
+
export interface LegendInfo {
|
|
28
|
+
colours: Colours;
|
|
29
|
+
stat: string;
|
|
30
|
+
percent: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** A legend layer: a colour bar for another heat layer (`for`) or with a ramp and a domain of its own. `known` holds the colours of the layers drawn. */
|
|
33
|
+
export declare function drawLegend(layer: LegendLayer, env: Env, gid: string, known: ReadonlyMap<string, LegendInfo>): Made;
|
|
34
|
+
/** A table of a heat layer's numbers: the heading cells, the rows, and the note for the caption. */
|
|
35
|
+
export interface HeatTable {
|
|
36
|
+
head: string[];
|
|
37
|
+
rows: (string | number | null)[][];
|
|
38
|
+
title: string;
|
|
39
|
+
note: string;
|
|
40
|
+
}
|
|
41
|
+
/** The numbers a heat layer shows, as table rows: a row for each zone; the cells that hold something, the hottest first; or a row for each contour level. */
|
|
42
|
+
export declare function heatTable(layer: HeatLayer, env: Env): HeatTable;
|
|
43
|
+
export {};
|