@azohra/meteo.station 0.5.0 → 0.7.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.
Files changed (147) hide show
  1. package/README.md +17 -17
  2. package/dist/client/climatology.js +1 -1
  3. package/dist/client/history.js +3 -11
  4. package/dist/client/live.d.ts +2 -1
  5. package/dist/client/live.js +7 -4
  6. package/dist/client/stores.js +10 -2
  7. package/dist/climatology.d.ts +1 -1
  8. package/dist/climatology.js +1 -1
  9. package/dist/connectivity.d.ts +2 -2
  10. package/dist/contract.d.ts +98 -98
  11. package/dist/derive.js +9 -8
  12. package/dist/elements/elements/AirExtremesElement.js +5 -18
  13. package/dist/elements/elements/AirMatrixElement.js +6 -31
  14. package/dist/elements/elements/ClimatologyDailyPatternElement.js +17 -12
  15. package/dist/elements/elements/ClimatologyRoseElement.js +5 -15
  16. package/dist/elements/elements/CompassFanElement.js +5 -64
  17. package/dist/elements/elements/CurrentConditionsElement.js +7 -26
  18. package/dist/elements/elements/DailyPatternElement.d.ts +0 -1
  19. package/dist/elements/elements/DailyPatternElement.js +6 -120
  20. package/dist/elements/elements/DialElement.js +3 -95
  21. package/dist/elements/elements/FavorableShareElement.js +6 -21
  22. package/dist/elements/elements/RecentSummariesElement.js +6 -23
  23. package/dist/elements/elements/SparklineElement.d.ts +0 -1
  24. package/dist/elements/elements/SparklineElement.js +4 -39
  25. package/dist/elements/elements/StationCardElement.js +4 -18
  26. package/dist/elements/elements/StationFeedElement.js +4 -2
  27. package/dist/elements/elements/StationStripElement.js +4 -18
  28. package/dist/elements/elements/StationTableElement.js +15 -51
  29. package/dist/elements/elements/TrendChartElement.js +27 -94
  30. package/dist/elements/elements/WindHistoryChartElement.js +29 -189
  31. package/dist/elements/elements/WindRoseElement.d.ts +0 -1
  32. package/dist/elements/elements/WindRoseElement.js +6 -70
  33. package/dist/elements/elements/atoms.js +11 -38
  34. package/dist/elements/index.js +3 -3
  35. package/dist/elements/lib/fragments.js +8 -37
  36. package/dist/elements/lib/h.js +1 -1
  37. package/dist/elements/lib/pinned-cursor.js +48 -0
  38. package/dist/elements/lib/render.js +30 -0
  39. package/dist/fixtures.d.ts +6 -2
  40. package/dist/fixtures.js +30 -2
  41. package/dist/format.js +7 -3
  42. package/dist/geometry.d.ts +1 -1
  43. package/dist/geometry.js +22 -9
  44. package/dist/instruments.js +2 -2
  45. package/dist/react/components/AirExtremes.d.ts +1 -1
  46. package/dist/react/components/AirExtremes.js +5 -22
  47. package/dist/react/components/AirMatrix.js +10 -43
  48. package/dist/react/components/ClimatologyDailyPattern.d.ts +1 -1
  49. package/dist/react/components/ClimatologyDailyPattern.js +19 -13
  50. package/dist/react/components/ClimatologyRose.d.ts +1 -1
  51. package/dist/react/components/ClimatologyRose.js +11 -28
  52. package/dist/react/components/CompassFan.d.ts +1 -1
  53. package/dist/react/components/CompassFan.js +6 -73
  54. package/dist/react/components/CurrentConditions.d.ts +1 -1
  55. package/dist/react/components/CurrentConditions.js +11 -74
  56. package/dist/react/components/DailyPattern.d.ts +1 -3
  57. package/dist/react/components/DailyPattern.js +10 -149
  58. package/dist/react/components/Dial.d.ts +2 -3
  59. package/dist/react/components/Dial.js +5 -118
  60. package/dist/react/components/FavorableShare.d.ts +1 -1
  61. package/dist/react/components/FavorableShare.js +6 -27
  62. package/dist/react/components/FreshnessBadge.d.ts +1 -1
  63. package/dist/react/components/FreshnessBadge.js +5 -12
  64. package/dist/react/components/RecentSummaries.d.ts +1 -1
  65. package/dist/react/components/RecentSummaries.js +6 -44
  66. package/dist/react/components/SceneTree.js +38 -0
  67. package/dist/react/components/Sparkline.d.ts +1 -1
  68. package/dist/react/components/Sparkline.js +3 -39
  69. package/dist/react/components/StationCard.d.ts +2 -2
  70. package/dist/react/components/StationCard.js +5 -45
  71. package/dist/react/components/StationStrip.d.ts +1 -1
  72. package/dist/react/components/StationStrip.js +5 -60
  73. package/dist/react/components/StationTable.js +21 -75
  74. package/dist/react/components/TrendChart.js +13 -86
  75. package/dist/react/components/WindArrow.d.ts +1 -1
  76. package/dist/react/components/WindArrow.js +3 -15
  77. package/dist/react/components/WindHistoryChart.js +12 -205
  78. package/dist/react/components/WindRose.d.ts +1 -3
  79. package/dist/react/components/WindRose.js +6 -89
  80. package/dist/react/components/WindSampleStrip.js +14 -139
  81. package/dist/react/components/atoms.d.ts +5 -5
  82. package/dist/react/components/atoms.js +12 -48
  83. package/dist/react/hooks/useStation.js +28 -50
  84. package/dist/react/hooks/useStationCurrent.js +3 -2
  85. package/dist/react/hooks/useStationFeed.d.ts +0 -1
  86. package/dist/react/hooks/useStationFeed.js +3 -2
  87. package/dist/react/index.d.ts +2 -2
  88. package/dist/react/index.js +7 -7
  89. package/dist/react/lib/cells.js +4 -24
  90. package/dist/react/lib/use-pinned-cursor.js +32 -0
  91. package/dist/samples.js +7 -43
  92. package/dist/scene/air-extremes.js +12 -27
  93. package/dist/scene/air-matrix.js +45 -58
  94. package/dist/scene/card.js +14 -40
  95. package/dist/scene/cells.d.ts +4 -0
  96. package/dist/scene/cells.js +51 -0
  97. package/dist/scene/chart.js +2 -1
  98. package/dist/scene/climatology-pattern.d.ts +1 -2
  99. package/dist/scene/climatology-pattern.js +10 -11
  100. package/dist/scene/climatology-rose.d.ts +1 -2
  101. package/dist/scene/climatology-rose.js +14 -33
  102. package/dist/scene/compass-fan.js +28 -100
  103. package/dist/scene/current.d.ts +2 -1
  104. package/dist/scene/current.js +29 -56
  105. package/dist/scene/daily-pattern.d.ts +1 -3
  106. package/dist/scene/daily-pattern.js +20 -27
  107. package/dist/scene/dial-parts.d.ts +1 -0
  108. package/dist/scene/dial-parts.js +70 -0
  109. package/dist/scene/dial.d.ts +1 -2
  110. package/dist/scene/dial.js +48 -136
  111. package/dist/scene/favorable-share.js +16 -33
  112. package/dist/scene/glyphs.js +20 -16
  113. package/dist/scene/index.d.ts +5 -3
  114. package/dist/scene/node.js +19 -0
  115. package/dist/scene/recent-summaries.js +26 -66
  116. package/dist/scene/rose.js +89 -117
  117. package/dist/scene/sample-strip.d.ts +1 -2
  118. package/dist/scene/sample-strip.js +35 -36
  119. package/dist/scene/sparkline.js +31 -40
  120. package/dist/scene/strip.js +18 -57
  121. package/dist/scene/table.js +47 -69
  122. package/dist/scene/trend.d.ts +1 -2
  123. package/dist/scene/trend.js +29 -55
  124. package/dist/scene/wind-history.d.ts +1 -2
  125. package/dist/scene/wind-history.js +41 -51
  126. package/dist/scene/wind-plot.js +70 -140
  127. package/dist/server/adapters/campbell.d.ts +7 -7
  128. package/dist/server/adapters/campbell.js +1 -1
  129. package/dist/server/adapters/ecowitt.d.ts +8 -8
  130. package/dist/server/adapters/tempest.d.ts +6 -6
  131. package/dist/server/adapters/windnerd-climatology.js +4 -3
  132. package/dist/server/adapters/windnerd-live.js +3 -2
  133. package/dist/server/adapters/windnerd.d.ts +10 -11
  134. package/dist/server/adapters/windnerd.js +3 -13
  135. package/dist/server/config.d.ts +48 -48
  136. package/dist/server/hologram.js +2 -1
  137. package/dist/server/index.d.ts +2 -2
  138. package/dist/server/index.js +2 -2
  139. package/dist/windnerd.d.ts +3 -1
  140. package/dist/windnerd.js +11 -1
  141. package/package.json +7 -12
  142. package/schema/README.md +3 -3
  143. package/schema/stationclimatology.schema.json +64 -61
  144. package/schema/stationcurrent.schema.json +68 -156
  145. package/schema/stationfeed.schema.json +71 -163
  146. package/schema/stationhistory.schema.json +37 -46
  147. package/schema/stationlive.schema.json +221 -306
