@azohra/meteo.station 0.5.0 → 0.6.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/README.md +1 -1
- package/dist/client/climatology.js +1 -1
- package/dist/client/history.js +3 -11
- package/dist/client/live.d.ts +2 -1
- package/dist/client/live.js +7 -4
- package/dist/client/stores.js +10 -2
- package/dist/climatology.d.ts +1 -1
- package/dist/climatology.js +1 -1
- package/dist/contract.d.ts +7 -7
- package/dist/derive.js +5 -4
- package/dist/elements/elements/TrendChartElement.js +12 -31
- package/dist/elements/elements/WindHistoryChartElement.js +12 -31
- package/dist/elements/elements/atoms.d.ts +1 -1
- package/dist/elements/lib/pinned-cursor.js +48 -0
- package/dist/fixtures.d.ts +6 -2
- package/dist/fixtures.js +30 -2
- package/dist/format.js +7 -3
- package/dist/geometry.d.ts +1 -1
- package/dist/geometry.js +21 -9
- package/dist/react/components/Dial.d.ts +1 -2
- package/dist/react/components/TrendChart.js +8 -26
- package/dist/react/components/WindHistoryChart.js +10 -29
- package/dist/react/components/WindSampleStrip.js +9 -27
- package/dist/react/hooks/useStation.js +28 -50
- package/dist/react/hooks/useStationFeed.d.ts +0 -1
- package/dist/react/index.js +2 -2
- package/dist/react/lib/use-pinned-cursor.js +32 -0
- package/dist/samples.js +7 -43
- package/dist/scene/recent-summaries.js +1 -4
- package/dist/server/adapters/windnerd.d.ts +2 -3
- package/dist/server/adapters/windnerd.js +2 -12
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -2
- package/dist/windnerd.d.ts +3 -1
- package/dist/windnerd.js +11 -1
- package/package.json +3 -3
- package/schema/README.md +2 -2
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ that render it natively, in your design system, with no vendor iframe.
|
|
|
14
14
|
| `@azohra/meteo.station/client` | The framework-free client data layer: `createJsonPoller` and the station stores (`createStationFeedStore`, `createStationCurrentStore`, `createStationStore`) every binding subscribes to. Client-only at runtime, import-safe anywhere. |
|
|
15
15
|
| `@azohra/meteo.station/server` | Vendor adapters plus the custom-adapter interface and `defineStationAdapter`, data-level `loadStationFeed()` / `loadStationCurrent()`, the Hologram connectivity loader (`loadHologramConnectivity`), and the mountable feed handler. Server-only, so it can never leak into a client bundle. |
|
|
16
16
|
| `@azohra/meteo.station/react` | `StationFeedProvider`, polling hooks (`useStation`, `useStationFeed`, `useStationCurrent`), the component set (`StationCard`, `CurrentConditions`, `WindHistoryChart`, `WindSampleStrip`, `TrendChart`, `WindRose`, `DailyPattern`, `StationTable`, `StationStrip`, `AirMatrix`, `FreshnessBadge`), and an atoms layer of inline primitives (`Speed`, `Gust`, `Lull`, `Temperature`, `Pressure`, `Direction`, `UpdatedAt`, `BandChip`, `Dial`, `Sparkline`, `Readout`) for composing your own layouts. |
|
|
17
|
-
| `@azohra/meteo.station/elements` | The same surface as light-DOM custom elements (`<meteo-station-feed>`, `<meteo-station-card>`, `<meteo-station-table>`, the charts, the atoms…), a full peer of the
|
|
17
|
+
| `@azohra/meteo.station/elements` | The same surface as light-DOM custom elements (`<meteo-station-feed>`, `<meteo-station-card>`, `<meteo-station-table>`, the charts, the atoms…), a full peer of the React binding, framework-free, held byte-identical by a parity suite. `/register` is the auto-defining one-liner. |
|
|
18
18
|
| `@azohra/meteo.station/styles.css` | The default skin (an intentional side effect), shared by both bindings. |
|
|
19
19
|
|
|
20
20
|
## Taste
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseStationClimatologyJson } from "../contract-climatology.js";
|
|
2
|
+
import { REQUEST_TIMEOUT_MS } from "./poll.js";
|
|
2
3
|
//#region src/client/climatology.ts
|
|
3
|
-
const REQUEST_TIMEOUT_MS = 15e3;
|
|
4
4
|
/**
|
|
5
5
|
* Fetch-once store for the climatology document: near-immutable history
|
|
6
6
|
* needs no poller. Every filter interaction re-aggregates the held cube
|
package/dist/client/history.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { parseStationHistoryJson } from "../contract.js";
|
|
2
2
|
import { historyEndpoint } from "../endpoints.js";
|
|
3
|
+
import { WINDNERD_RECORD_PERIODS_MINUTES } from "../windnerd.js";
|
|
4
|
+
import { REQUEST_TIMEOUT_MS } from "./poll.js";
|
|
3
5
|
//#region src/client/history.ts
|
|
4
|
-
const REQUEST_TIMEOUT_MS = 15e3;
|
|
5
6
|
const HISTORY_STORE_DEFAULT_MAX_WINDOWS = 32;
|
|
6
7
|
/** The default fetcher, against the mounted handler's /history route. */
|
|
7
8
|
function stationHistoryFetcher(base, stationId, fetchInit) {
|
|
@@ -52,16 +53,7 @@ function createStationHistoryStore(fetcher, options = {}) {
|
|
|
52
53
|
size: () => held.size
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
|
-
const ARCHIVE_DEFAULT_PERIODS_MINUTES =
|
|
56
|
-
1,
|
|
57
|
-
5,
|
|
58
|
-
10,
|
|
59
|
-
15,
|
|
60
|
-
30,
|
|
61
|
-
60,
|
|
62
|
-
180,
|
|
63
|
-
360
|
|
64
|
-
];
|
|
56
|
+
const ARCHIVE_DEFAULT_PERIODS_MINUTES = WINDNERD_RECORD_PERIODS_MINUTES;
|
|
65
57
|
const ARCHIVE_TARGET_POINTS = 500;
|
|
66
58
|
const DAY_MS = 864e5;
|
|
67
59
|
/** The finest ladder period that keeps the span at or under the point
|
package/dist/client/live.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ type StationLiveSnapshot = {
|
|
|
9
9
|
status: LiveStatus;
|
|
10
10
|
station: Station | null;
|
|
11
11
|
samples: LiveSample[];
|
|
12
|
+
sampleIntervalSeconds: number | null;
|
|
12
13
|
servedAt: string | null;
|
|
13
14
|
receivedAtMs: number | null;
|
|
14
15
|
error: PollError | null;
|
|
@@ -32,6 +33,6 @@ declare function createStationLiveStore(base: string, stationId: string, options
|
|
|
32
33
|
fetchInit?: FetchInitOption;
|
|
33
34
|
windowSeconds?: number;
|
|
34
35
|
}): StationLiveStore;
|
|
35
|
-
declare function liveSnapshotToCurrent(live: Pick<StationLiveSnapshot, "station" | "servedAt" | "samples">): StationCurrent | null;
|
|
36
|
+
declare function liveSnapshotToCurrent(live: Pick<StationLiveSnapshot, "station" | "servedAt" | "samples" | "sampleIntervalSeconds">): StationCurrent | null;
|
|
36
37
|
//#endregion
|
|
37
38
|
export { LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, LiveStatus, StationLiveSnapshot, StationLiveStore, createStationLiveStore, liveSnapshotToCurrent };
|
package/dist/client/live.js
CHANGED
|
@@ -21,6 +21,7 @@ function createStationLiveStore(base, stationId, options = {}) {
|
|
|
21
21
|
status: "stopped",
|
|
22
22
|
station: null,
|
|
23
23
|
samples: [],
|
|
24
|
+
sampleIntervalSeconds: null,
|
|
24
25
|
servedAt: null,
|
|
25
26
|
receivedAtMs: null,
|
|
26
27
|
error: null
|
|
@@ -36,11 +37,12 @@ function createStationLiveStore(base, stationId, options = {}) {
|
|
|
36
37
|
switch (frame.type) {
|
|
37
38
|
case "init": {
|
|
38
39
|
current.attempt = 0;
|
|
39
|
-
const
|
|
40
|
+
const ring = frame.station.status === "ok" ? frame.station.samples ?? null : null;
|
|
40
41
|
setSnapshot({
|
|
41
42
|
status: "open",
|
|
42
43
|
station: frame.station,
|
|
43
|
-
samples: mergeSamples(snapshot.samples, points, windowSeconds),
|
|
44
|
+
samples: mergeSamples(snapshot.samples, ring?.points ?? [], windowSeconds),
|
|
45
|
+
sampleIntervalSeconds: ring?.intervalSeconds ?? snapshot.sampleIntervalSeconds,
|
|
44
46
|
servedAt: frame.servedAt,
|
|
45
47
|
receivedAtMs: Date.now(),
|
|
46
48
|
error: null
|
|
@@ -52,6 +54,7 @@ function createStationLiveStore(base, stationId, options = {}) {
|
|
|
52
54
|
...snapshot,
|
|
53
55
|
status: "open",
|
|
54
56
|
samples: mergeSamples(snapshot.samples, frame.samples.points, windowSeconds),
|
|
57
|
+
sampleIntervalSeconds: frame.samples.intervalSeconds,
|
|
55
58
|
receivedAtMs: Date.now(),
|
|
56
59
|
error: null
|
|
57
60
|
});
|
|
@@ -225,10 +228,10 @@ function createStationLiveStore(base, stationId, options = {}) {
|
|
|
225
228
|
}
|
|
226
229
|
function liveSnapshotToCurrent(live) {
|
|
227
230
|
if (live.station == null || live.servedAt == null) return null;
|
|
228
|
-
const station = live.station.status === "ok" && live.samples.length > 0 ? {
|
|
231
|
+
const station = live.station.status === "ok" && live.samples.length > 0 && live.sampleIntervalSeconds != null ? {
|
|
229
232
|
...live.station,
|
|
230
233
|
samples: {
|
|
231
|
-
intervalSeconds: live.
|
|
234
|
+
intervalSeconds: live.sampleIntervalSeconds,
|
|
232
235
|
points: live.samples
|
|
233
236
|
}
|
|
234
237
|
} : live.station;
|
package/dist/client/stores.js
CHANGED
|
@@ -80,6 +80,7 @@ function liveCurrentLeg(base, stationId, fetchInit) {
|
|
|
80
80
|
error: null,
|
|
81
81
|
receivedAtMs: null
|
|
82
82
|
};
|
|
83
|
+
let running = false;
|
|
83
84
|
const toCurrent = (live) => {
|
|
84
85
|
const data = liveSnapshotToCurrent(live);
|
|
85
86
|
return {
|
|
@@ -98,9 +99,16 @@ function liveCurrentLeg(base, stationId, fetchInit) {
|
|
|
98
99
|
return mapped;
|
|
99
100
|
},
|
|
100
101
|
subscribe: (listener) => liveStore.subscribe(listener),
|
|
101
|
-
start: () =>
|
|
102
|
-
|
|
102
|
+
start: () => {
|
|
103
|
+
running = true;
|
|
104
|
+
liveStore.start();
|
|
105
|
+
},
|
|
106
|
+
stop: () => {
|
|
107
|
+
running = false;
|
|
108
|
+
liveStore.stop();
|
|
109
|
+
},
|
|
103
110
|
refresh: () => {
|
|
111
|
+
if (!running) return;
|
|
104
112
|
liveStore.stop();
|
|
105
113
|
liveStore.start();
|
|
106
114
|
}
|
package/dist/climatology.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ declare function coveredSlotCountByYear(accumulator: ClimatologyAccumulator): Ma
|
|
|
60
60
|
declare function climatologyCoverage(document: StationClimatology): ClimatologyCoverage;
|
|
61
61
|
/** The share of the filtered non-calm record blowing from inside the
|
|
62
62
|
* consumer's arcs, judged at each sector's centre bearing; null when
|
|
63
|
-
* nothing non-calm was recorded
|
|
63
|
+
* nothing non-calm was recorded. */
|
|
64
64
|
declare function climatologyFavorableShare(document: StationClimatology, arcs: ReadonlyArray<DirectionArc>, filters?: ClimatologyFilters): number | null;
|
|
65
65
|
//#endregion
|
|
66
66
|
export { ClimatologyAccumulator, ClimatologyCoverage, ClimatologyFilters, ClimatologyFoldParams, accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, coveredSlotCountByYear, createClimatologyAccumulator, foldClimatologyPoints };
|
package/dist/climatology.js
CHANGED
|
@@ -214,7 +214,7 @@ function climatologyCoverage(document) {
|
|
|
214
214
|
}
|
|
215
215
|
/** The share of the filtered non-calm record blowing from inside the
|
|
216
216
|
* consumer's arcs, judged at each sector's centre bearing; null when
|
|
217
|
-
* nothing non-calm was recorded
|
|
217
|
+
* nothing non-calm was recorded. */
|
|
218
218
|
function climatologyFavorableShare(document, arcs, filters) {
|
|
219
219
|
if (arcs.length === 0) return null;
|
|
220
220
|
const sectorWidth = 360 / document.sectorCount;
|
package/dist/contract.d.ts
CHANGED
|
@@ -13,10 +13,10 @@ declare const airConditionsSchema: z.ZodObject<{
|
|
|
13
13
|
precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
|
|
14
14
|
precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
|
|
15
15
|
pressureTrend: z.ZodNullable<z.ZodEnum<{
|
|
16
|
+
unknown: "unknown";
|
|
16
17
|
falling: "falling";
|
|
17
18
|
rising: "rising";
|
|
18
19
|
steady: "steady";
|
|
19
|
-
unknown: "unknown";
|
|
20
20
|
}>>;
|
|
21
21
|
relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
|
|
22
22
|
seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
|
|
@@ -45,10 +45,10 @@ declare const readingSchema: z.ZodObject<{
|
|
|
45
45
|
precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
|
|
46
46
|
precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
|
|
47
47
|
pressureTrend: z.ZodNullable<z.ZodEnum<{
|
|
48
|
+
unknown: "unknown";
|
|
48
49
|
falling: "falling";
|
|
49
50
|
rising: "rising";
|
|
50
51
|
steady: "steady";
|
|
51
|
-
unknown: "unknown";
|
|
52
52
|
}>>;
|
|
53
53
|
relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
|
|
54
54
|
seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
|
|
@@ -184,10 +184,10 @@ declare const stationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
184
184
|
precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
|
|
185
185
|
precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
|
|
186
186
|
pressureTrend: z.ZodNullable<z.ZodEnum<{
|
|
187
|
+
unknown: "unknown";
|
|
187
188
|
falling: "falling";
|
|
188
189
|
rising: "rising";
|
|
189
190
|
steady: "steady";
|
|
190
|
-
unknown: "unknown";
|
|
191
191
|
}>>;
|
|
192
192
|
relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
|
|
193
193
|
seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
|
|
@@ -325,10 +325,10 @@ declare const stationFeedSchema: z.ZodObject<{
|
|
|
325
325
|
precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
|
|
326
326
|
precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
|
|
327
327
|
pressureTrend: z.ZodNullable<z.ZodEnum<{
|
|
328
|
+
unknown: "unknown";
|
|
328
329
|
falling: "falling";
|
|
329
330
|
rising: "rising";
|
|
330
331
|
steady: "steady";
|
|
331
|
-
unknown: "unknown";
|
|
332
332
|
}>>;
|
|
333
333
|
relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
|
|
334
334
|
seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
|
|
@@ -466,10 +466,10 @@ declare const stationCurrentSchema: z.ZodObject<{
|
|
|
466
466
|
precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
|
|
467
467
|
precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
|
|
468
468
|
pressureTrend: z.ZodNullable<z.ZodEnum<{
|
|
469
|
+
unknown: "unknown";
|
|
469
470
|
falling: "falling";
|
|
470
471
|
rising: "rising";
|
|
471
472
|
steady: "steady";
|
|
472
|
-
unknown: "unknown";
|
|
473
473
|
}>>;
|
|
474
474
|
relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
|
|
475
475
|
seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
|
|
@@ -633,10 +633,10 @@ declare const stationLiveFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
633
633
|
precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
|
|
634
634
|
precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
|
|
635
635
|
pressureTrend: z.ZodNullable<z.ZodEnum<{
|
|
636
|
+
unknown: "unknown";
|
|
636
637
|
falling: "falling";
|
|
637
638
|
rising: "rising";
|
|
638
639
|
steady: "steady";
|
|
639
|
-
unknown: "unknown";
|
|
640
640
|
}>>;
|
|
641
641
|
relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
|
|
642
642
|
seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
|
|
@@ -782,10 +782,10 @@ declare const stationLiveFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
782
782
|
precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
|
|
783
783
|
precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
|
|
784
784
|
pressureTrend: z.ZodNullable<z.ZodEnum<{
|
|
785
|
+
unknown: "unknown";
|
|
785
786
|
falling: "falling";
|
|
786
787
|
rising: "rising";
|
|
787
788
|
steady: "steady";
|
|
788
|
-
unknown: "unknown";
|
|
789
789
|
}>>;
|
|
790
790
|
relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
|
|
791
791
|
seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
|
package/dist/derive.js
CHANGED
|
@@ -161,13 +161,14 @@ function stationFreshnessThresholds(meta) {
|
|
|
161
161
|
staleAfterMs: clampMs(currentForMs * 6, 10 * 6e4, 45 * 6e4)
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
|
+
function anchoredAgeMs(input) {
|
|
165
|
+
return Math.max(0, Date.parse(input.servedAt) - Date.parse(input.observedAt)) + Math.max(0, input.nowMs - input.receivedAtMs);
|
|
166
|
+
}
|
|
164
167
|
function freshness(input, thresholds = DEFAULT_FRESHNESS_THRESHOLDS) {
|
|
165
|
-
const
|
|
166
|
-
const sinceReceivedMs = Math.max(0, input.nowMs - input.receivedAtMs);
|
|
167
|
-
const ageMs = Math.max(0, ageAtServeMs) + sinceReceivedMs;
|
|
168
|
+
const ageMs = anchoredAgeMs(input);
|
|
168
169
|
if (ageMs <= thresholds.currentForMs) return "live";
|
|
169
170
|
if (ageMs <= thresholds.staleAfterMs) return "aging";
|
|
170
171
|
return "stale";
|
|
171
172
|
}
|
|
172
173
|
//#endregion
|
|
173
|
-
export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, compassDirection, freshness, isCalm, lastNightLowC, normalizeDegrees, periodSummary, pressureDeltaHpa, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
|
|
174
|
+
export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, anchoredAgeMs, compassDirection, freshness, isCalm, lastNightLowC, normalizeDegrees, periodSummary, pressureDeltaHpa, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { requireResolved } from "../../display.js";
|
|
2
2
|
import { measuredChartWidth } from "../../geometry.js";
|
|
3
|
-
import {
|
|
3
|
+
import { readoutAriaLive } from "../../scene/chart.js";
|
|
4
4
|
import { TREND_CLASS, trendGate, trendScene } from "../../scene/trend.js";
|
|
5
5
|
import { ELEMENTS_AMBIENT_HINT } from "../lib/ambient.js";
|
|
6
6
|
import { MeteoStationElement } from "../lib/base.js";
|
|
7
7
|
import { h, hs } from "../lib/h.js";
|
|
8
|
+
import { PinnedCursor } from "../lib/pinned-cursor.js";
|
|
8
9
|
//#region src/elements/elements/TrendChartElement.ts
|
|
9
10
|
var TrendChartElement = class extends MeteoStationElement {
|
|
10
11
|
static observedAttributes = ["series", "station-id"];
|
|
11
12
|
#width = null;
|
|
12
13
|
#observer = null;
|
|
13
|
-
#pinnedAt = null;
|
|
14
|
-
#previewIndex = null;
|
|
15
14
|
#scene = null;
|
|
16
15
|
#readout = null;
|
|
17
16
|
#svg = null;
|
|
18
17
|
#hit = null;
|
|
18
|
+
#cursor = new PinnedCursor({
|
|
19
|
+
scene: () => this.#scene,
|
|
20
|
+
svg: () => this.#svg,
|
|
21
|
+
onChange: () => this.#updateCursor()
|
|
22
|
+
});
|
|
19
23
|
disconnected() {
|
|
20
24
|
this.#observer?.disconnect();
|
|
21
25
|
this.#observer = null;
|
|
@@ -76,12 +80,9 @@ var TrendChartElement = class extends MeteoStationElement {
|
|
|
76
80
|
class: scene.hit.className,
|
|
77
81
|
fill: scene.hit.fill,
|
|
78
82
|
height: scene.hit.height,
|
|
79
|
-
onclick: (event) => this.#handleClick(event),
|
|
80
|
-
onpointerleave: () =>
|
|
81
|
-
|
|
82
|
-
this.#updateCursor();
|
|
83
|
-
},
|
|
84
|
-
onpointermove: (event) => this.#handlePointerMove(event),
|
|
83
|
+
onclick: (event) => this.#cursor.handleClick(event),
|
|
84
|
+
onpointerleave: () => this.#cursor.handlePointerLeave(),
|
|
85
|
+
onpointermove: (event) => this.#cursor.handlePointerMove(event),
|
|
85
86
|
width: scene.hit.width,
|
|
86
87
|
x: scene.hit.x,
|
|
87
88
|
y: scene.hit.y
|
|
@@ -123,34 +124,14 @@ var TrendChartElement = class extends MeteoStationElement {
|
|
|
123
124
|
wrap.replaceChildren(readout, svg);
|
|
124
125
|
this.#updateCursor();
|
|
125
126
|
}
|
|
126
|
-
#indexAtPoint(clientX) {
|
|
127
|
-
const scene = this.#scene;
|
|
128
|
-
const svg = this.#svg;
|
|
129
|
-
if (scene == null || svg == null) return null;
|
|
130
|
-
return chartIndexAtClient(scene.points, scene.frame, scene.scales, clientX, svg.getBoundingClientRect());
|
|
131
|
-
}
|
|
132
|
-
#handlePointerMove(event) {
|
|
133
|
-
if (event.pointerType === "touch") return;
|
|
134
|
-
this.#previewIndex = this.#indexAtPoint(event.clientX);
|
|
135
|
-
this.#updateCursor();
|
|
136
|
-
}
|
|
137
|
-
#handleClick(event) {
|
|
138
|
-
const index = this.#indexAtPoint(event.clientX);
|
|
139
|
-
if (index == null) return;
|
|
140
|
-
const observedAt = this.#scene?.points[index]?.observedAt;
|
|
141
|
-
if (observedAt == null) return;
|
|
142
|
-
this.#pinnedAt = togglePinnedAt(this.#pinnedAt, observedAt);
|
|
143
|
-
this.#previewIndex = null;
|
|
144
|
-
this.#updateCursor();
|
|
145
|
-
}
|
|
146
127
|
#updateCursor() {
|
|
147
128
|
const scene = this.#scene;
|
|
148
129
|
const readout = this.#readout;
|
|
149
130
|
const svg = this.#svg;
|
|
150
131
|
const hit = this.#hit;
|
|
151
132
|
if (scene == null || readout == null || svg == null || hit == null) return;
|
|
152
|
-
const inspection = scene.inspect(
|
|
153
|
-
readout.setAttribute("aria-live", readoutAriaLive(this.#previewIndex));
|
|
133
|
+
const inspection = scene.inspect(this.#cursor.activeIndex());
|
|
134
|
+
readout.setAttribute("aria-live", readoutAriaLive(this.#cursor.previewIndex));
|
|
154
135
|
readout.replaceChildren(h("strong", null, inspection.readout.strong), h("span", null, inspection.readout.span));
|
|
155
136
|
for (const mark of [...svg.querySelectorAll(".meteo-cursor, .meteo-cursor-dot")]) mark.remove();
|
|
156
137
|
const cursor = inspection.cursor;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { measuredChartWidth } from "../../geometry.js";
|
|
2
|
-
import {
|
|
2
|
+
import { readoutAriaLive } from "../../scene/chart.js";
|
|
3
3
|
import { WIND_CHART_CLASS, windChartGate, windChartScene } from "../../scene/wind-history.js";
|
|
4
4
|
import { numberAttribute } from "../lib/attributes.js";
|
|
5
5
|
import { MeteoStationElement } from "../lib/base.js";
|
|
6
6
|
import { h, hs } from "../lib/h.js";
|
|
7
7
|
import { windArrowSvg } from "../lib/fragments.js";
|
|
8
|
+
import { PinnedCursor } from "../lib/pinned-cursor.js";
|
|
8
9
|
//#region src/elements/elements/WindHistoryChartElement.ts
|
|
9
10
|
let hatchCounter = 0;
|
|
10
11
|
function readoutSpan(parts) {
|
|
@@ -23,12 +24,15 @@ var WindHistoryChartElement = class extends MeteoStationElement {
|
|
|
23
24
|
];
|
|
24
25
|
#width = null;
|
|
25
26
|
#observer = null;
|
|
26
|
-
#pinnedAt = null;
|
|
27
|
-
#previewIndex = null;
|
|
28
27
|
#scene = null;
|
|
29
28
|
#readout = null;
|
|
30
29
|
#svg = null;
|
|
31
30
|
#hit = null;
|
|
31
|
+
#cursor = new PinnedCursor({
|
|
32
|
+
scene: () => this.#scene,
|
|
33
|
+
svg: () => this.#svg,
|
|
34
|
+
onChange: () => this.#updateCursor()
|
|
35
|
+
});
|
|
32
36
|
disconnected() {
|
|
33
37
|
this.#observer?.disconnect();
|
|
34
38
|
this.#observer = null;
|
|
@@ -98,12 +102,9 @@ var WindHistoryChartElement = class extends MeteoStationElement {
|
|
|
98
102
|
class: scene.hit.className,
|
|
99
103
|
fill: scene.hit.fill,
|
|
100
104
|
height: scene.hit.height,
|
|
101
|
-
onclick: (event) => this.#handleClick(event),
|
|
102
|
-
onpointerleave: () =>
|
|
103
|
-
|
|
104
|
-
this.#updateCursor();
|
|
105
|
-
},
|
|
106
|
-
onpointermove: (event) => this.#handlePointerMove(event),
|
|
105
|
+
onclick: (event) => this.#cursor.handleClick(event),
|
|
106
|
+
onpointerleave: () => this.#cursor.handlePointerLeave(),
|
|
107
|
+
onpointermove: (event) => this.#cursor.handlePointerMove(event),
|
|
107
108
|
width: scene.hit.width,
|
|
108
109
|
x: scene.hit.x,
|
|
109
110
|
y: scene.hit.y
|
|
@@ -239,34 +240,14 @@ var WindHistoryChartElement = class extends MeteoStationElement {
|
|
|
239
240
|
wrap.replaceChildren(readout, svg);
|
|
240
241
|
this.#updateCursor();
|
|
241
242
|
}
|
|
242
|
-
#indexAtPoint(clientX) {
|
|
243
|
-
const scene = this.#scene;
|
|
244
|
-
const svg = this.#svg;
|
|
245
|
-
if (scene == null || svg == null) return null;
|
|
246
|
-
return chartIndexAtClient(scene.points, scene.frame, scene.scales, clientX, svg.getBoundingClientRect());
|
|
247
|
-
}
|
|
248
|
-
#handlePointerMove(event) {
|
|
249
|
-
if (event.pointerType === "touch") return;
|
|
250
|
-
this.#previewIndex = this.#indexAtPoint(event.clientX);
|
|
251
|
-
this.#updateCursor();
|
|
252
|
-
}
|
|
253
|
-
#handleClick(event) {
|
|
254
|
-
const index = this.#indexAtPoint(event.clientX);
|
|
255
|
-
if (index == null) return;
|
|
256
|
-
const observedAt = this.#scene?.points[index]?.observedAt;
|
|
257
|
-
if (observedAt == null) return;
|
|
258
|
-
this.#pinnedAt = togglePinnedAt(this.#pinnedAt, observedAt);
|
|
259
|
-
this.#previewIndex = null;
|
|
260
|
-
this.#updateCursor();
|
|
261
|
-
}
|
|
262
243
|
#updateCursor() {
|
|
263
244
|
const scene = this.#scene;
|
|
264
245
|
const readout = this.#readout;
|
|
265
246
|
const svg = this.#svg;
|
|
266
247
|
const hit = this.#hit;
|
|
267
248
|
if (scene == null || readout == null || svg == null || hit == null) return;
|
|
268
|
-
const inspection = scene.inspect(
|
|
269
|
-
readout.setAttribute("aria-live", readoutAriaLive(this.#previewIndex));
|
|
249
|
+
const inspection = scene.inspect(this.#cursor.activeIndex());
|
|
250
|
+
readout.setAttribute("aria-live", readoutAriaLive(this.#cursor.previewIndex));
|
|
270
251
|
readout.replaceChildren(h("strong", null, inspection.readout.strong), readoutSpan(inspection.readout.span));
|
|
271
252
|
for (const mark of [...svg.querySelectorAll(".meteo-cursor, .meteo-cursor-dot")]) mark.remove();
|
|
272
253
|
const cursor = inspection.cursor;
|
|
@@ -2,7 +2,7 @@ import { SpeedKind } from "../../format.js";
|
|
|
2
2
|
import { MeteoStationElement } from "../lib/base.js";
|
|
3
3
|
//#region src/elements/elements/atoms.d.ts
|
|
4
4
|
declare abstract class SpeedAtomElement extends MeteoStationElement {
|
|
5
|
-
static readonly observedAttributes: ("
|
|
5
|
+
static readonly observedAttributes: ("unit" | "station-id")[];
|
|
6
6
|
protected abstract readonly kind: SpeedKind;
|
|
7
7
|
protected abstract readonly component: string;
|
|
8
8
|
protected render(): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { activeChartIndex, chartIndexAtClient, togglePinnedAt } from "../../scene/chart.js";
|
|
2
|
+
//#region src/elements/lib/pinned-cursor.ts
|
|
3
|
+
var PinnedCursor = class {
|
|
4
|
+
#pinnedAt = null;
|
|
5
|
+
#previewIndex = null;
|
|
6
|
+
#scene;
|
|
7
|
+
#svg;
|
|
8
|
+
#onChange;
|
|
9
|
+
constructor(host) {
|
|
10
|
+
this.#scene = host.scene;
|
|
11
|
+
this.#svg = host.svg;
|
|
12
|
+
this.#onChange = host.onChange;
|
|
13
|
+
}
|
|
14
|
+
get previewIndex() {
|
|
15
|
+
return this.#previewIndex;
|
|
16
|
+
}
|
|
17
|
+
activeIndex() {
|
|
18
|
+
const scene = this.#scene();
|
|
19
|
+
if (scene == null) return null;
|
|
20
|
+
return activeChartIndex(scene.points, this.#pinnedAt, this.#previewIndex);
|
|
21
|
+
}
|
|
22
|
+
handlePointerMove(event) {
|
|
23
|
+
if (event.pointerType === "touch") return;
|
|
24
|
+
this.#previewIndex = this.#indexAtPoint(event.clientX);
|
|
25
|
+
this.#onChange();
|
|
26
|
+
}
|
|
27
|
+
handlePointerLeave() {
|
|
28
|
+
this.#previewIndex = null;
|
|
29
|
+
this.#onChange();
|
|
30
|
+
}
|
|
31
|
+
handleClick(event) {
|
|
32
|
+
const index = this.#indexAtPoint(event.clientX);
|
|
33
|
+
if (index == null) return;
|
|
34
|
+
const observedAt = this.#scene()?.points[index]?.observedAt;
|
|
35
|
+
if (observedAt == null) return;
|
|
36
|
+
this.#pinnedAt = togglePinnedAt(this.#pinnedAt, observedAt);
|
|
37
|
+
this.#previewIndex = null;
|
|
38
|
+
this.#onChange();
|
|
39
|
+
}
|
|
40
|
+
#indexAtPoint(clientX) {
|
|
41
|
+
const scene = this.#scene();
|
|
42
|
+
const svg = this.#svg();
|
|
43
|
+
if (scene == null || svg == null) return null;
|
|
44
|
+
return chartIndexAtClient(scene.points, scene.frame, scene.scales, clientX, svg.getBoundingClientRect());
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { PinnedCursor };
|
package/dist/fixtures.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { HistoryPoint } from "./contract.js";
|
|
1
|
+
import { HistoryPoint, StationMeta } from "./contract.js";
|
|
2
|
+
import { SpeedThresholds } from "./derive.js";
|
|
2
3
|
//#region src/fixtures.d.ts
|
|
4
|
+
declare const LAUNCH_RIDGE_META: StationMeta;
|
|
5
|
+
/** The wind grading the demo exhibits judge with. */
|
|
6
|
+
declare const EXHIBIT_THRESHOLDS: SpeedThresholds;
|
|
3
7
|
/** Deterministic PRNG (mulberry32). */
|
|
4
8
|
declare function mulberry32(seed: number): () => number;
|
|
5
9
|
/** Smoothstep clamped to [0, 1]. */
|
|
@@ -20,4 +24,4 @@ interface LongHistoryOptions {
|
|
|
20
24
|
/** A long-range deterministic synthetic history: seasonal, diurnal, with occasional dropouts. */
|
|
21
25
|
declare function buildLongHistory({ nowMs, days, periodMinutes, seed, withGaps }: LongHistoryOptions): HistoryPoint[];
|
|
22
26
|
//#endregion
|
|
23
|
-
export { LongHistoryOptions, buildLongHistory, mulberry32, smooth, wobble };
|
|
27
|
+
export { EXHIBIT_THRESHOLDS, LAUNCH_RIDGE_META, LongHistoryOptions, buildLongHistory, mulberry32, smooth, wobble };
|
package/dist/fixtures.js
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
|
+
import { kmhToMps } from "@azohra/meteo.core";
|
|
1
2
|
//#region src/fixtures.ts
|
|
2
3
|
const MINUTE_MS = 6e4;
|
|
3
4
|
const DAY_MS = 1440 * MINUTE_MS;
|
|
5
|
+
const LAUNCH_RIDGE_META = {
|
|
6
|
+
id: "launch-ridge",
|
|
7
|
+
name: "Launch Ridge",
|
|
8
|
+
sourceLabel: "WindNerd",
|
|
9
|
+
pageUrl: null,
|
|
10
|
+
latitude: 49.078,
|
|
11
|
+
longitude: -117.785,
|
|
12
|
+
timeZone: "America/Vancouver",
|
|
13
|
+
elevationM: 1245,
|
|
14
|
+
capabilities: {
|
|
15
|
+
gustLull: true,
|
|
16
|
+
temperature: true,
|
|
17
|
+
conditions: false,
|
|
18
|
+
history: true
|
|
19
|
+
},
|
|
20
|
+
samplingWindowSeconds: 3,
|
|
21
|
+
recommendedPollSeconds: 5
|
|
22
|
+
};
|
|
23
|
+
/** The wind grading the demo exhibits judge with. */
|
|
24
|
+
const EXHIBIT_THRESHOLDS = {
|
|
25
|
+
unit: "kmh",
|
|
26
|
+
values: [
|
|
27
|
+
12,
|
|
28
|
+
20,
|
|
29
|
+
28
|
|
30
|
+
]
|
|
31
|
+
};
|
|
4
32
|
/** Deterministic PRNG (mulberry32). */
|
|
5
33
|
function mulberry32(seed) {
|
|
6
34
|
let a = seed >>> 0;
|
|
@@ -20,7 +48,7 @@ const smooth = (value) => {
|
|
|
20
48
|
const wobble = (seed) => (Math.sin(seed * 12.9898) + Math.sin(seed * 4.1414 + 1.3)) / 2;
|
|
21
49
|
const round1 = (value) => Math.round(value * 10) / 10;
|
|
22
50
|
const round2 = (value) => Math.round(value * 100) / 100;
|
|
23
|
-
const mps = (kmh) => round2(kmh
|
|
51
|
+
const mps = (kmh) => round2(kmhToMps(kmh));
|
|
24
52
|
const normalizeDeg = (deg) => (deg % 360 + 360) % 360;
|
|
25
53
|
function seasonPhase(dateUtc) {
|
|
26
54
|
const solsticeMs = Date.UTC(dateUtc.getUTCFullYear(), 11, 21);
|
|
@@ -64,4 +92,4 @@ function buildLongHistory({ nowMs, days = 420, periodMinutes = 15, seed = 995373
|
|
|
64
92
|
return points;
|
|
65
93
|
}
|
|
66
94
|
//#endregion
|
|
67
|
-
export { buildLongHistory, mulberry32, smooth, wobble };
|
|
95
|
+
export { EXHIBIT_THRESHOLDS, LAUNCH_RIDGE_META, buildLongHistory, mulberry32, smooth, wobble };
|
package/dist/format.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compassDirection, isCalm, periodSummary, speedFromMps } from "./derive.js";
|
|
1
|
+
import { anchoredAgeMs, compassDirection, isCalm, periodSummary, speedFromMps } from "./derive.js";
|
|
2
2
|
//#region src/format.ts
|
|
3
3
|
function roundSpeed(mps, unit) {
|
|
4
4
|
return Math.round(speedFromMps(mps, unit));
|
|
@@ -40,8 +40,12 @@ function relativeWords(ageMs, words) {
|
|
|
40
40
|
return words.updated.hoursAgo(Math.floor(ageMs / HOUR_MS));
|
|
41
41
|
}
|
|
42
42
|
function readingAgeMs(args) {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
return args.servedAt != null && args.receivedAtMs != null ? anchoredAgeMs({
|
|
44
|
+
observedAt: args.observedAt,
|
|
45
|
+
servedAt: args.servedAt,
|
|
46
|
+
receivedAtMs: args.receivedAtMs,
|
|
47
|
+
nowMs: args.nowMs
|
|
48
|
+
}) : Math.max(0, args.nowMs - Date.parse(args.observedAt));
|
|
45
49
|
}
|
|
46
50
|
function updatedAtText(ageMs, observedAt, words, formatTime) {
|
|
47
51
|
return ageMs >= 216e5 ? formatTime(new Date(Date.parse(observedAt))) : relativeWords(ageMs, words);
|
package/dist/geometry.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ declare const METEOROLOGICAL_SEASON_MONTHS: Record<"fall" | "spring" | "summer"
|
|
|
90
90
|
declare function filterByMonth(points: ReadonlyArray<HistoryPoint>, months: ReadonlyArray<number>, utcOffsetMinutes?: number): HistoryPoint[];
|
|
91
91
|
declare function filterByTimeOfDay(points: ReadonlyArray<HistoryPoint>, fromMinute: number, toMinute: number, utcOffsetMinutes?: number): HistoryPoint[];
|
|
92
92
|
/** The share of non-calm history blowing from inside the consumer's arcs;
|
|
93
|
-
* null when nothing non-calm was measured
|
|
93
|
+
* null when nothing non-calm was measured. */
|
|
94
94
|
declare function favorableShare(points: ReadonlyArray<HistoryPoint>, arcs: ReadonlyArray<DirectionArc>): number | null;
|
|
95
95
|
type HistoryCoverage = {
|
|
96
96
|
actualCount: number;
|