@azohra/meteo.station 0.1.1
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/air.d.ts +13 -0
- package/dist/air.js +76 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.js +4 -0
- package/dist/client/poll.d.ts +42 -0
- package/dist/client/poll.js +121 -0
- package/dist/client/stores.d.ts +46 -0
- package/dist/client/stores.js +128 -0
- package/dist/client/ticker.d.ts +4 -0
- package/dist/client/ticker.js +19 -0
- package/dist/contract.d.ts +381 -0
- package/dist/contract.js +143 -0
- package/dist/derive.d.ts +54 -0
- package/dist/derive.js +134 -0
- package/dist/display.d.ts +28 -0
- package/dist/display.js +27 -0
- package/dist/elements/elements/AirMatrixElement.d.ts +14 -0
- package/dist/elements/elements/AirMatrixElement.js +83 -0
- package/dist/elements/elements/CurrentConditionsElement.d.ts +9 -0
- package/dist/elements/elements/CurrentConditionsElement.js +52 -0
- package/dist/elements/elements/DailyPatternElement.d.ts +15 -0
- package/dist/elements/elements/DailyPatternElement.js +200 -0
- package/dist/elements/elements/DialElement.d.ts +9 -0
- package/dist/elements/elements/DialElement.js +128 -0
- package/dist/elements/elements/FreshnessBadgeElement.d.ts +8 -0
- package/dist/elements/elements/FreshnessBadgeElement.js +22 -0
- package/dist/elements/elements/SparklineElement.d.ts +9 -0
- package/dist/elements/elements/SparklineElement.js +74 -0
- package/dist/elements/elements/StationCardElement.d.ts +53 -0
- package/dist/elements/elements/StationCardElement.js +211 -0
- package/dist/elements/elements/StationFeedElement.d.ts +32 -0
- package/dist/elements/elements/StationFeedElement.js +215 -0
- package/dist/elements/elements/StationStripElement.d.ts +9 -0
- package/dist/elements/elements/StationStripElement.js +43 -0
- package/dist/elements/elements/StationTableElement.d.ts +18 -0
- package/dist/elements/elements/StationTableElement.js +102 -0
- package/dist/elements/elements/TrendChartElement.d.ts +10 -0
- package/dist/elements/elements/TrendChartElement.js +174 -0
- package/dist/elements/elements/WindArrowElement.d.ts +8 -0
- package/dist/elements/elements/WindArrowElement.js +14 -0
- package/dist/elements/elements/WindHistoryChartElement.d.ts +10 -0
- package/dist/elements/elements/WindHistoryChartElement.js +277 -0
- package/dist/elements/elements/WindRoseElement.d.ts +17 -0
- package/dist/elements/elements/WindRoseElement.js +106 -0
- package/dist/elements/elements/atoms.d.ts +48 -0
- package/dist/elements/elements/atoms.js +131 -0
- package/dist/elements/index.d.ts +48 -0
- package/dist/elements/index.js +57 -0
- package/dist/elements/lib/ambient.d.ts +15 -0
- package/dist/elements/lib/ambient.js +5 -0
- package/dist/elements/lib/attributes.js +21 -0
- package/dist/elements/lib/base.d.ts +45 -0
- package/dist/elements/lib/base.js +152 -0
- package/dist/elements/lib/context.js +28 -0
- package/dist/elements/lib/fragments.js +45 -0
- package/dist/elements/lib/h.js +35 -0
- package/dist/elements/register.d.ts +1 -0
- package/dist/elements/register.js +5 -0
- package/dist/endpoints.d.ts +5 -0
- package/dist/endpoints.js +10 -0
- package/dist/fixtures.d.ts +23 -0
- package/dist/fixtures.js +67 -0
- package/dist/format.d.ts +31 -0
- package/dist/format.js +82 -0
- package/dist/geometry.d.ts +84 -0
- package/dist/geometry.js +333 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/instruments.d.ts +75 -0
- package/dist/instruments.js +173 -0
- package/dist/merge-current.d.ts +13 -0
- package/dist/merge-current.js +54 -0
- package/dist/react/components/AirMatrix.d.ts +11 -0
- package/dist/react/components/AirMatrix.js +82 -0
- package/dist/react/components/CurrentConditions.d.ts +17 -0
- package/dist/react/components/CurrentConditions.js +98 -0
- package/dist/react/components/DailyPattern.d.ts +19 -0
- package/dist/react/components/DailyPattern.js +212 -0
- package/dist/react/components/Dial.d.ts +17 -0
- package/dist/react/components/Dial.js +133 -0
- package/dist/react/components/FreshnessBadge.d.ts +10 -0
- package/dist/react/components/FreshnessBadge.js +20 -0
- package/dist/react/components/Sparkline.d.ts +17 -0
- package/dist/react/components/Sparkline.js +60 -0
- package/dist/react/components/StationCard.d.ts +46 -0
- package/dist/react/components/StationCard.js +140 -0
- package/dist/react/components/StationFeedProvider.d.ts +27 -0
- package/dist/react/components/StationFeedProvider.js +40 -0
- package/dist/react/components/StationStrip.d.ts +16 -0
- package/dist/react/components/StationStrip.js +84 -0
- package/dist/react/components/StationTable.d.ts +18 -0
- package/dist/react/components/StationTable.js +115 -0
- package/dist/react/components/TrendChart.d.ts +14 -0
- package/dist/react/components/TrendChart.js +150 -0
- package/dist/react/components/WindArrow.d.ts +7 -0
- package/dist/react/components/WindArrow.js +21 -0
- package/dist/react/components/WindHistoryChart.d.ts +18 -0
- package/dist/react/components/WindHistoryChart.js +278 -0
- package/dist/react/components/WindRose.d.ts +17 -0
- package/dist/react/components/WindRose.js +99 -0
- package/dist/react/components/atoms.d.ts +33 -0
- package/dist/react/components/atoms.js +136 -0
- package/dist/react/hooks/useFreshness.d.ts +6 -0
- package/dist/react/hooks/useFreshness.js +21 -0
- package/dist/react/hooks/usePolledJson.js +17 -0
- package/dist/react/hooks/useStation.d.ts +23 -0
- package/dist/react/hooks/useStation.js +42 -0
- package/dist/react/hooks/useStationCurrent.d.ts +23 -0
- package/dist/react/hooks/useStationCurrent.js +32 -0
- package/dist/react/hooks/useStationFeed.d.ts +22 -0
- package/dist/react/hooks/useStationFeed.js +28 -0
- package/dist/react/index.d.ts +20 -0
- package/dist/react/index.js +21 -0
- package/dist/react/lib/cells.js +29 -0
- package/dist/scene/air-matrix.js +71 -0
- package/dist/scene/atoms.js +102 -0
- package/dist/scene/card.js +54 -0
- package/dist/scene/chart.js +28 -0
- package/dist/scene/current.js +66 -0
- package/dist/scene/daily-pattern.js +81 -0
- package/dist/scene/dial.js +141 -0
- package/dist/scene/glyphs.js +24 -0
- package/dist/scene/rose.js +120 -0
- package/dist/scene/sparkline.js +73 -0
- package/dist/scene/strip.js +63 -0
- package/dist/scene/table.js +76 -0
- package/dist/scene/trend.js +160 -0
- package/dist/scene/wind-history.js +148 -0
- package/dist/scene/wind-plot.js +214 -0
- package/dist/server/adapter.d.ts +28 -0
- package/dist/server/adapter.js +32 -0
- package/dist/server/adapters/campbell.d.ts +112 -0
- package/dist/server/adapters/campbell.js +414 -0
- package/dist/server/adapters/tempest.d.ts +27 -0
- package/dist/server/adapters/tempest.js +137 -0
- package/dist/server/adapters/windnerd.d.ts +39 -0
- package/dist/server/adapters/windnerd.js +159 -0
- package/dist/server/config.d.ts +135 -0
- package/dist/server/config.js +57 -0
- package/dist/server/environment.d.ts +48 -0
- package/dist/server/environment.js +128 -0
- package/dist/server/feed.d.ts +31 -0
- package/dist/server/feed.js +216 -0
- package/dist/server/handler.d.ts +17 -0
- package/dist/server/handler.js +133 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +10 -0
- package/dist/strings.d.ts +118 -0
- package/dist/strings.js +237 -0
- package/dist/windnerd.d.ts +5 -0
- package/dist/windnerd.js +25 -0
- package/package.json +97 -0
- package/schema/README.md +14 -0
- package/schema/example-current.json +48 -0
- package/schema/example-feed.json +147 -0
- package/schema/stationcurrent.schema.json +641 -0
- package/schema/stationfeed.schema.json +656 -0
- package/styles.css +1141 -0
package/dist/derive.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { KMH_PER_MPS, degreesToRadians, normalizeDegrees } from "@azohra/meteo.core";
|
|
2
|
+
//#region src/derive.ts
|
|
3
|
+
const CALM_THRESHOLD_MPS = .5;
|
|
4
|
+
function isCalm(speedMps) {
|
|
5
|
+
return speedMps < CALM_THRESHOLD_MPS;
|
|
6
|
+
}
|
|
7
|
+
const SPEED_UNITS = [
|
|
8
|
+
"kmh",
|
|
9
|
+
"knots",
|
|
10
|
+
"mph",
|
|
11
|
+
"mps"
|
|
12
|
+
];
|
|
13
|
+
const KNOTS_PER_MPS = 1 / .514444;
|
|
14
|
+
const MPH_PER_MPS = 1 / .44704;
|
|
15
|
+
function unitsPerMps(unit) {
|
|
16
|
+
switch (unit) {
|
|
17
|
+
case "kmh": return KMH_PER_MPS;
|
|
18
|
+
case "knots": return KNOTS_PER_MPS;
|
|
19
|
+
case "mph": return MPH_PER_MPS;
|
|
20
|
+
case "mps": return 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function speedFromMps(mps, unit) {
|
|
24
|
+
return mps * unitsPerMps(unit);
|
|
25
|
+
}
|
|
26
|
+
function speedToMps(value, unit) {
|
|
27
|
+
return value / unitsPerMps(unit);
|
|
28
|
+
}
|
|
29
|
+
function thresholdsToMps(thresholds) {
|
|
30
|
+
return thresholds.values.map((value) => speedToMps(value, thresholds.unit));
|
|
31
|
+
}
|
|
32
|
+
function speedUnitLabel(unit) {
|
|
33
|
+
switch (unit) {
|
|
34
|
+
case "kmh": return "km/h";
|
|
35
|
+
case "knots": return "kn";
|
|
36
|
+
case "mph": return "mph";
|
|
37
|
+
case "mps": return "m/s";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function radians(value) {
|
|
41
|
+
return degreesToRadians(value);
|
|
42
|
+
}
|
|
43
|
+
const COMPASS_POINTS = [
|
|
44
|
+
"N",
|
|
45
|
+
"NNE",
|
|
46
|
+
"NE",
|
|
47
|
+
"ENE",
|
|
48
|
+
"E",
|
|
49
|
+
"ESE",
|
|
50
|
+
"SE",
|
|
51
|
+
"SSE",
|
|
52
|
+
"S",
|
|
53
|
+
"SSW",
|
|
54
|
+
"SW",
|
|
55
|
+
"WSW",
|
|
56
|
+
"W",
|
|
57
|
+
"WNW",
|
|
58
|
+
"NW",
|
|
59
|
+
"NNW"
|
|
60
|
+
];
|
|
61
|
+
function compassDirection(bearingDeg) {
|
|
62
|
+
const normalized = normalizeDegrees(bearingDeg);
|
|
63
|
+
return COMPASS_POINTS[Math.round(normalized / 22.5) % COMPASS_POINTS.length];
|
|
64
|
+
}
|
|
65
|
+
function periodSummary(history) {
|
|
66
|
+
const points = history.points;
|
|
67
|
+
const last = points[points.length - 1];
|
|
68
|
+
if (!last) return null;
|
|
69
|
+
const speedSum = points.reduce((total, point) => total + point.windAvgMps, 0);
|
|
70
|
+
let peak = null;
|
|
71
|
+
let lowestLullMps = null;
|
|
72
|
+
let high = null;
|
|
73
|
+
let low = null;
|
|
74
|
+
for (const point of points) {
|
|
75
|
+
if (point.windGustMps != null && (peak == null || point.windGustMps > peak.windGustMps)) peak = point;
|
|
76
|
+
if (point.windLullMps != null) lowestLullMps = lowestLullMps == null ? point.windLullMps : Math.min(lowestLullMps, point.windLullMps);
|
|
77
|
+
if (point.temperatureC != null) {
|
|
78
|
+
if (high == null || point.temperatureC > high.temperatureC) high = point;
|
|
79
|
+
if (low == null || point.temperatureC < low.temperatureC) low = point;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
windAvgMps: speedSum / points.length,
|
|
84
|
+
peakGustMps: peak?.windGustMps ?? null,
|
|
85
|
+
peakGustAt: peak?.observedAt ?? null,
|
|
86
|
+
lowestLullMps,
|
|
87
|
+
periodEndedAt: last.observedAt,
|
|
88
|
+
temperatureHighC: high?.temperatureC ?? null,
|
|
89
|
+
temperatureHighAt: high?.observedAt ?? null,
|
|
90
|
+
temperatureLowC: low?.temperatureC ?? null,
|
|
91
|
+
temperatureLowAt: low?.observedAt ?? null,
|
|
92
|
+
windRunKm: speedSum * history.periodMinutes * 60 / 1e3
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function seaLevelPressureHpa(stationPressureHpa, elevationM, temperatureC = 15) {
|
|
96
|
+
const temperature = temperatureC ?? 15;
|
|
97
|
+
const factor = 1 - .0065 * elevationM / (temperature + .0065 * elevationM + 273.15);
|
|
98
|
+
return stationPressureHpa * Math.pow(factor, -5.257);
|
|
99
|
+
}
|
|
100
|
+
function pressureTendency(points, { windowHours = 3, thresholdHpa = 1.5 } = {}) {
|
|
101
|
+
const carrying = points.filter((point) => point.seaLevelPressureHpa != null);
|
|
102
|
+
const last = carrying[carrying.length - 1];
|
|
103
|
+
if (!last) return null;
|
|
104
|
+
const targetMs = Date.parse(last.observedAt) - windowHours * 36e5;
|
|
105
|
+
let reference = null;
|
|
106
|
+
for (const point of carrying) if (reference == null || Math.abs(Date.parse(point.observedAt) - targetMs) < Math.abs(Date.parse(reference.observedAt) - targetMs)) reference = point;
|
|
107
|
+
if (reference == null || Date.parse(last.observedAt) - Date.parse(reference.observedAt) < windowHours * 36e5 * .6) return null;
|
|
108
|
+
const delta = last.seaLevelPressureHpa - reference.seaLevelPressureHpa;
|
|
109
|
+
if (delta >= thresholdHpa) return "rising";
|
|
110
|
+
if (delta <= -thresholdHpa) return "falling";
|
|
111
|
+
return "steady";
|
|
112
|
+
}
|
|
113
|
+
const DEFAULT_FRESHNESS_THRESHOLDS = {
|
|
114
|
+
currentForMs: 10 * 6e4,
|
|
115
|
+
staleAfterMs: 45 * 6e4
|
|
116
|
+
};
|
|
117
|
+
const clampMs = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
118
|
+
function stationFreshnessThresholds(meta) {
|
|
119
|
+
const currentForMs = clampMs(meta.recommendedPollSeconds * 5 * 1e3, 6e4, 10 * 6e4);
|
|
120
|
+
return {
|
|
121
|
+
currentForMs,
|
|
122
|
+
staleAfterMs: clampMs(currentForMs * 6, 10 * 6e4, 45 * 6e4)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function freshness(input, thresholds = DEFAULT_FRESHNESS_THRESHOLDS) {
|
|
126
|
+
const ageAtServeMs = Date.parse(input.servedAt) - Date.parse(input.observedAt);
|
|
127
|
+
const sinceReceivedMs = Math.max(0, input.nowMs - input.receivedAtMs);
|
|
128
|
+
const ageMs = Math.max(0, ageAtServeMs) + sinceReceivedMs;
|
|
129
|
+
if (ageMs <= thresholds.currentForMs) return "live";
|
|
130
|
+
if (ageMs <= thresholds.staleAfterMs) return "aging";
|
|
131
|
+
return "stale";
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, compassDirection, freshness, isCalm, normalizeDegrees, periodSummary, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Station, StationFeed } from "./contract.js";
|
|
2
|
+
import { SpeedThresholds, SpeedUnit } from "./derive.js";
|
|
3
|
+
import { FormatTime, StationStringOverrides, StationStrings } from "./strings.js";
|
|
4
|
+
//#region src/display.d.ts
|
|
5
|
+
type DisplayDefaults = {
|
|
6
|
+
strings?: StationStringOverrides | undefined;
|
|
7
|
+
unit?: SpeedUnit | undefined;
|
|
8
|
+
formatTime?: FormatTime | undefined;
|
|
9
|
+
thresholds?: SpeedThresholds | undefined;
|
|
10
|
+
};
|
|
11
|
+
type DisplayProps = {
|
|
12
|
+
strings?: StationStringOverrides | undefined;
|
|
13
|
+
unit?: SpeedUnit | undefined;
|
|
14
|
+
formatTime?: FormatTime | undefined;
|
|
15
|
+
thresholds?: SpeedThresholds | null | undefined;
|
|
16
|
+
};
|
|
17
|
+
type ResolvedDisplay = {
|
|
18
|
+
strings: StationStringOverrides | undefined;
|
|
19
|
+
words: StationStrings;
|
|
20
|
+
unit: SpeedUnit;
|
|
21
|
+
formatTime: FormatTime;
|
|
22
|
+
thresholds: SpeedThresholds | undefined;
|
|
23
|
+
};
|
|
24
|
+
declare function resolveDisplay(defaults: DisplayDefaults | null | undefined, props: DisplayProps): ResolvedDisplay;
|
|
25
|
+
declare function resolveStation(feed: StationFeed | null | undefined, stationId: string | undefined): Station | null;
|
|
26
|
+
declare function requireResolved<T>(component: string, what: string, value: T | null | undefined, ambientHint: string): T;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { DisplayDefaults, DisplayProps, ResolvedDisplay, requireResolved, resolveDisplay, resolveStation };
|
package/dist/display.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defaultFormatTime, mergeStringOverrides, resolveStrings } from "./strings.js";
|
|
2
|
+
//#region src/display.ts
|
|
3
|
+
function resolveDisplay(defaults, props) {
|
|
4
|
+
const strings = mergeStringOverrides(defaults?.strings, props.strings);
|
|
5
|
+
return {
|
|
6
|
+
strings,
|
|
7
|
+
words: resolveStrings(strings),
|
|
8
|
+
unit: props.unit ?? defaults?.unit ?? "kmh",
|
|
9
|
+
formatTime: props.formatTime ?? defaults?.formatTime ?? defaultFormatTime,
|
|
10
|
+
thresholds: props.thresholds === void 0 ? defaults?.thresholds : props.thresholds ?? void 0
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function resolveStation(feed, stationId) {
|
|
14
|
+
if (feed == null) return null;
|
|
15
|
+
if (stationId != null) return feed.stations.find((station) => station.id === stationId) ?? null;
|
|
16
|
+
if (feed.primaryStationId != null) {
|
|
17
|
+
const primary = feed.stations.find((station) => station.id === feed.primaryStationId);
|
|
18
|
+
if (primary != null) return primary;
|
|
19
|
+
}
|
|
20
|
+
return feed.stations[0] ?? null;
|
|
21
|
+
}
|
|
22
|
+
function requireResolved(component, what, value, ambientHint) {
|
|
23
|
+
if (value == null) throw new Error(`<${component}> resolved no ${what} — pass the prop explicitly or ${ambientHint}.`);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { requireResolved, resolveDisplay, resolveStation };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Station } from "../../contract.js";
|
|
2
|
+
import "../../index.js";
|
|
3
|
+
import { MeteoStationElement } from "../lib/base.js";
|
|
4
|
+
//#region src/elements/elements/AirMatrixElement.d.ts
|
|
5
|
+
declare class AirMatrixElement extends MeteoStationElement {
|
|
6
|
+
#private;
|
|
7
|
+
static readonly observedAttributes: string[];
|
|
8
|
+
constructor();
|
|
9
|
+
get stations(): readonly Station[] | undefined;
|
|
10
|
+
set stations(value: readonly Station[] | undefined);
|
|
11
|
+
protected render(): void;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { AirMatrixElement };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { requireResolved } from "../../display.js";
|
|
2
|
+
import { airMatrixScene } from "../../scene/air-matrix.js";
|
|
3
|
+
import { ELEMENTS_AMBIENT_HINT } from "../lib/ambient.js";
|
|
4
|
+
import { MeteoStationElement } from "../lib/base.js";
|
|
5
|
+
import { h } from "../lib/h.js";
|
|
6
|
+
//#region src/elements/elements/AirMatrixElement.ts
|
|
7
|
+
let panelCounter = 0;
|
|
8
|
+
var AirMatrixElement = class extends MeteoStationElement {
|
|
9
|
+
static observedAttributes = ["received-at-ms", "served-at"];
|
|
10
|
+
#stations;
|
|
11
|
+
#expanded = false;
|
|
12
|
+
#panelId = `meteo-air-e${++panelCounter}`;
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.upgradeProperty("stations");
|
|
16
|
+
}
|
|
17
|
+
get stations() {
|
|
18
|
+
return this.#stations;
|
|
19
|
+
}
|
|
20
|
+
set stations(value) {
|
|
21
|
+
this.#stations = value;
|
|
22
|
+
this.requestRender();
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
const stations = requireResolved("meteo-air-matrix", "stations", this.#stations ?? this.ambient()?.feed?.stations, ELEMENTS_AMBIENT_HINT);
|
|
26
|
+
const { formatTime, words } = this.display();
|
|
27
|
+
const expanded = this.#expanded;
|
|
28
|
+
const scene = airMatrixScene({
|
|
29
|
+
formatTime,
|
|
30
|
+
stations,
|
|
31
|
+
words
|
|
32
|
+
});
|
|
33
|
+
if (scene == null) {
|
|
34
|
+
this.replaceChildren();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const rowStyled = (element) => {
|
|
38
|
+
element.style.gridTemplateColumns = scene.matrix.gridTemplateColumns;
|
|
39
|
+
return element;
|
|
40
|
+
};
|
|
41
|
+
this.replaceChildren(h("section", {
|
|
42
|
+
class: scene.className,
|
|
43
|
+
"data-expanded": String(expanded)
|
|
44
|
+
}, h("button", {
|
|
45
|
+
"aria-controls": this.#panelId,
|
|
46
|
+
"aria-expanded": String(expanded),
|
|
47
|
+
class: scene.trigger.className,
|
|
48
|
+
onclick: () => {
|
|
49
|
+
this.#expanded = !this.#expanded;
|
|
50
|
+
this.requestRender();
|
|
51
|
+
},
|
|
52
|
+
type: "button"
|
|
53
|
+
}, h("strong", { class: scene.trigger.title.className }, scene.trigger.title.text), h("span", { class: scene.trigger.summary.className }, scene.trigger.summary.text)), h("div", {
|
|
54
|
+
class: scene.panelClassName,
|
|
55
|
+
hidden: !expanded,
|
|
56
|
+
id: this.#panelId
|
|
57
|
+
}, h("div", {
|
|
58
|
+
"aria-label": scene.matrix.ariaLabel,
|
|
59
|
+
class: scene.matrix.className,
|
|
60
|
+
role: "table"
|
|
61
|
+
}, rowStyled(h("div", {
|
|
62
|
+
class: scene.matrix.head.className,
|
|
63
|
+
role: "row"
|
|
64
|
+
}, h("span", {
|
|
65
|
+
class: scene.matrix.head.corner.className,
|
|
66
|
+
role: "columnheader"
|
|
67
|
+
}), scene.matrix.head.columns.map((column) => h("span", {
|
|
68
|
+
class: scene.matrix.head.columnClassName,
|
|
69
|
+
role: "columnheader"
|
|
70
|
+
}, column.text)))), scene.matrix.rows.map((row) => rowStyled(h("div", {
|
|
71
|
+
class: row.className,
|
|
72
|
+
role: "row"
|
|
73
|
+
}, h("span", {
|
|
74
|
+
class: row.labelClassName,
|
|
75
|
+
role: "rowheader"
|
|
76
|
+
}, row.label, h("small", null, row.unit)), row.cells.map((cell) => h("span", {
|
|
77
|
+
class: cell.className,
|
|
78
|
+
role: "cell"
|
|
79
|
+
}, cell.text)))))), h("p", { class: scene.note.className }, scene.note.text))));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
//#endregion
|
|
83
|
+
export { AirMatrixElement };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MeteoStationElement } from "../lib/base.js";
|
|
2
|
+
//#region src/elements/elements/CurrentConditionsElement.d.ts
|
|
3
|
+
declare class CurrentConditionsElement extends MeteoStationElement {
|
|
4
|
+
static readonly observedAttributes: string[];
|
|
5
|
+
protected connected(): void;
|
|
6
|
+
protected render(): void;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { CurrentConditionsElement };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { currentConditionsScene } from "../../scene/current.js";
|
|
2
|
+
import { MeteoStationElement } from "../lib/base.js";
|
|
3
|
+
import { h } from "../lib/h.js";
|
|
4
|
+
import { freshnessBadgeSpan, windArrowSvg } from "../lib/fragments.js";
|
|
5
|
+
import { dialSvg } from "./DialElement.js";
|
|
6
|
+
//#region src/elements/elements/CurrentConditionsElement.ts
|
|
7
|
+
var CurrentConditionsElement = class extends MeteoStationElement {
|
|
8
|
+
static observedAttributes = [
|
|
9
|
+
"received-at-ms",
|
|
10
|
+
"served-at",
|
|
11
|
+
"station-id",
|
|
12
|
+
"thresholds",
|
|
13
|
+
"unit"
|
|
14
|
+
];
|
|
15
|
+
connected() {
|
|
16
|
+
this.watchFreshness();
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
const station = this.requiredStation("meteo-current-conditions");
|
|
20
|
+
const { formatTime, thresholds, unit, words } = this.display();
|
|
21
|
+
const status = this.freshnessOf(station);
|
|
22
|
+
const scene = currentConditionsScene({
|
|
23
|
+
formatTime,
|
|
24
|
+
station,
|
|
25
|
+
unit,
|
|
26
|
+
words
|
|
27
|
+
});
|
|
28
|
+
const { direction, temperature, footer } = scene;
|
|
29
|
+
const directionChildren = direction.content.kind === "text" ? [direction.content.text] : [
|
|
30
|
+
h("span", { class: direction.content.labelClassName }, direction.content.label),
|
|
31
|
+
" ",
|
|
32
|
+
windArrowSvg(direction.content.deg),
|
|
33
|
+
" ",
|
|
34
|
+
h("strong", null, direction.content.compass),
|
|
35
|
+
direction.content.tail
|
|
36
|
+
];
|
|
37
|
+
this.replaceChildren(h("div", {
|
|
38
|
+
"aria-label": scene.root.ariaLabel,
|
|
39
|
+
class: scene.root.className,
|
|
40
|
+
"data-status": scene.root.status,
|
|
41
|
+
role: "group"
|
|
42
|
+
}, h("div", { class: scene.instrumentClassName }, scene.flanks != null && h("div", { class: scene.flanks.lull.className }, h("small", { class: scene.flanks.lull.labelClassName }, scene.flanks.lull.label), h("strong", null, scene.flanks.lull.value)), dialSvg({
|
|
43
|
+
station,
|
|
44
|
+
thresholds,
|
|
45
|
+
unit,
|
|
46
|
+
words,
|
|
47
|
+
calmWord: false
|
|
48
|
+
}), scene.flanks != null && h("div", { class: scene.flanks.gust.className }, h("small", { class: scene.flanks.gust.labelClassName }, scene.flanks.gust.label), h("strong", null, scene.flanks.gust.value))), h("p", { class: direction.className }, ...directionChildren), temperature != null && h("p", { class: temperature.className }, temperature.text, temperature.chill != null && h("span", { class: temperature.chill.className }, temperature.chill.text)), h("p", { class: footer.className }, status != null && freshnessBadgeSpan(status, words), h("span", { class: footer.observed.className }, footer.observed.text))));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { CurrentConditionsElement };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HistoryPoint } from "../../contract.js";
|
|
2
|
+
import "../../index.js";
|
|
3
|
+
import { MeteoStationElement } from "../lib/base.js";
|
|
4
|
+
//#region src/elements/elements/DailyPatternElement.d.ts
|
|
5
|
+
declare class DailyPatternElement extends MeteoStationElement {
|
|
6
|
+
#private;
|
|
7
|
+
static readonly observedAttributes: string[];
|
|
8
|
+
constructor();
|
|
9
|
+
get points(): HistoryPoint[] | undefined;
|
|
10
|
+
set points(value: HistoryPoint[] | undefined);
|
|
11
|
+
protected disconnected(): void;
|
|
12
|
+
protected render(): void;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { DailyPatternElement };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { resolveStation } from "../../display.js";
|
|
2
|
+
import "../../geometry.js";
|
|
3
|
+
import { measuredChartWidth } from "../../scene/chart.js";
|
|
4
|
+
import { DAILY_PATTERN_CLASS, dailyPatternGate, dailyPatternScene, dailyPatternSource } from "../../scene/daily-pattern.js";
|
|
5
|
+
import { numberAttribute } from "../lib/attributes.js";
|
|
6
|
+
import { MeteoStationElement } from "../lib/base.js";
|
|
7
|
+
import { h, hs } from "../lib/h.js";
|
|
8
|
+
//#region src/elements/elements/DailyPatternElement.ts
|
|
9
|
+
let hatchCounter = 0;
|
|
10
|
+
var DailyPatternElement = class extends MeteoStationElement {
|
|
11
|
+
static observedAttributes = [
|
|
12
|
+
"plot-height",
|
|
13
|
+
"slot-minutes",
|
|
14
|
+
"station-id",
|
|
15
|
+
"thresholds",
|
|
16
|
+
"unit",
|
|
17
|
+
"utc-offset-minutes"
|
|
18
|
+
];
|
|
19
|
+
#points;
|
|
20
|
+
#width = null;
|
|
21
|
+
#observer = null;
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.upgradeProperty("points");
|
|
25
|
+
}
|
|
26
|
+
get points() {
|
|
27
|
+
return this.#points;
|
|
28
|
+
}
|
|
29
|
+
set points(value) {
|
|
30
|
+
this.#points = value;
|
|
31
|
+
this.requestRender();
|
|
32
|
+
}
|
|
33
|
+
disconnected() {
|
|
34
|
+
this.#observer?.disconnect();
|
|
35
|
+
this.#observer = null;
|
|
36
|
+
}
|
|
37
|
+
render() {
|
|
38
|
+
const station = this.station ?? (this.#points == null ? resolveStation(this.ambient()?.feed ?? null, this.getAttribute("station-id") ?? void 0) ?? void 0 : void 0);
|
|
39
|
+
const { thresholds, unit, words } = this.display();
|
|
40
|
+
const { source, periodMinutes } = dailyPatternSource(this.#points, station);
|
|
41
|
+
const gate = dailyPatternGate(source, words);
|
|
42
|
+
if (gate.kind === "note") {
|
|
43
|
+
this.#observer?.disconnect();
|
|
44
|
+
this.#observer = null;
|
|
45
|
+
this.replaceChildren(h("div", {
|
|
46
|
+
class: gate.className,
|
|
47
|
+
role: "note"
|
|
48
|
+
}, gate.text));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const wrap = h("div", { class: DAILY_PATTERN_CLASS });
|
|
52
|
+
this.replaceChildren(wrap);
|
|
53
|
+
this.#observe(wrap);
|
|
54
|
+
if (this.#width == null) return;
|
|
55
|
+
this.#buildChart(wrap, source, periodMinutes, thresholds, unit, words, this.#width, station?.name);
|
|
56
|
+
}
|
|
57
|
+
#observe(wrap) {
|
|
58
|
+
this.#observer?.disconnect();
|
|
59
|
+
if (typeof ResizeObserver === "undefined") {
|
|
60
|
+
this.#width = 360;
|
|
61
|
+
this.#observer = null;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.#observer = new ResizeObserver((entries) => {
|
|
65
|
+
const width = measuredChartWidth(entries[0]?.contentRect.width ?? 0);
|
|
66
|
+
if (width !== this.#width) {
|
|
67
|
+
this.#width = width;
|
|
68
|
+
this.requestRender();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
this.#observer.observe(wrap);
|
|
72
|
+
}
|
|
73
|
+
#buildChart(wrap, points, periodMinutes, thresholds, unit, words, width, stationName) {
|
|
74
|
+
const scene = dailyPatternScene({
|
|
75
|
+
hatchId: `meteo-daily-pattern-hatch-e${++hatchCounter}`,
|
|
76
|
+
periodMinutes,
|
|
77
|
+
plotHeight: numberAttribute(this.getAttribute("plot-height")),
|
|
78
|
+
points,
|
|
79
|
+
slotMinutes: numberAttribute(this.getAttribute("slot-minutes")) ?? 180,
|
|
80
|
+
stationName,
|
|
81
|
+
thresholds,
|
|
82
|
+
unit,
|
|
83
|
+
utcOffsetMinutes: numberAttribute(this.getAttribute("utc-offset-minutes")) ?? 0,
|
|
84
|
+
width,
|
|
85
|
+
words
|
|
86
|
+
});
|
|
87
|
+
const caption = h("output", { class: scene.caption.className }, scene.caption.text);
|
|
88
|
+
const svg = hs("svg", {
|
|
89
|
+
"aria-label": scene.svg.ariaLabel,
|
|
90
|
+
class: scene.svg.className,
|
|
91
|
+
height: scene.svg.height,
|
|
92
|
+
role: "img",
|
|
93
|
+
viewBox: scene.svg.viewBox,
|
|
94
|
+
width: scene.svg.width
|
|
95
|
+
}, hs("defs", null, hs("pattern", {
|
|
96
|
+
height: scene.defs.pattern.height,
|
|
97
|
+
id: scene.defs.pattern.id,
|
|
98
|
+
patternTransform: scene.defs.pattern.transform,
|
|
99
|
+
patternUnits: scene.defs.pattern.units,
|
|
100
|
+
width: scene.defs.pattern.width
|
|
101
|
+
}, hs("line", {
|
|
102
|
+
class: scene.defs.pattern.line.className,
|
|
103
|
+
x1: scene.defs.pattern.line.x1,
|
|
104
|
+
x2: scene.defs.pattern.line.x2,
|
|
105
|
+
y1: scene.defs.pattern.line.y1,
|
|
106
|
+
y2: scene.defs.pattern.line.y2
|
|
107
|
+
}))), scene.zones.map((zone) => hs("rect", {
|
|
108
|
+
class: zone.className,
|
|
109
|
+
height: zone.height,
|
|
110
|
+
width: zone.width,
|
|
111
|
+
x: zone.x,
|
|
112
|
+
y: zone.y
|
|
113
|
+
})), scene.grid.map(({ line, label }) => hs("g", null, hs("line", {
|
|
114
|
+
class: line.className,
|
|
115
|
+
x1: line.x1,
|
|
116
|
+
x2: line.x2,
|
|
117
|
+
y1: line.y1,
|
|
118
|
+
y2: line.y2
|
|
119
|
+
}), hs("text", {
|
|
120
|
+
class: label.className,
|
|
121
|
+
"text-anchor": label.anchor,
|
|
122
|
+
x: label.x,
|
|
123
|
+
y: label.y
|
|
124
|
+
}, label.text))), scene.thresholdGuides.map(({ line, label }) => hs("g", null, hs("line", {
|
|
125
|
+
class: line.className,
|
|
126
|
+
x1: line.x1,
|
|
127
|
+
x2: line.x2,
|
|
128
|
+
y1: line.y1,
|
|
129
|
+
y2: line.y2
|
|
130
|
+
}), hs("text", {
|
|
131
|
+
class: label.className,
|
|
132
|
+
"text-anchor": label.anchor,
|
|
133
|
+
x: label.x,
|
|
134
|
+
y: label.y
|
|
135
|
+
}, label.text))), scene.vaneGuides.map((guide) => hs("line", {
|
|
136
|
+
class: guide.className,
|
|
137
|
+
x1: guide.x1,
|
|
138
|
+
x2: guide.x2,
|
|
139
|
+
y1: guide.y1,
|
|
140
|
+
y2: guide.y2
|
|
141
|
+
})), scene.gaps.map((gap) => hs("rect", {
|
|
142
|
+
class: gap.className,
|
|
143
|
+
fill: gap.fill,
|
|
144
|
+
height: gap.height,
|
|
145
|
+
width: gap.width,
|
|
146
|
+
x: gap.x,
|
|
147
|
+
y: gap.y
|
|
148
|
+
})), scene.mean.kind === "polyline" ? hs("polyline", {
|
|
149
|
+
class: scene.mean.className,
|
|
150
|
+
points: scene.mean.points
|
|
151
|
+
}) : scene.mean.segments.map((segment) => hs("line", {
|
|
152
|
+
class: segment.className,
|
|
153
|
+
x1: segment.x1,
|
|
154
|
+
x2: segment.x2,
|
|
155
|
+
y1: segment.y1,
|
|
156
|
+
y2: segment.y2
|
|
157
|
+
})), scene.calmNote != null && hs("text", {
|
|
158
|
+
class: scene.calmNote.className,
|
|
159
|
+
"text-anchor": scene.calmNote.anchor,
|
|
160
|
+
x: scene.calmNote.x,
|
|
161
|
+
y: scene.calmNote.y
|
|
162
|
+
}, scene.calmNote.text), hs("text", {
|
|
163
|
+
class: scene.rowLabels.to.className,
|
|
164
|
+
"text-anchor": scene.rowLabels.to.anchor,
|
|
165
|
+
x: scene.rowLabels.to.x,
|
|
166
|
+
y: scene.rowLabels.to.y
|
|
167
|
+
}, scene.rowLabels.to.text), scene.vanes.map((vane) => vane.mark.kind === "calm" ? hs("text", {
|
|
168
|
+
class: vane.mark.text.className,
|
|
169
|
+
"text-anchor": vane.mark.text.anchor,
|
|
170
|
+
x: vane.mark.text.x,
|
|
171
|
+
y: vane.mark.text.y
|
|
172
|
+
}, vane.mark.text.text) : hs("path", {
|
|
173
|
+
class: vane.mark.className,
|
|
174
|
+
d: vane.mark.d
|
|
175
|
+
})), scene.vanes.map((vane) => hs("text", {
|
|
176
|
+
class: vane.label.className,
|
|
177
|
+
"text-anchor": vane.label.anchor,
|
|
178
|
+
x: vane.label.x,
|
|
179
|
+
y: vane.label.y
|
|
180
|
+
}, vane.label.text)), hs("text", {
|
|
181
|
+
class: scene.rowLabels.avg.className,
|
|
182
|
+
"text-anchor": scene.rowLabels.avg.anchor,
|
|
183
|
+
x: scene.rowLabels.avg.x,
|
|
184
|
+
y: scene.rowLabels.avg.y
|
|
185
|
+
}, scene.rowLabels.avg.text), scene.vanes.map((vane) => hs("text", {
|
|
186
|
+
class: vane.value.className,
|
|
187
|
+
"text-anchor": vane.value.anchor,
|
|
188
|
+
x: vane.value.x,
|
|
189
|
+
y: vane.value.y
|
|
190
|
+
}, vane.value.text)), scene.ticks.map((tick) => hs("text", {
|
|
191
|
+
class: tick.className,
|
|
192
|
+
"text-anchor": tick.anchor,
|
|
193
|
+
x: tick.x,
|
|
194
|
+
y: tick.y
|
|
195
|
+
}, tick.text)));
|
|
196
|
+
wrap.replaceChildren(caption, svg);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
//#endregion
|
|
200
|
+
export { DailyPatternElement };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "../../index.js";
|
|
2
|
+
import { MeteoStationElement } from "../lib/base.js";
|
|
3
|
+
//#region src/elements/elements/DialElement.d.ts
|
|
4
|
+
declare class DialElement extends MeteoStationElement {
|
|
5
|
+
static readonly observedAttributes: string[];
|
|
6
|
+
protected render(): void;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DialElement };
|