@@ -1,53 +1,18 @@
1
1
  import { sparklineScene } from "../../scene/sparkline.js";
2
2
  import { numberAttribute } from "../lib/attributes.js";
3
3
  import { MeteoStationElement } from "../lib/base.js";
4
- import { h, hs } from "../lib/h.js";
4
+ import { renderScene } from "../lib/render.js";
5
5
  //#region src/elements/elements/SparklineElement.ts
6
6
  function sparklineNode(options) {
7
7
  const { station, thresholds, words, width = 120, height = 32, showBand = true } = options;
8
- const scene = sparklineScene({
8
+ return renderScene(sparklineScene({
9
9
  height,
10
10
  showBand,
11
11
  station,
12
12
  thresholds,
13
13
  width,
14
14
  words
15
- });
16
- if (scene.kind === "placeholder") {
17
- const placeholder = h("span", {
18
- "aria-label": scene.ariaLabel,
19
- class: scene.className,
20
- role: "img"
21
- }, scene.text);
22
- placeholder.style.height = `${scene.height}px`;
23
- placeholder.style.width = `${scene.width}px`;
24
- return placeholder;
25
- }
26
- return hs("svg", {
27
- "aria-label": scene.svg.ariaLabel,
28
- class: scene.svg.className,
29
- height: scene.svg.height,
30
- role: "img",
31
- viewBox: scene.svg.viewBox,
32
- width: scene.svg.width
33
- }, scene.bands.map((band) => hs("polygon", {
34
- class: band.className,
35
- points: band.points
36
- })), scene.trace.map((part) => part.kind === "dot" ? hs("circle", {
37
- class: part.className,
38
- cx: part.cx,
39
- cy: part.cy,
40
- r: part.r
41
- }) : part.kind === "polyline" ? hs("polyline", {
42
- class: part.className,
43
- points: part.points
44
- }) : hs("line", {
45
- class: part.className,
46
- x1: part.x1,
47
- x2: part.x2,
48
- y1: part.y1,
49
- y2: part.y2
50
- })));
15
+ }));
51
16
  }
