@sjvair/monitor-map 4.1.0 → 4.3.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 +68 -16
- package/dist/lib/LazyMapLayout.svelte +53 -0
- package/dist/lib/LazyMapLayout.svelte.d.ts +7 -0
- package/dist/lib/LazyMonitorDetailPanel.svelte +33 -0
- package/dist/lib/LazyMonitorDetailPanel.svelte.d.ts +4 -0
- package/dist/lib/LoadError.svelte +19 -0
- package/dist/lib/LoadError.svelte.d.ts +7 -0
- package/dist/lib/LoadScreen.svelte +10 -1
- package/dist/lib/LoadScreen.svelte.d.ts +6 -16
- package/dist/lib/MonitorDetailPanel.svelte +108 -28
- package/dist/lib/MonitorMapLayout.svelte +19 -1
- package/dist/lib/abort.d.ts +16 -0
- package/dist/lib/abort.js +51 -0
- package/dist/lib/collocation-sites/collocations.svelte.d.ts +3 -2
- package/dist/lib/collocation-sites/collocations.svelte.js +8 -4
- package/dist/lib/core.d.ts +1 -1
- package/dist/lib/data-chart/DataChart.svelte +78 -13
- package/dist/lib/data-chart/DataChart.svelte.d.ts +10 -5
- package/dist/lib/data-chart/DateRange.d.ts +4 -0
- package/dist/lib/data-chart/DateRange.js +9 -1
- package/dist/lib/data-chart/chart-utils.d.ts +2 -1
- package/dist/lib/data-chart/chart-utils.js +19 -23
- package/dist/lib/data-chart/level-colors.d.ts +6 -0
- package/dist/lib/data-chart/level-colors.js +5 -0
- package/dist/lib/data-chart/requests.d.ts +6 -2
- package/dist/lib/data-chart/requests.js +6 -4
- package/dist/lib/data-chart/tooltip.d.ts +2 -1
- package/dist/lib/data-chart/tooltip.js +1 -9
- package/dist/lib/ev-stations/ev-stations-map-integration.svelte.js +4 -6
- package/dist/lib/ev-stations/ev-stations.svelte.d.ts +3 -2
- package/dist/lib/ev-stations/ev-stations.svelte.js +8 -6
- package/dist/lib/hms/hms.svelte.d.ts +4 -3
- package/dist/lib/hms/hms.svelte.js +16 -6
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/lazy-chunks.d.ts +2 -0
- package/dist/lib/lazy-chunks.js +6 -0
- package/dist/lib/lazy-routes.d.ts +6 -4
- package/dist/lib/lazy-routes.js +12 -7
- package/dist/lib/map/MapShell.svelte +7 -1
- package/dist/lib/map/MapShell.svelte.d.ts +5 -0
- package/dist/lib/map/integrations/map-geojson-integration.svelte.d.ts +13 -0
- package/dist/lib/map/integrations/map-geojson-integration.svelte.js +30 -4
- package/dist/lib/map/map-style-state.svelte.d.ts +10 -0
- package/dist/lib/map/map-style-state.svelte.js +56 -5
- package/dist/lib/monitors/components/MonitorSubscriptionManager.svelte +17 -22
- package/dist/lib/monitors/monitor-details.svelte.d.ts +15 -0
- package/dist/lib/monitors/monitor-details.svelte.js +71 -0
- package/dist/lib/monitors/monitors-map-integration.svelte.js +4 -6
- package/dist/lib/monitors/monitors.svelte.d.ts +28 -5
- package/dist/lib/monitors/monitors.svelte.js +131 -31
- package/dist/lib/monitors/panel-pollutant.d.ts +37 -0
- package/dist/lib/monitors/panel-pollutant.js +43 -0
- package/dist/lib/monitors/subscriptions.d.ts +3 -0
- package/dist/lib/monitors/subscriptions.js +9 -0
- package/dist/lib/options/OptionsBar.svelte +8 -1
- package/dist/lib/options/OptionsMenu.svelte +10 -1
- package/dist/lib/shared-load.d.ts +5 -0
- package/dist/lib/shared-load.js +14 -0
- package/package.json +2 -2
- package/src/lib/LazyMapLayout.svelte +53 -0
- package/src/lib/LazyMonitorDetailPanel.svelte +33 -0
- package/src/lib/LoadError.svelte +19 -0
- package/src/lib/LoadScreen.svelte +10 -1
- package/src/lib/MonitorDetailPanel.svelte +108 -28
- package/src/lib/MonitorMapLayout.svelte +19 -1
- package/src/lib/abort.ts +59 -0
- package/src/lib/collocation-sites/collocations.svelte.ts +7 -4
- package/src/lib/core.ts +1 -1
- package/src/lib/data-chart/DataChart.svelte +78 -13
- package/src/lib/data-chart/DateRange.ts +11 -1
- package/src/lib/data-chart/chart-utils.ts +23 -26
- package/src/lib/data-chart/level-colors.ts +13 -0
- package/src/lib/data-chart/requests.ts +21 -10
- package/src/lib/data-chart/tooltip.ts +2 -10
- package/src/lib/ev-stations/ev-stations-map-integration.svelte.ts +4 -4
- package/src/lib/ev-stations/ev-stations.svelte.ts +11 -6
- package/src/lib/hms/hms.svelte.ts +12 -6
- package/src/lib/index.ts +1 -1
- package/src/lib/lazy-chunks.ts +7 -0
- package/src/lib/lazy-routes.ts +12 -7
- package/src/lib/map/MapShell.svelte +7 -1
- package/src/lib/map/integrations/map-geojson-integration.svelte.ts +32 -3
- package/src/lib/map/map-style-state.svelte.ts +58 -6
- package/src/lib/monitors/components/MonitorSubscriptionManager.svelte +17 -22
- package/src/lib/monitors/monitor-details.svelte.ts +75 -0
- package/src/lib/monitors/monitors-map-integration.svelte.ts +4 -4
- package/src/lib/monitors/monitors.svelte.ts +161 -34
- package/src/lib/monitors/panel-pollutant.ts +76 -0
- package/src/lib/monitors/subscriptions.ts +17 -0
- package/src/lib/options/OptionsBar.svelte +8 -1
- package/src/lib/options/OptionsMenu.svelte +10 -1
- package/src/lib/shared-load.ts +15 -0
package/dist/lib/core.d.ts
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export { ROUTER_KEY, provideMonitorMapRouter, useMonitorMapRouter, type MonitorMapRouterApi } from "./router-context";
|
|
10
10
|
export { monitorsManager } from "./monitors/monitors.svelte.js";
|
|
11
|
-
export type { MonitorsManager } from "./monitors/monitors.svelte.js";
|
|
11
|
+
export type { MonitorsManager, MonitorsInitOptions } from "./monitors/monitors.svelte.js";
|
|
12
12
|
export type { MonitorsDataSource, MonitorsPollutant } from "./monitors/types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { untrack } from "svelte";
|
|
2
3
|
import type { Attachment } from "svelte/attachments";
|
|
3
|
-
import type { MonitorLatestType } from "@sjvair/sdk";
|
|
4
4
|
import type { DateRange as CalendarRange } from "bits-ui";
|
|
5
5
|
import { parseAbsolute } from "@internationalized/date";
|
|
6
6
|
import { Maximize, SquareX } from "@lucide/svelte";
|
|
@@ -9,13 +9,23 @@
|
|
|
9
9
|
import { getMonitorEntriesCSVUrl } from "@sjvair/sdk/monitors";
|
|
10
10
|
import { format, parseISO } from "date-fns";
|
|
11
11
|
import { RangeCalendar } from "../components/ui/range-calendar";
|
|
12
|
+
import type { PanelPollutant } from "../monitors/panel-pollutant";
|
|
13
|
+
import { monitorsManager } from "../monitors/monitors.svelte";
|
|
12
14
|
import { DataChartManager } from "./data-chart.svelte";
|
|
13
|
-
import { createDateRange } from "./DateRange";
|
|
14
|
-
import { fetchChartData } from "./requests";
|
|
15
|
+
import { createDateRange, extendToNow, includesToday } from "./DateRange";
|
|
16
|
+
import { fetchChartData, type ChartMonitor } from "./requests";
|
|
15
17
|
import { getChartConfig } from "./chart-utils";
|
|
16
|
-
import {
|
|
18
|
+
import { levelColors } from "./level-colors";
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
monitor: ChartMonitor;
|
|
22
|
+
/** The pollutant to chart. Independent of the pollutant the map is coloring by. */
|
|
23
|
+
pollutant: PanelPollutant;
|
|
24
|
+
/** Bumped by the owner whenever fresh data may exist; see the effect below. */
|
|
25
|
+
refreshTick?: number;
|
|
26
|
+
}
|
|
17
27
|
|
|
18
|
-
let { monitor
|
|
28
|
+
let { monitor, pollutant, refreshTick = 0 }: Props = $props();
|
|
19
29
|
|
|
20
30
|
const chartManager = new DataChartManager();
|
|
21
31
|
let expanded = $state(false);
|
|
@@ -34,7 +44,8 @@
|
|
|
34
44
|
format(parseISO(chartManager.dateRange.end), "MMM d, yyyy")
|
|
35
45
|
);
|
|
36
46
|
|
|
37
|
-
|
|
47
|
+
// A request with no entries still resolves to [[], []], so test the x axis, not the tuple.
|
|
48
|
+
const noChartData = $derived(!chartManager.chartData[0]?.length);
|
|
38
49
|
const message = $derived(
|
|
39
50
|
chartManager.loading
|
|
40
51
|
? "Loading Data"
|
|
@@ -42,10 +53,38 @@
|
|
|
42
53
|
? "No Data Available For Selected Date Range"
|
|
43
54
|
: ""
|
|
44
55
|
);
|
|
45
|
-
const pollutantLabel = $derived(
|
|
56
|
+
const pollutantLabel = $derived(pollutant === "pm25" ? "PM 2.5" : "Ozone");
|
|
57
|
+
// Level definitions are shared metadata, not the map's current selection.
|
|
58
|
+
const colors = $derived(
|
|
59
|
+
levelColors(monitorsManager.meta?.entryType(pollutant).asIter.levels ?? [])
|
|
60
|
+
);
|
|
46
61
|
|
|
62
|
+
// Reload for another monitor or pollutant, not for a new object describing the same one.
|
|
63
|
+
// Both go through a $derived: the owner recomputes what it passes on every refresh, and a
|
|
64
|
+
// prop read directly would re-run this effect even when the value is unchanged.
|
|
65
|
+
const monitorId = $derived(monitor.id);
|
|
66
|
+
const chartPollutant = $derived(pollutant);
|
|
47
67
|
$effect(() => {
|
|
48
|
-
|
|
68
|
+
void monitorId;
|
|
69
|
+
void chartPollutant;
|
|
70
|
+
untrack(() => loadChartData());
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Whether the chosen range ended on the day it was chosen, so it should follow the present.
|
|
74
|
+
// Remembered, not re-tested per tick: a panel left open past midnight keeps following.
|
|
75
|
+
let live = includesToday(chartManager.dateRange);
|
|
76
|
+
let seenTick = untrack(() => refreshTick);
|
|
77
|
+
|
|
78
|
+
// A range that ended in the past cannot gain entries, so only a live one reloads.
|
|
79
|
+
$effect(() => {
|
|
80
|
+
const tick = refreshTick;
|
|
81
|
+
if (tick === seenTick) return;
|
|
82
|
+
seenTick = tick;
|
|
83
|
+
if (!live) return;
|
|
84
|
+
untrack(() => {
|
|
85
|
+
chartManager.dateRange = extendToNow(chartManager.dateRange);
|
|
86
|
+
loadChartData({ silent: true });
|
|
87
|
+
});
|
|
49
88
|
});
|
|
50
89
|
|
|
51
90
|
$effect(() => {
|
|
@@ -82,7 +121,7 @@
|
|
|
82
121
|
instance?.destroy?.();
|
|
83
122
|
el.innerHTML = "";
|
|
84
123
|
const maxDiff = Math.max(...flatData) - Math.min(...flatData);
|
|
85
|
-
const opts = getChartConfig(monitor.type, maxDiff, width, height);
|
|
124
|
+
const opts = getChartConfig(monitor.type, maxDiff, width, height, colors, pollutantLabel);
|
|
86
125
|
instance = new uPlot(opts, chartManager.chartData, el);
|
|
87
126
|
};
|
|
88
127
|
|
|
@@ -103,9 +142,34 @@
|
|
|
103
142
|
};
|
|
104
143
|
};
|
|
105
144
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
145
|
+
let chartRequest = 0;
|
|
146
|
+
let chartController: AbortController | undefined;
|
|
147
|
+
|
|
148
|
+
// A closed panel cancels its in-flight fetch.
|
|
149
|
+
$effect(() => () => chartController?.abort());
|
|
150
|
+
|
|
151
|
+
// `silent` keeps the current chart on screen while a timed refresh loads.
|
|
152
|
+
async function loadChartData({ silent = false } = {}) {
|
|
153
|
+
const request = ++chartRequest;
|
|
154
|
+
chartController?.abort();
|
|
155
|
+
const controller = (chartController = new AbortController());
|
|
156
|
+
if (!silent) chartManager.loading = true;
|
|
157
|
+
let data: Awaited<ReturnType<typeof fetchChartData>>;
|
|
158
|
+
try {
|
|
159
|
+
data = await fetchChartData(monitor, chartManager.dateRange, pollutant, {
|
|
160
|
+
signal: controller.signal
|
|
161
|
+
});
|
|
162
|
+
} catch (err) {
|
|
163
|
+
// Superseded or closed: the newer call owns `loading` and the chart, so leave both.
|
|
164
|
+
if (controller.signal.aborted) return;
|
|
165
|
+
throw err;
|
|
166
|
+
}
|
|
167
|
+
// A newer request (another range, monitor, pollutant or refresh) owns the chart now.
|
|
168
|
+
if (request !== chartRequest) return;
|
|
169
|
+
// A failed request resolves to [] (an empty range is [[], []]); a background refresh
|
|
170
|
+
// that failed keeps the chart already on screen.
|
|
171
|
+
if (silent && data.length === 0) return;
|
|
172
|
+
chartManager.chartData = data;
|
|
109
173
|
chartManager.loading = false;
|
|
110
174
|
}
|
|
111
175
|
|
|
@@ -113,6 +177,7 @@
|
|
|
113
177
|
if (calendarValue?.start && calendarValue?.end) {
|
|
114
178
|
dataRange = calendarValue;
|
|
115
179
|
chartManager.dateRange = createDateRange(dataRange.start, dataRange.end);
|
|
180
|
+
live = includesToday(chartManager.dateRange);
|
|
116
181
|
calendarOpen = false;
|
|
117
182
|
loadChartData();
|
|
118
183
|
}
|
|
@@ -121,7 +186,7 @@
|
|
|
121
186
|
function downloadCSV() {
|
|
122
187
|
const url = getMonitorEntriesCSVUrl({
|
|
123
188
|
monitorId: monitor.id,
|
|
124
|
-
entryType:
|
|
189
|
+
entryType: pollutant,
|
|
125
190
|
timestampGte: chartManager.dateRange.start,
|
|
126
191
|
timestampLte: chartManager.dateRange.end
|
|
127
192
|
});
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { MonitorLatestType } from "@sjvair/sdk";
|
|
2
1
|
import "uplot/dist/uPlot.min.css";
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import type { PanelPollutant } from "../monitors/panel-pollutant";
|
|
3
|
+
import { type ChartMonitor } from "./requests";
|
|
4
|
+
interface Props {
|
|
5
|
+
monitor: ChartMonitor;
|
|
6
|
+
/** The pollutant to chart. Independent of the pollutant the map is coloring by. */
|
|
7
|
+
pollutant: PanelPollutant;
|
|
8
|
+
/** Bumped by the owner whenever fresh data may exist; see the effect below. */
|
|
9
|
+
refreshTick?: number;
|
|
10
|
+
}
|
|
11
|
+
declare const DataChart: import("svelte").Component<Props, {}, "">;
|
|
7
12
|
type DataChart = ReturnType<typeof DataChart>;
|
|
8
13
|
export default DataChart;
|
|
@@ -4,3 +4,7 @@ export type DateRange = {
|
|
|
4
4
|
end: string;
|
|
5
5
|
};
|
|
6
6
|
export declare function createDateRange(start?: DateValue, end?: DateValue): DateRange;
|
|
7
|
+
/** Whether the range ends on the current calendar day, i.e. it can still gain entries. */
|
|
8
|
+
export declare function includesToday(range: DateRange): boolean;
|
|
9
|
+
/** The same range with its end moved to the present. */
|
|
10
|
+
export declare function extendToNow(range: DateRange): DateRange;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { subDays, startOfDay, endOfDay, isToday } from "date-fns";
|
|
1
|
+
import { subDays, startOfDay, endOfDay, isToday, parseISO } from "date-fns";
|
|
2
2
|
export function createDateRange(start, end) {
|
|
3
3
|
if (!start || !end) {
|
|
4
4
|
return {
|
|
@@ -14,3 +14,11 @@ export function createDateRange(start, end) {
|
|
|
14
14
|
end: endDate.toISOString()
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
/** Whether the range ends on the current calendar day, i.e. it can still gain entries. */
|
|
18
|
+
export function includesToday(range) {
|
|
19
|
+
return isToday(parseISO(range.end));
|
|
20
|
+
}
|
|
21
|
+
/** The same range with its end moved to the present. */
|
|
22
|
+
export function extendToNow(range) {
|
|
23
|
+
return { start: range.start, end: new Date().toISOString() };
|
|
24
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LevelColors } from "./level-colors";
|
|
1
2
|
import type uPlot from "uplot";
|
|
2
3
|
import type { MonitorType } from "@sjvair/sdk";
|
|
3
|
-
export declare function getChartConfig(sourceName: MonitorType, maxDiff: number, width: number, height: number): uPlot.Options;
|
|
4
|
+
export declare function getChartConfig(sourceName: MonitorType, maxDiff: number, width: number, height: number, colors: LevelColors, label: string): uPlot.Options;
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import { monitorsManager } from "../monitors/monitors.svelte";
|
|
2
1
|
import { tooltipsPlugin, uPlotCursorConfig } from "./tooltip";
|
|
3
2
|
import { fromUnixTime, getUnixTime, isToday, isAfter } from "date-fns";
|
|
4
3
|
const PM25_AVG_60_STROKE = "3572b0";
|
|
5
|
-
function getColors() {
|
|
6
|
-
const levels = monitorsManager.levels ?? [];
|
|
7
|
-
const colors = levels.map((level) => [level.range[0], level.color.replace(/^#/, "")]);
|
|
8
|
-
colors.push([Infinity, "000000"]);
|
|
9
|
-
return colors;
|
|
10
|
-
}
|
|
11
4
|
const baseXSeriesConfig = {};
|
|
12
5
|
const baseYSeriesConfig = {
|
|
13
6
|
show: true,
|
|
14
7
|
spanGaps: false,
|
|
15
8
|
width: 1
|
|
16
9
|
};
|
|
17
|
-
|
|
10
|
+
/** The level stops plus a final black stop, so values above the top level still get a color. */
|
|
11
|
+
function gradientStops(colors) {
|
|
12
|
+
return [...colors, [Infinity, "000000"]];
|
|
13
|
+
}
|
|
14
|
+
const pm25SeriesConfig = (stops) => ({
|
|
18
15
|
...baseYSeriesConfig,
|
|
19
16
|
label: "Real Time",
|
|
20
17
|
width: 2,
|
|
21
|
-
stroke: (u) => scaleGradient(u, "y", 1,
|
|
22
|
-
};
|
|
23
|
-
const pm25Avg60SeriesConfig = {
|
|
18
|
+
stroke: (u) => scaleGradient(u, "y", 1, stops, true)
|
|
19
|
+
});
|
|
20
|
+
const pm25Avg60SeriesConfig = (stops) => ({
|
|
24
21
|
...baseYSeriesConfig,
|
|
25
22
|
label: "60 Minute Average",
|
|
26
|
-
stroke: (u) => autograd(u, PM25_AVG_60_STROKE)
|
|
27
|
-
};
|
|
28
|
-
export function getChartConfig(sourceName, maxDiff, width, height) {
|
|
29
|
-
const series = getSeriesConfigs(sourceName);
|
|
23
|
+
stroke: (u) => autograd(u, PM25_AVG_60_STROKE, stops)
|
|
24
|
+
});
|
|
25
|
+
export function getChartConfig(sourceName, maxDiff, width, height, colors, label) {
|
|
26
|
+
const series = getSeriesConfigs(sourceName, gradientStops(colors));
|
|
30
27
|
const getStroke = (u, sIdx) => {
|
|
31
28
|
const stroke = series[sIdx].stroke;
|
|
32
29
|
return stroke(u, sIdx);
|
|
@@ -34,7 +31,7 @@ export function getChartConfig(sourceName, maxDiff, width, height) {
|
|
|
34
31
|
return {
|
|
35
32
|
width,
|
|
36
33
|
height,
|
|
37
|
-
cursor: uPlotCursorConfig.get(),
|
|
34
|
+
cursor: uPlotCursorConfig.get(colors),
|
|
38
35
|
// @ts-expect-error: select missing pseudo "required" options
|
|
39
36
|
select: {
|
|
40
37
|
show: false
|
|
@@ -77,7 +74,7 @@ export function getChartConfig(sourceName, maxDiff, width, height) {
|
|
|
77
74
|
}
|
|
78
75
|
},
|
|
79
76
|
{
|
|
80
|
-
label
|
|
77
|
+
label,
|
|
81
78
|
side: 3,
|
|
82
79
|
values: (_, ticks) => ticks.map((v) => v.toFixed(maxDiff < 5 ? 1 : 0))
|
|
83
80
|
}
|
|
@@ -87,9 +84,8 @@ export function getChartConfig(sourceName, maxDiff, width, height) {
|
|
|
87
84
|
}
|
|
88
85
|
};
|
|
89
86
|
}
|
|
90
|
-
function getSeriesConfigs(monitorType) {
|
|
91
|
-
const singleSeriesConfig =
|
|
92
|
-
singleSeriesConfig.width = 2;
|
|
87
|
+
function getSeriesConfigs(monitorType, stops) {
|
|
88
|
+
const singleSeriesConfig = { ...pm25Avg60SeriesConfig(stops), width: 2 };
|
|
93
89
|
switch (monitorType) {
|
|
94
90
|
case "airnow":
|
|
95
91
|
case "aqview":
|
|
@@ -99,14 +95,14 @@ function getSeriesConfigs(monitorType) {
|
|
|
99
95
|
return [baseXSeriesConfig, singleSeriesConfig];
|
|
100
96
|
case "airgradient":
|
|
101
97
|
case "purpleair":
|
|
102
|
-
return [baseXSeriesConfig, pm25SeriesConfig];
|
|
98
|
+
return [baseXSeriesConfig, pm25SeriesConfig(stops)];
|
|
103
99
|
}
|
|
104
100
|
}
|
|
105
|
-
function autograd(u, fallback) {
|
|
101
|
+
function autograd(u, fallback, stops) {
|
|
106
102
|
if (u.series.length > 2) {
|
|
107
103
|
return fallback;
|
|
108
104
|
}
|
|
109
|
-
return scaleGradient(u, "y", 1,
|
|
105
|
+
return scaleGradient(u, "y", 1, stops, true);
|
|
110
106
|
}
|
|
111
107
|
function scaleGradient(u, scaleKey, ori, scaleStops, discrete = false) {
|
|
112
108
|
const scale = u.scales[scaleKey];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Color stops for a chart: each level's lower bound and its hex color without the `#`. */
|
|
2
|
+
export type LevelColors = Array<[number, string]>;
|
|
3
|
+
export declare function levelColors(levels: ReadonlyArray<{
|
|
4
|
+
range: readonly [number, ...unknown[]] | readonly number[];
|
|
5
|
+
color: string;
|
|
6
|
+
}>): LevelColors;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type MonitorDetails } from "@sjvair/sdk";
|
|
2
|
+
import type { PanelPollutant } from "../monitors/panel-pollutant";
|
|
2
3
|
import type { DateRange } from "./DateRange";
|
|
3
|
-
|
|
4
|
+
import type { SignalOptions } from "../abort";
|
|
5
|
+
/** The monitor fields the chart reads. */
|
|
6
|
+
export type ChartMonitor = Pick<MonitorDetails, "id" | "name" | "type" | "data_source">;
|
|
7
|
+
export declare function fetchChartData(m: ChartMonitor, d: DateRange, entryType: PanelPollutant, options?: SignalOptions): Promise<uPlot.AlignedData>;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { getMonitorEntries } from "@sjvair/sdk";
|
|
2
2
|
import { getUnixTime, parseISO, differenceInMinutes, addMinutes } from "date-fns";
|
|
3
|
-
|
|
4
|
-
export async function fetchChartData(m, d) {
|
|
3
|
+
export async function fetchChartData(m, d, entryType, options = {}) {
|
|
5
4
|
return await getMonitorEntries({
|
|
6
|
-
entryType
|
|
5
|
+
entryType,
|
|
7
6
|
monitorId: m.id,
|
|
8
7
|
timestampGte: d.start,
|
|
9
8
|
timestampLte: d.end
|
|
10
|
-
})
|
|
9
|
+
}, { signal: options.signal })
|
|
11
10
|
.then((entries) => {
|
|
12
11
|
const xAxisData = [];
|
|
13
12
|
const updateDuration = m.data_source.name === "PurpleAir" ? 2 : 60;
|
|
@@ -27,6 +26,9 @@ export async function fetchChartData(m, d) {
|
|
|
27
26
|
return [xAxisData.map((d) => getUnixTime(d)), yAxisRecord];
|
|
28
27
|
})
|
|
29
28
|
.catch((err) => {
|
|
29
|
+
// A cancelled request is not a failure: let the caller see the reason, log nothing.
|
|
30
|
+
if (options.signal?.aborted)
|
|
31
|
+
throw options.signal.reason;
|
|
30
32
|
console.error("Failed to load chart data: ", err);
|
|
31
33
|
return [];
|
|
32
34
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { LevelColors } from "./level-colors";
|
|
1
2
|
export declare const uPlotCursorConfig: {
|
|
2
3
|
set: (left: number, top: number) => void;
|
|
3
|
-
get: () => uPlot.Cursor;
|
|
4
|
+
get: (colors: LevelColors) => uPlot.Cursor;
|
|
4
5
|
};
|
|
5
6
|
export declare function tooltipsPlugin(): {
|
|
6
7
|
hooks: {
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { format, fromUnixTime } from "date-fns";
|
|
2
|
-
import { monitorsManager } from "../monitors/monitors.svelte";
|
|
3
|
-
function getColors() {
|
|
4
|
-
return (monitorsManager.levels ?? []).map((level) => [
|
|
5
|
-
level.range[0],
|
|
6
|
-
level.color.replace(/^#/, "")
|
|
7
|
-
]);
|
|
8
|
-
}
|
|
9
2
|
let cursLeft = -100;
|
|
10
3
|
let cursTop = -100;
|
|
11
4
|
export const uPlotCursorConfig = {
|
|
@@ -13,7 +6,7 @@ export const uPlotCursorConfig = {
|
|
|
13
6
|
cursLeft = left;
|
|
14
7
|
cursTop = top;
|
|
15
8
|
},
|
|
16
|
-
get: () => ({
|
|
9
|
+
get: (colors) => ({
|
|
17
10
|
left: cursLeft,
|
|
18
11
|
top: cursTop,
|
|
19
12
|
y: false,
|
|
@@ -21,7 +14,6 @@ export const uPlotCursorConfig = {
|
|
|
21
14
|
size: 7,
|
|
22
15
|
fill: (u, sIdx) => {
|
|
23
16
|
const xIdx = u.cursor.idxs[sIdx];
|
|
24
|
-
const colors = getColors();
|
|
25
17
|
if (xIdx != null && u.series.length >= 2 && sIdx === 1) {
|
|
26
18
|
const val = u.data[sIdx][xIdx];
|
|
27
19
|
for (let i = colors.length - 1; i >= 0; i--) {
|
|
@@ -169,9 +169,9 @@ class EvStationsMapIntegration extends MapIconLayerIntegration {
|
|
|
169
169
|
clickManager.unregister([this.referenceId]);
|
|
170
170
|
this.tooltipManager.disable();
|
|
171
171
|
this.renderer.remove();
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
// Clustering may be toggled again before the icons arrive; only the latest apply runs.
|
|
173
|
+
this.supersedePending();
|
|
174
|
+
this.whenIconsLoad(() => {
|
|
175
175
|
this.renderer.apply(this.handleStationClick);
|
|
176
176
|
this.tooltipManager.enable();
|
|
177
177
|
});
|
|
@@ -181,9 +181,7 @@ class EvStationsMapIntegration extends MapIconLayerIntegration {
|
|
|
181
181
|
this.tooltipManager.disable();
|
|
182
182
|
clickManager.unregister([this.referenceId]);
|
|
183
183
|
super.apply();
|
|
184
|
-
this.
|
|
185
|
-
if (mapManager.styleLoading)
|
|
186
|
-
return;
|
|
184
|
+
this.whenIconsLoad(() => {
|
|
187
185
|
clickManager.register([this.referenceId], this.handleStationClick);
|
|
188
186
|
this.tooltipManager.enable();
|
|
189
187
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { SignalOptions } from "../abort";
|
|
1
2
|
import type { EvStation } from "./types";
|
|
2
3
|
declare class EvStationsManager {
|
|
3
4
|
lvl2Stations: Array<EvStation> | undefined;
|
|
4
5
|
lvl3Stations: Array<EvStation> | undefined;
|
|
5
|
-
loadLvl3Stations(): Promise<void>;
|
|
6
|
-
loadLvl2Stations(): Promise<void>;
|
|
6
|
+
loadLvl3Stations({ signal }?: SignalOptions): Promise<void>;
|
|
7
|
+
loadLvl2Stations({ signal }?: SignalOptions): Promise<void>;
|
|
7
8
|
}
|
|
8
9
|
export declare const evStationsManager: EvStationsManager;
|
|
9
10
|
export type { EvStationsManager };
|
|
@@ -3,17 +3,19 @@ import * as ZipCodes from "./zip-codes";
|
|
|
3
3
|
class EvStationsManager {
|
|
4
4
|
lvl2Stations = $state();
|
|
5
5
|
lvl3Stations = $state();
|
|
6
|
-
async loadLvl3Stations() {
|
|
7
|
-
this.lvl3Stations = await fetchEvStations("dc_fast");
|
|
6
|
+
async loadLvl3Stations({ signal } = {}) {
|
|
7
|
+
this.lvl3Stations = await fetchEvStations("dc_fast", signal);
|
|
8
8
|
}
|
|
9
|
-
async loadLvl2Stations() {
|
|
10
|
-
this.lvl2Stations = await fetchEvStations("2");
|
|
9
|
+
async loadLvl2Stations({ signal } = {}) {
|
|
10
|
+
this.lvl2Stations = await fetchEvStations("2", signal);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
const zipCodes = Object.values(ZipCodes)
|
|
14
14
|
.reduce((prev, curr) => prev.concat(curr))
|
|
15
15
|
.join(",");
|
|
16
|
-
async function fetchEvStations(chargingLevel) {
|
|
16
|
+
async function fetchEvStations(chargingLevel, signal) {
|
|
17
|
+
if (signal?.aborted)
|
|
18
|
+
throw signal.reason;
|
|
17
19
|
const url = new URL(`https://developer.nlr.gov/api/alt-fuel-stations/v1.json`);
|
|
18
20
|
url.searchParams.set("fuel_type", "ELEC");
|
|
19
21
|
url.searchParams.set("state", "CA");
|
|
@@ -22,7 +24,7 @@ async function fetchEvStations(chargingLevel) {
|
|
|
22
24
|
url.searchParams.set("ev_charging_level", chargingLevel);
|
|
23
25
|
url.searchParams.set("zip", zipCodes);
|
|
24
26
|
url.searchParams.set("api_key", import.meta.env.VITE_NREL_KEY);
|
|
25
|
-
return await fetch(url)
|
|
27
|
+
return await fetch(url, { signal })
|
|
26
28
|
.then(async (res) => await res.json())
|
|
27
29
|
.then((data) => {
|
|
28
30
|
const fuelStations = data.fuel_stations;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type HMSFireGeoJSON, type HMSSmokeGeoJSON } from "@sjvair/sdk/hms";
|
|
2
|
+
import type { SignalOptions } from "../abort";
|
|
2
3
|
export interface HMSFireGroup {
|
|
3
4
|
id: string;
|
|
4
5
|
coordinates: [number, number];
|
|
@@ -11,9 +12,9 @@ declare class HmsManager {
|
|
|
11
12
|
frp: number;
|
|
12
13
|
}> | undefined;
|
|
13
14
|
fireGroups: Array<HMSFireGroup> | undefined;
|
|
14
|
-
init(): Promise<void>;
|
|
15
|
-
loadSmoke(): Promise<void>;
|
|
16
|
-
loadFire(): Promise<void>;
|
|
15
|
+
init({ signal }?: SignalOptions): Promise<void>;
|
|
16
|
+
loadSmoke({ signal }?: SignalOptions): Promise<void>;
|
|
17
|
+
loadFire({ signal }?: SignalOptions): Promise<void>;
|
|
17
18
|
}
|
|
18
19
|
export declare const hmsManager: HmsManager;
|
|
19
20
|
export type { HmsManager as HMSManager };
|
|
@@ -7,21 +7,31 @@ class HmsManager {
|
|
|
7
7
|
smoke = $state();
|
|
8
8
|
fire = $state();
|
|
9
9
|
fireGroups = $state();
|
|
10
|
-
async init() {
|
|
11
|
-
|
|
10
|
+
async init({ signal } = {}) {
|
|
11
|
+
if (signal?.aborted)
|
|
12
|
+
throw signal.reason;
|
|
13
|
+
await Promise.allSettled([this.loadSmoke({ signal }), this.loadFire({ signal })]);
|
|
14
|
+
if (signal?.aborted)
|
|
15
|
+
throw signal.reason;
|
|
12
16
|
}
|
|
13
|
-
async loadSmoke() {
|
|
14
|
-
|
|
17
|
+
async loadSmoke({ signal } = {}) {
|
|
18
|
+
if (signal?.aborted)
|
|
19
|
+
throw signal.reason;
|
|
20
|
+
this.smoke = await getHMSSmoke({ signal });
|
|
15
21
|
}
|
|
16
|
-
async loadFire() {
|
|
22
|
+
async loadFire({ signal } = {}) {
|
|
17
23
|
try {
|
|
18
|
-
|
|
24
|
+
if (signal?.aborted)
|
|
25
|
+
throw signal.reason;
|
|
26
|
+
const raw = await getHMSFire({ signal });
|
|
19
27
|
const filtered = raw.filter((d) => d.frp !== null);
|
|
20
28
|
const deduped = deduplicateByCoordinates(filtered);
|
|
21
29
|
this.fire = deduped;
|
|
22
30
|
this.fireGroups = computeFireGroups(deduped);
|
|
23
31
|
}
|
|
24
32
|
catch (err) {
|
|
33
|
+
if (signal?.aborted)
|
|
34
|
+
throw err;
|
|
25
35
|
console.error("HMS fire load failed:", err);
|
|
26
36
|
}
|
|
27
37
|
}
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
export { monitorMapRoutes } from "./routes";
|
|
33
33
|
export { ROUTER_KEY, provideMonitorMapRouter, useMonitorMapRouter, type MonitorMapRouterApi } from "./router-context";
|
|
34
34
|
export { monitorsManager } from "./monitors/monitors.svelte";
|
|
35
|
-
export type { MonitorsManager } from "./monitors/monitors.svelte";
|
|
35
|
+
export type { MonitorsManager, MonitorsInitOptions } from "./monitors/monitors.svelte";
|
|
36
36
|
export { collocationSitesManager } from "./collocation-sites/collocations.svelte";
|
|
37
37
|
export type { CollocationSitesManager } from "./collocation-sites/collocations.svelte";
|
|
38
38
|
export { evStationsManager } from "./ev-stations/ev-stations.svelte";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { sharedLoad } from "./shared-load";
|
|
2
|
+
// The heavy chunks behind the lazy routes entry (`./lazy-routes.ts`). They are imported here,
|
|
3
|
+
// not in the wrapper components that await them: sv-router treats any function whose source
|
|
4
|
+
// contains `() => import(...)` as a lazy route, and a compiled component is such a function.
|
|
5
|
+
export const loadMonitorMapLayout = sharedLoad(() => import("./MonitorMapLayout.svelte"));
|
|
6
|
+
export const loadMonitorDetailPanel = sharedLoad(() => import("./MonitorDetailPanel.svelte"));
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Routes } from "sv-router";
|
|
2
2
|
/**
|
|
3
3
|
* Lazy routes entry (`@sjvair/monitor-map/routes`): the same route tree as the main entry's
|
|
4
|
-
* `monitorMapRoutes`, but the layout and
|
|
5
|
-
* reference it at startup without loading the map.
|
|
4
|
+
* `monitorMapRoutes`, but the map layout and the monitor panel load on demand, so a host
|
|
5
|
+
* router can reference it at startup without loading the map.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* The components here are light wrappers that load the real ones themselves
|
|
8
|
+
* (`./lazy-chunks.ts`) and show the load screen meanwhile. They are deliberately not
|
|
9
|
+
* `() => import(...)` routes: sv-router renders nothing for a route until every lazy component
|
|
10
|
+
* on it has loaded, which left the outlet empty on a cold link into the map.
|
|
9
11
|
*/
|
|
10
12
|
export declare const monitorMapRoutes: Routes;
|
package/dist/lib/lazy-routes.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import LazyMapLayout from "./LazyMapLayout.svelte";
|
|
2
|
+
import LazyMonitorDetailPanel from "./LazyMonitorDetailPanel.svelte";
|
|
3
|
+
import MainMapView from "./MainMapView.svelte";
|
|
1
4
|
/**
|
|
2
5
|
* Lazy routes entry (`@sjvair/monitor-map/routes`): the same route tree as the main entry's
|
|
3
|
-
* `monitorMapRoutes`, but the layout and
|
|
4
|
-
* reference it at startup without loading the map.
|
|
6
|
+
* `monitorMapRoutes`, but the map layout and the monitor panel load on demand, so a host
|
|
7
|
+
* router can reference it at startup without loading the map.
|
|
5
8
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
9
|
+
* The components here are light wrappers that load the real ones themselves
|
|
10
|
+
* (`./lazy-chunks.ts`) and show the load screen meanwhile. They are deliberately not
|
|
11
|
+
* `() => import(...)` routes: sv-router renders nothing for a route until every lazy component
|
|
12
|
+
* on it has loaded, which left the outlet empty on a cold link into the map.
|
|
8
13
|
*/
|
|
9
14
|
export const monitorMapRoutes = {
|
|
10
|
-
layout:
|
|
11
|
-
"/":
|
|
12
|
-
"/monitor/:id":
|
|
15
|
+
layout: LazyMapLayout,
|
|
16
|
+
"/": MainMapView,
|
|
17
|
+
"/monitor/:id": LazyMonitorDetailPanel
|
|
13
18
|
};
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
* is true.
|
|
12
12
|
*/
|
|
13
13
|
ready: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Rendered on the load screen, under the logo, for as long as the load screen is up.
|
|
16
|
+
* Render it only when the caller's initial load failed (e.g. a message and a retry).
|
|
17
|
+
*/
|
|
18
|
+
loadError?: Snippet;
|
|
14
19
|
/** True when the routed detail panel (`children`) should be visible */
|
|
15
20
|
panelOpen: boolean;
|
|
16
21
|
/**
|
|
@@ -59,6 +64,7 @@
|
|
|
59
64
|
let {
|
|
60
65
|
integrations,
|
|
61
66
|
ready,
|
|
67
|
+
loadError,
|
|
62
68
|
panelOpen,
|
|
63
69
|
knownRoutes = [],
|
|
64
70
|
menu,
|
|
@@ -123,7 +129,7 @@
|
|
|
123
129
|
</script>
|
|
124
130
|
|
|
125
131
|
<div class="relative flex h-full w-full flex-col md:flex-row">
|
|
126
|
-
<LoadScreen />
|
|
132
|
+
<LoadScreen error={loadError} />
|
|
127
133
|
<div class="relative flex-1 overflow-hidden">
|
|
128
134
|
<Map {integrations} />
|
|
129
135
|
{@render overlays?.()}
|
|
@@ -9,6 +9,11 @@ export interface MapShellProps {
|
|
|
9
9
|
* is true.
|
|
10
10
|
*/
|
|
11
11
|
ready: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Rendered on the load screen, under the logo, for as long as the load screen is up.
|
|
14
|
+
* Render it only when the caller's initial load failed (e.g. a message and a retry).
|
|
15
|
+
*/
|
|
16
|
+
loadError?: Snippet;
|
|
12
17
|
/** True when the routed detail panel (`children`) should be visible */
|
|
13
18
|
panelOpen: boolean;
|
|
14
19
|
/**
|