52
17
  var SparklineElement = class extends MeteoStationElement {
53
18
  static observedAttributes = [
@@ -71,4 +36,4 @@ var SparklineElement = class extends MeteoStationElement {
71
36
  }
72
37
  };
73
38
  //#endregion
74
- export { SparklineElement, sparklineNode };
39
+ export { SparklineElement };
@@ -2,12 +2,12 @@ import { freshness, stationFreshnessThresholds } from "../../derive.js";
2
2
  import { mergeStringOverrides, resolveStrings } from "../../strings.js";
3
3
  import { resolveDisplay } from "../../display.js";
4
4
  import { subscribeTicker } from "../../client/ticker.js";
5
- import { STATION_CARD_CLASS, cardHeaderScene, cardPartThresholds, cardPartWiringError, summaryScene } from "../../scene/card.js";
5
+ import { STATION_CARD_CLASS, cardHeaderNode, cardPartThresholds, cardPartWiringError, summaryNode } from "../../scene/card.js";
6
6
  import { numberAttribute } from "../lib/attributes.js";
7
7
  import { provideContext, requestContext } from "../lib/context.js";
8
8
  import { MeteoElement, MeteoStationElement } from "../lib/base.js";
9
9
  import { h } from "../lib/h.js";
10
- import { freshnessBadgeSpan } from "../lib/fragments.js";
10
+ import { renderOptional, renderScene } from "../lib/render.js";
11
11
  //#region src/elements/elements/StationCardElement.ts
12
12
  const STATION_CARD_CONTEXT_KEY = "meteo-station-card";
13
13
  var StationCardElement = class extends MeteoStationElement {
@@ -136,13 +136,7 @@ var StationCardHeaderElement = class extends StationCardPartElement {
136
136
  receivedAtMs,
137
137
  nowMs: Date.now()
138
138
  }, stationFreshnessThresholds(station));
139
- const scene = cardHeaderScene(station, words);
140
- const { name, meta } = scene.identity;
141
- this.replaceChildren(h("header", { class: scene.className }, h("div", { class: scene.identity.className }, h("h3", { class: name.className }, name.link ? h("a", {
142
- href: name.link.href,
143
- rel: name.link.rel,
144
- target: name.link.target
145
- }, name.link.text) : name.text), h("p", { class: meta.className }, h("span", { class: meta.source.className }, meta.source.text), meta.elevation != null && h("span", { class: meta.elevation.className }, meta.elevation.text))), status != null && freshnessBadgeSpan(status, words)));
139
+ this.replaceChildren(renderScene(cardHeaderNode(station, status, words)));
146
140
  }
147
141
  };
148
142
  var StationCardInstrumentElement = class extends StationCardPartElement {
@@ -196,15 +190,7 @@ var StationCardSummaryElement = class extends StationCardPartElement {
196
190
  render() {
197
191
  const context = this.card();
198
192
  const words = resolveStrings(context.strings);
199
- const summary = summaryScene(context.station, context.unit, words, context.formatTime);
200
- if (summary == null) {
201
- this.replaceChildren();
202
- return;
203
- }
204
- this.replaceChildren(h("dl", {
205
- "aria-label": summary.ariaLabel,
206
- class: summary.className
207
- }, summary.items.map((item) => h("div", { class: summary.itemClassName }, h("dt", { class: summary.labelClassName }, item.label), h("dd", null, item.value)))));
193
+ this.replaceChildren(...renderOptional(summaryNode(context.station, context.unit, words, context.formatTime)));
208
194
  }
209
195
  };
210
196
  //#endregion
@@ -163,8 +163,10 @@ var StationFeedElement = class extends MeteoElement {
163
163
  this.#unsubscribeStore = this.#store.subscribe(() => this.#onStoreChange());
164
164
  }
165
165
  }
166
- if (this.#store != null) if (this.hasAttribute("paused")) this.#store.stop();
167
- else this.#store.start();
166
+ if (this.#store != null) {
167
+ if (this.hasAttribute("paused")) this.#store.stop();
168
+ else this.#store.start();
169
+ }
168
170
  }
169
171
  #buildStore(src, stationId, pollSeconds, currentPollSeconds) {
170
172
  const fetchInit = () => this.#fetchInit;
@@ -1,7 +1,6 @@
1
1
  import { stationStripScene } from "../../scene/strip.js";
2
2
  import { MeteoStationElement } from "../lib/base.js";
3
- import { h } from "../lib/h.js";
4
- import { directionCellNodes, freshnessBadgeSpan, stationNameNode } from "../lib/fragments.js";
3
+ import { renderScene } from "../lib/render.js";
5
4
  //#region src/elements/elements/StationStripElement.ts
6
5
  var StationStripElement = class extends MeteoStationElement {
7
6
  static observedAttributes = [
@@ -17,26 +16,13 @@ var StationStripElement = class extends MeteoStationElement {
17
16
  const station = this.requiredStation("meteo-station-strip");
18
17
  const { formatTime, unit, words } = this.display();
19
18
  const status = this.freshnessOf(station);
20
- const scene = stationStripScene({
19
+ this.replaceChildren(renderScene(stationStripScene({
21
20
  formatTime,
21
+ freshness: status,
22
22
  station,
23
23
  unit,
24
24
  words
25
- });
26
- const { body } = scene;
27
- const cells = body.kind === "reading" ? [
28
- h("span", { class: body.wind.className }, h("strong", null, body.wind.value), h("small", null, body.wind.unitLabel)),
29
- body.gustLull != null && [h("span", { class: body.gustLull.lull.className }, h("small", { class: body.gustLull.lull.labelClassName }, body.gustLull.lull.label), body.gustLull.lull.value), h("span", { class: body.gustLull.gust.className }, h("small", { class: body.gustLull.gust.labelClassName }, body.gustLull.gust.label), body.gustLull.gust.value)],
30
- h("span", { class: body.from.className }, ...directionCellNodes(body.from.windAvgMps, body.from.windDirectionDeg, words)),
31
- body.temperature != null && h("span", { class: body.temperature.className }, body.temperature.text),
32
- h("span", { class: body.updated.className }, h("span", { class: body.updated.time.className }, body.updated.time.text), status != null && freshnessBadgeSpan(status, words))
33
- ] : [h("span", { class: body.className }, body.text)];
34
- this.replaceChildren(h("div", {
35
- "aria-label": scene.root.ariaLabel,
36
- class: scene.root.className,
37
- "data-status": scene.root.status,
38
- role: "group"
39
- }, h("span", { class: scene.stationClassName }, stationNameNode(station)), ...cells));
25
+ })));
40
26
  }
41
27
  };
42
28
  //#endregion
@@ -1,9 +1,10 @@
1
1
  import { requireResolved } from "../../display.js";
2
- import { stationTableRowScene, stationTableScene } from "../../scene/table.js";
2
+ import { TABLE_BODY_CLASS, TABLE_ROW_CLASS, TABLE_STATION_CELL_CLASS, stationTableHeadNode, stationTableRootAttrs, stationTableRowCells } from "../../scene/table.js";
3
3
  import { ELEMENTS_AMBIENT_HINT } from "../lib/ambient.js";
4
4
  import { MeteoStationElement } from "../lib/base.js";
5
5
  import { h } from "../lib/h.js";
6
- import { directionCellNodes, freshnessBadgeSpan, stationNameNode } from "../lib/fragments.js";
6
+ import { renderScene } from "../lib/render.js";
7
+ import { stationNameNode } from "../lib/fragments.js";
7
8
  //#region src/elements/elements/StationTableElement.ts
8
9
  var StationTableElement = class extends MeteoStationElement {
9
10
  static observedAttributes = [
@@ -37,65 +38,28 @@ var StationTableElement = class extends MeteoStationElement {
37
38
  render() {
38
39
  const stations = requireResolved("meteo-station-table", "stations", this.#stations ?? this.ambient()?.feed?.stations, ELEMENTS_AMBIENT_HINT);
39
40
  const { formatTime, unit, words } = this.display();
40
- const scene = stationTableScene(stations, words);
41
- this.replaceChildren(h("div", {
42
- "aria-label": scene.root.ariaLabel,
43
- class: scene.root.className,
44
- role: "table"
45
- }, h("div", {
46
- class: scene.head.className,
47
- role: "row"
48
- }, scene.head.columns.map((column) => h("span", { role: "columnheader" }, column))), h("div", {
49
- class: scene.bodyClassName,
41
+ this.replaceChildren(h("div", stationTableRootAttrs(stations, words), renderScene(stationTableHeadNode(words)), h("div", {
42
+ class: TABLE_BODY_CLASS,
50
43
  role: "rowgroup"
51
44
  }, stations.map((station) => this.#row(station, unit, words, formatTime)))));
52
45
  }
53
46
  #row(station, unit, words, formatTime) {
54
47
  const status = this.freshnessOf(station);
55
48
  const meta = this.#stationMeta ? this.#stationMeta(station) : station.sourceLabel;
56
- const row = stationTableRowScene({
57
- formatTime,
58
- station,
59
- unit,
60
- words
61
- });
62
- const { cells } = row;
63
49
  return h("div", {
64
- class: row.className,
65
- "data-status": row.status,
50
+ class: TABLE_ROW_CLASS,
51
+ "data-status": station.status,
66
52
  role: "row"
67
53
  }, h("span", {
68
- class: row.stationCellClassName,
54
+ class: TABLE_STATION_CELL_CLASS,
69
55
  role: "cell"
70
- }, h("strong", null, stationNameNode(station)), h("small", null, meta)), cells.kind === "reading" ? [
71
- h("span", {
72
- class: cells.wind.className,
73
- role: "cell"
74
- }, h("strong", null, cells.wind.value), h("small", null, cells.wind.unitLabel)),
75
- h("span", {
76
- class: cells.lull.className,
77
- role: "cell"
78
- }, cells.lull.value),
79
- h("span", {
80
- class: cells.gust.className,
81
- role: "cell"
82
- }, cells.gust.value),
83
- h("span", {
84
- class: cells.from.className,
85
- role: "cell"
86
- }, ...directionCellNodes(cells.from.windAvgMps, cells.from.windDirectionDeg, words)),
87
- h("span", {
88
- class: cells.temperature.className,
89
- role: "cell"
90
- }, cells.temperature.value),
91
- h("span", {
92
- class: cells.updated.className,
93
- role: "cell"
94
- }, h("span", { class: cells.updated.time.className }, cells.updated.time.text), status != null && freshnessBadgeSpan(status, words))
95
- ] : h("span", {
96
- class: cells.className,
97
- role: "cell"
98
- }, cells.text));
56
+ }, h("strong", null, stationNameNode(station)), h("small", null, meta)), stationTableRowCells({
57
+ formatTime,
58
+ freshness: status,
59
+ station,
60
+ unit,
61
+ words
62
+ }).map((child) => typeof child === "object" && child !== null ? renderScene(child) : child));
99
63
  }
100
64
  };
101
65
  //#endregion
@@ -1,21 +1,25 @@
1
1
  import { requireResolved } from "../../display.js";
2
2
  import { measuredChartWidth } from "../../geometry.js";
3
- import { activeChartIndex, chartIndexAtClient, readoutAriaLive, togglePinnedAt } from "../../scene/chart.js";
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
- import { h, hs } from "../lib/h.js";
7
+ import { h } from "../lib/h.js";
8
+ import { renderChildren, renderScene } from "../lib/render.js";
9
+ import { PinnedCursor } from "../lib/pinned-cursor.js";
8
10
  //#region src/elements/elements/TrendChartElement.ts
9
11
  var TrendChartElement = class extends MeteoStationElement {
10
12
  static observedAttributes = ["series", "station-id"];
11
13
  #width = null;
12
14
  #observer = null;
13
- #pinnedAt = null;
14
- #previewIndex = null;
15
15
  #scene = null;
16
16
  #readout = null;
17
- #svg = null;
18
- #hit = null;
17
+ #wrap = null;
18
+ #cursor = new PinnedCursor({
19
+ scene: () => this.#scene,
20
+ svg: () => this.#wrap?.querySelector("svg") ?? null,
21
+ onChange: () => this.#updateCursor()
22
+ });
19
23
  disconnected() {
20
24
  this.#observer?.disconnect();
21
25
  this.#observer = null;
@@ -72,103 +76,32 @@ var TrendChartElement = class extends MeteoStationElement {
72
76
  class: scene.readout.className
73
77
  });
74
78
  this.#readout = readout;
75
- const hit = hs("rect", {
76
- class: scene.hit.className,
77
- fill: scene.hit.fill,
78
- height: scene.hit.height,
79
- onclick: (event) => this.#handleClick(event),
80
- onpointerleave: () => {
81
- this.#previewIndex = null;
82
- this.#updateCursor();
83
- },
84
- onpointermove: (event) => this.#handlePointerMove(event),
85
- width: scene.hit.width,
86
- x: scene.hit.x,
87
- y: scene.hit.y
88
- });
89
- this.#hit = hit;
90
- const svg = hs("svg", {
91
- "aria-label": scene.svg.ariaLabel,
92
- class: scene.svg.className,
93
- height: scene.svg.height,
94
- role: "img",
95
- viewBox: scene.svg.viewBox,
96
- width: scene.svg.width
97
- }, scene.grid.map(({ line, label }) => hs("g", null, hs("line", {
98
- class: line.className,
99
- x1: line.x1,
100
- x2: line.x2,
101
- y1: line.y1,
102
- y2: line.y2
103
- }), hs("text", {
104
- class: label.className,
105
- "text-anchor": label.anchor,
106
- x: label.x,
107
- y: label.y
108
- }, label.text))), scene.segments.map((segment) => segment.kind === "dot" ? hs("circle", {
109
- class: segment.className,
110
- cx: segment.cx,
111
- cy: segment.cy,
112
- r: segment.r
113
- }) : hs("polyline", {
114
- class: segment.className,
115
- points: segment.points
116
- })), scene.ticks.map((tick) => hs("text", {
117
- class: tick.className,
118
- "text-anchor": tick.anchor,
119
- x: tick.x,
120
- y: tick.y
121
- }, tick.text)), hit);
122
- this.#svg = svg;
123
- wrap.replaceChildren(readout, svg);
79
+ this.#wrap = wrap;
80
+ wrap.replaceChildren(readout, this.#drawSvg());
124
81
  this.#updateCursor();
125
82
  }
126
- #indexAtPoint(clientX) {
83
+ #drawSvg() {
127
84
  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();
85
+ if (scene == null) throw new Error("meteo-trend-chart: no scene to draw");
86
+ return renderScene(scene.draw([], {
87
+ onClick: (event) => this.#cursor.handleClick(event),
88
+ onPointerLeave: () => this.#cursor.handlePointerLeave(),
89
+ onPointerMove: (event) => this.#cursor.handlePointerMove(event)
90
+ }));
145
91
  }
146
92
  #updateCursor() {
147
93
  const scene = this.#scene;
148
94
  const readout = this.#readout;
149
- const svg = this.#svg;
150
- const hit = this.#hit;
151
- if (scene == null || readout == null || svg == null || hit == null) return;
152
- const inspection = scene.inspect(activeChartIndex(scene.points, this.#pinnedAt, this.#previewIndex));
153
- readout.setAttribute("aria-live", readoutAriaLive(this.#previewIndex));
95
+ const wrap = this.#wrap;
96
+ if (scene == null || readout == null || wrap == null) return;
97
+ const inspection = scene.inspect(this.#cursor.activeIndex());
98
+ readout.setAttribute("aria-live", readoutAriaLive(this.#cursor.previewIndex));
154
99
  readout.replaceChildren(h("strong", null, inspection.readout.strong), h("span", null, inspection.readout.span));
100
+ const svg = wrap.querySelector("svg");
101
+ const hit = svg?.querySelector(".meteo-hit") ?? null;
102
+ if (svg == null) return;
155
103
  for (const mark of [...svg.querySelectorAll(".meteo-cursor, .meteo-cursor-dot")]) mark.remove();
156
- const cursor = inspection.cursor;
157
- if (cursor != null) {
158
- svg.insertBefore(hs("line", {
159
- class: cursor.line.className,
160
- x1: cursor.line.x1,
161
- x2: cursor.line.x2,
162
- y1: cursor.line.y1,
163
- y2: cursor.line.y2
164
- }), hit);
165
- if (cursor.dot != null) svg.insertBefore(hs("circle", {
166
- class: cursor.dot.className,
167
- cx: cursor.dot.cx,
168
- cy: cursor.dot.cy,
169
- r: cursor.dot.r
170
- }), hit);
171
- }
104
+ for (const node of renderChildren(inspection.cursor)) svg.insertBefore(node, hit);
172
105
  }
173
106
  };
174
107
  //#endregion
@@ -1,14 +1,17 @@
1
1
  import { measuredChartWidth } from "../../geometry.js";
2
- import { activeChartIndex, chartIndexAtClient, readoutAriaLive, togglePinnedAt } from "../../scene/chart.js";
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
- import { h, hs } from "../lib/h.js";
6
+ import { h } from "../lib/h.js";
7
+ import { renderChildren, renderScene } from "../lib/render.js";
7
8
  import { windArrowSvg } from "../lib/fragments.js";
9
+ import { PinnedCursor } from "../lib/pinned-cursor.js";
8
10
  //#region src/elements/elements/WindHistoryChartElement.ts
9
11
  let hatchCounter = 0;
10
12
  function readoutSpan(parts) {
11
- return h("span", null, ...parts.map((part) => part.kind === "arrow" ? windArrowSvg(part.deg) : part.text));
13
+ const children = parts.map((part) => part.kind === "arrow" ? windArrowSvg(part.deg) : part.text);
14
+ return h("span", null, ...children);
12
15
  }
13
16
  var WindHistoryChartElement = class extends MeteoStationElement {
14
17
  static observedAttributes = [
@@ -23,12 +26,14 @@ var WindHistoryChartElement = class extends MeteoStationElement {
23
26
  ];
24
27
  #width = null;
25
28
  #observer = null;
26
- #pinnedAt = null;
27
- #previewIndex = null;
28
29
  #scene = null;
29
30
  #readout = null;
30
- #svg = null;
31
- #hit = null;
31
+ #wrap = null;
32
+ #cursor = new PinnedCursor({
33
+ scene: () => this.#scene,
34
+ svg: () => this.#wrap?.querySelector("svg") ?? null,
35
+ onChange: () => this.#updateCursor()
36
+ });
32
37
  disconnected() {
33
38
  this.#observer?.disconnect();
34
39
  this.#observer = null;
@@ -94,197 +99,32 @@ var WindHistoryChartElement = class extends MeteoStationElement {
94
99
  class: scene.readout.className
95
100
  });
96
101
  this.#readout = readout;
97
- const hit = hs("rect", {
98
- class: scene.hit.className,
99
- fill: scene.hit.fill,
100
- height: scene.hit.height,
101
- onclick: (event) => this.#handleClick(event),
102
- onpointerleave: () => {
103
- this.#previewIndex = null;
104
- this.#updateCursor();
105
- },
106
- onpointermove: (event) => this.#handlePointerMove(event),
107
- width: scene.hit.width,
108
- x: scene.hit.x,
109
- y: scene.hit.y
110
- });
111
- this.#hit = hit;
112
- const svg = hs("svg", {
113
- "aria-label": scene.svg.ariaLabel,
114
- class: scene.svg.className,
115
- height: scene.svg.height,
116
- role: "img",
117
- viewBox: scene.svg.viewBox,
118
- width: scene.svg.width
119
- }, hs("defs", null, hs("pattern", {
120
- height: scene.defs.pattern.height,
121
- id: scene.defs.pattern.id,
122
- patternTransform: scene.defs.pattern.transform,
123
- patternUnits: scene.defs.pattern.units,
124
- width: scene.defs.pattern.width
125
- }, hs("line", {
126
- class: scene.defs.pattern.line.className,
127
- x1: scene.defs.pattern.line.x1,
128
- x2: scene.defs.pattern.line.x2,
129
- y1: scene.defs.pattern.line.y1,
130
- y2: scene.defs.pattern.line.y2
131
- })), hs("clipPath", { id: scene.defs.clip.id }, hs("rect", {
132
- height: scene.defs.clip.rect.height,
133
- width: scene.defs.clip.rect.width,
134
- x: scene.defs.clip.rect.x,
135
- y: scene.defs.clip.rect.y
136
- }))), scene.zones.map((zone) => hs("rect", {
137
- class: zone.className,
138
- height: zone.height,
139
- width: zone.width,
140
- x: zone.x,
141
- y: zone.y
142
- })), scene.nightRects.map((rect) => hs("rect", {
143
- class: rect.className,
144
- height: rect.height,
145
- width: rect.width,
146
- x: rect.x,
147
- y: rect.y
148
- })), scene.grid.map(({ line, label }) => hs("g", null, hs("line", {
149
- class: line.className,
150
- x1: line.x1,
151
- x2: line.x2,
152
- y1: line.y1,
153
- y2: line.y2
154
- }), hs("text", {
155
- class: label.className,
156
- "text-anchor": label.anchor,
157
- x: label.x,
158
- y: label.y
159
- }, label.text))), scene.thresholdGuides.map(({ line, label }) => hs("g", null, hs("line", {
160
- class: line.className,
161
- x1: line.x1,
162
- x2: line.x2,
163
- y1: line.y1,
164
- y2: line.y2
165
- }), hs("text", {
166
- class: label.className,
167
- "text-anchor": label.anchor,
168
- x: label.x,
169
- y: label.y
170
- }, label.text))), scene.vaneGuides.map((guide) => hs("line", {
171
- class: guide.className,
172
- x1: guide.x1,
173
- x2: guide.x2,
174
- y1: guide.y1,
175
- y2: guide.y2
176
- })), scene.gaps.map((gap) => hs("rect", {
177
- class: gap.className,
178
- fill: gap.fill,
179
- height: gap.height,
180
- width: gap.width,
181
- x: gap.x,
182
- y: gap.y
183
- })), scene.band != null && hs("polygon", {
184
- class: scene.band.className,
185
- points: scene.band.points
186
- }), scene.compare != null && hs("polyline", {
187
- class: scene.compare.className,
188
- "clip-path": scene.compare.clipPath,
189
- points: scene.compare.points
190
- }), scene.mean.kind === "polyline" ? hs("polyline", {
191
- class: scene.mean.className,
192
- points: scene.mean.points
193
- }) : scene.mean.segments.map((segment) => hs("line", {
194
- class: segment.className,
195
- x1: segment.x1,
196
- x2: segment.x2,
197
- y1: segment.y1,
198
- y2: segment.y2
199
- })), scene.calmNote != null && hs("text", {
200
- class: scene.calmNote.className,
201
- "text-anchor": scene.calmNote.anchor,
202
- x: scene.calmNote.x,
203
- y: scene.calmNote.y
204
- }, scene.calmNote.text), hs("text", {
205
- class: scene.rowLabels.to.className,
206
- "text-anchor": scene.rowLabels.to.anchor,
207
- x: scene.rowLabels.to.x,
208
- y: scene.rowLabels.to.y
209
- }, scene.rowLabels.to.text), scene.vanes.map((vane) => vane.mark.kind === "calm" ? hs("text", {
210
- class: vane.mark.text.className,
211
- "text-anchor": vane.mark.text.anchor,
212
- x: vane.mark.text.x,
213
- y: vane.mark.text.y
214
- }, vane.mark.text.text) : hs("path", {
215
- class: vane.mark.className,
216
- d: vane.mark.d
217
- })), scene.vanes.flatMap((vane) => vane.label == null ? [] : [hs("text", {
218
- class: vane.label.className,
219
- "text-anchor": vane.label.anchor,
220
- x: vane.label.x,
221
- y: vane.label.y
222
- }, vane.label.text)]), hs("text", {
223
- class: scene.rowLabels.avg.className,
224
- "text-anchor": scene.rowLabels.avg.anchor,
225
- x: scene.rowLabels.avg.x,
226
- y: scene.rowLabels.avg.y
227
- }, scene.rowLabels.avg.text), scene.vanes.flatMap((vane) => vane.value == null ? [] : [hs("text", {
228
- class: vane.value.className,
229
- "text-anchor": vane.value.anchor,
230
- x: vane.value.x,
231
- y: vane.value.y
232
- }, vane.value.text)]), scene.ticks.map((tick) => hs("text", {
233
- class: tick.className,
234
- "text-anchor": tick.anchor,
235
- x: tick.x,
236
- y: tick.y
237
- }, tick.text)), hit);
238
- this.#svg = svg;
239
- wrap.replaceChildren(readout, svg);
102
+ this.#wrap = wrap;
103
+ wrap.replaceChildren(readout, this.#drawSvg());
240
104
  this.#updateCursor();
241
105
  }
242
- #indexAtPoint(clientX) {
106
+ #drawSvg() {
243
107
  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();
108
+ if (scene == null) throw new Error("meteo-wind-history-chart: no scene to draw");
109
+ return renderScene(scene.draw([], {
110
+ onClick: (event) => this.#cursor.handleClick(event),
111
+ onPointerLeave: () => this.#cursor.handlePointerLeave(),
112
+ onPointerMove: (event) => this.#cursor.handlePointerMove(event)
113
+ }));
261
114
  }
262
115
  #updateCursor() {
263
116
  const scene = this.#scene;
264
117
  const readout = this.#readout;
265
- const svg = this.#svg;
266
- const hit = this.#hit;
267
- if (scene == null || readout == null || svg == null || hit == null) return;
268
- const inspection = scene.inspect(activeChartIndex(scene.points, this.#pinnedAt, this.#previewIndex));
269
- readout.setAttribute("aria-live", readoutAriaLive(this.#previewIndex));
118
+ const wrap = this.#wrap;
119
+ if (scene == null || readout == null || wrap == null) return;
120
+ const inspection = scene.inspect(this.#cursor.activeIndex());
121
+ readout.setAttribute("aria-live", readoutAriaLive(this.#cursor.previewIndex));
270
122
  readout.replaceChildren(h("strong", null, inspection.readout.strong), readoutSpan(inspection.readout.span));
123
+ const svg = wrap.querySelector("svg");
124
+ const hit = svg?.querySelector(".meteo-hit") ?? null;
125
+ if (svg == null) return;
271
126
  for (const mark of [...svg.querySelectorAll(".meteo-cursor, .meteo-cursor-dot")]) mark.remove();
272
- const cursor = inspection.cursor;
273
- if (cursor != null) {
274
- svg.insertBefore(hs("line", {
275
- class: cursor.line.className,
276
- x1: cursor.line.x1,
277
- x2: cursor.line.x2,
278
- y1: cursor.line.y1,
279
- y2: cursor.line.y2
280
- }), hit);
281
- svg.insertBefore(hs("circle", {
282
- class: cursor.dot.className,
283
- cx: cursor.dot.cx,
284
- cy: cursor.dot.cy,
285
- r: cursor.dot.r
286
- }), hit);
287
- }
127
+ for (const node of renderChildren(inspection.cursor)) svg.insertBefore(node, hit);
288
128
  }
289
129
  };
290
130
  //#endregion
@@ -1,7 +1,6 @@
1
1
  import { HistoryPoint } from "../../contract.js";
2
2
  import "../../index.js";
3
3
  import { MeteoStationElement } from "../lib/base.js";
4
- import "../../scene/index.js";
5
4
  //#region src/elements/elements/WindRoseElement.d.ts
6
5
  declare class WindRoseElement extends MeteoStationElement {
7
6
  #private;