@sailingrotevista/rotevista-dash 6.1.3 → 6.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sailing Rotevista
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @sailingrotevista/rotevista-dash
2
+
3
+ ## Sailing Dashboard Pro (v6.0)
4
+
5
+ A tactical marine dashboard and advanced monitoring system for sailboats, designed to run as a Web App (PWA) fully integrated into the **Signal K** ecosystem. Specifically optimized for precision rendering on boat tablets (such as iPads and Samsung Galaxy Tab Active) and built to run efficiently on low-resource gateways like the **Victron Cerbo GX** (running Venus OS Large) or Raspberry Pi.
6
+
7
+ ---
8
+
9
+ ## Core Features
10
+
11
+ ### 📈 Server-Side RAM-Buffered History
12
+ Unlike traditional dashboards that store history in the volatile memory of the client browser (wiping it whenever the screen locks or the browser reloads), this dashboard performs continuous background logging in RAM directly within the Signal K server process. Upon startup, the client instantly loads up to 60 minutes of pre-populated history via a fast JSON API endpoint, ensuring fully drawn, stable charts from the very first second the page is opened.
13
+
14
+ ### 🔋 Extreme Low-Power Architecture (Battery Saver)
15
+ Engineered for long-range cruising without overheating your mobile devices or draining the boat's house batteries:
16
+ * **Event-Driven SVG Redraw:** Complex SVG chart elements are not redrawn on a blind timer. Instead, they are redrawn *only* when a new historical data point is appended to the buffer (reducing the browser's active SVG layout and paint cycles by **93%**).
17
+ * **Virtual-DOM Text Protection (`safeSetText`):** Digital text readouts are updated only if their numerical value has actually changed since the previous second, bypassing expensive browser style and layout calculations (*reflow/repaint*).
18
+ * **Zero-Overhead Analog Needles:** Pointers (AWA, TWA, Leeway) snap instantly to their new positions at 1Hz instead of forcing continuous 60fps style interpolations, allowing the tablet's GPU to rest in a low-power idle state.
19
+
20
+ ### 🧭 Weather Compass & True Wind Direction (TWD) Trends
21
+ * **Tactical Trend (Short-term):** Instantly detects lift or header shifts by comparing the 2-second moving average of True Wind Angle (TWA) with the 10-second average.
22
+ * **Strategic Trend (Long-term):** Flashing green (CW) and red (CCW) dots on the TWD mini-compass indicate meteorological wind rotations, comparing the last 1 minute of wind with a stable strategic baseline of **15 minutes** under sail or **60 minutes** at anchor.
23
+ * **Absolute UTC Epoch Snapping:** Time windows on both the server and any connected clients are locked to absolute UTC second boundaries (00, 10, 20, 30, 40, 50). This eliminates phase offsets and ensures identical tactical trends across all devices on the boat.
24
+
25
+ ### 🛡️ Shallow Water Alarms & Geometric Safety Lines
26
+ * Automatically draws high-visibility dashed safety lines across the depth chart background to indicate **Warning (Yellow, e.g. 3.5m)** and **Danger (Red, e.g. 2.5m)** thresholds.
27
+ * **Non-Scaling Vector Effects:** By using `vector-effect="non-scaling-stroke"`, these lines and the active depth curve remain perfectly sharp, thin, and professional regardless of whether the widget is small or zoomed to full screen.
28
+ * **Adaptive 0-Baseline:** In shallow water, the chart minimum is locked to 0 for keel safety; in deep water, the scale floats freely (e.g., 98m to 102m) to reveal the fine contour details of the seabed.
29
+
30
+ ### 🔌 Smart Source Locking (Zero-Config)
31
+ An intelligent background algorithm assigns priority scores to active hardware sources on your boat (e.g. Yacht Devices N2K GPS vs a generic USB GPS) and locks onto the highest-quality sensor, switching to a backup only if a signal dropout occurs.
32
+
33
+ ### ⏰ Sleep & Power-Save Watchdog
34
+ Detects when the tablet is unlocked or the browser wakes up a tab from *Power Save* mode, automatically closing orphaned WebSockets, reconnecting, and downloading the latest server-logged history in milliseconds to resume fluid, gap-free operation.
35
+
36
+ ### 🎮 Smart Local Development Auto-Detection
37
+ The dashboard automatically detects if it is running locally on your Mac/PC via the `file://` protocol or on `localhost`. In this mode, it still connects to your boat's Cerbo GX over Wi-Fi to stream real-time data, but **bypasses the server's configuration, preserving your local `CONFIG` edits** so you can test scales, alarms, and steps instantly.
38
+
39
+ ---
40
+
41
+ ## System Requirements
42
+
43
+ * **Server:** Signal K Node Server (v1.20.0 or higher) installed on a Victron Cerbo GX, Raspberry Pi, or onboard PC.
44
+ * **Client:** Any modern PWA-compliant browser supporting ES6 (Safari on iPadOS/iOS, Samsung Internet, Chrome on Android, Chrome/Safari on macOS/Windows).
45
+
46
+ ---
47
+
48
+ ## Signal K Data Requirements
49
+
50
+ ### Required Foundational Paths
51
+ To derive, calculate, and display the entire suite of tactical data, the dashboard must receive the following raw paths from your boat's NMEA network:
52
+
53
+ * `navigation.speedThroughWater` (STW - Speed through water)
54
+ * `navigation.speedOverGround` (SOG - Speed over ground)
55
+ * `navigation.courseOverGroundTrue` (COG - Course over ground)
56
+ * `navigation.headingTrue` (True Heading - *If missing, the system automatically falls back to Magnetic Heading*)
57
+ * `environment.wind.speedApparent` (AWS - Apparent wind speed)
58
+ * `environment.wind.angleApparent` (AWA - Apparent wind angle)
59
+ * `environment.depth.belowTransducer` (Depth below keel/transducer)
60
+ * `navigation.position` (GPS Latitude and Longitude - used for hemisphere detection and CSV logging)
61
+
62
+ ### Optional / Native Fallback Paths (Surgically Supported)
63
+ The dashboard operates on a **"Native First, Fallback Second"** architecture. If any of the following calculated paths are transmitted natively by your boat's instruments, the dashboard will utilize them directly to preserve their calibration. If they are missing, the system silently activates its own local vector formulas:
64
+
65
+ * `environment.wind.speedTrue` (**Optional** - Native True Wind Speed in m/s; falls back to local calculation if missing)
66
+ * `environment.wind.directionTrue` (**Optional** - Native True Wind Direction in radians; falls back to local calculation if missing)
67
+ * `navigation.headingMagnetic` (**Optional** - Magnetic Heading; automatically used if True Heading is missing on the network)
68
+ * `navigation.magneticVariation` (**Optional** - Magnetic Variation; used to calibrate the Magnetic Heading fallback to True)
69
+
70
+ ---
71
+
72
+ ## Installation
73
+
74
+ The dashboard is distributed as a standard Signal K Node Server plugin and Web App.
75
+
76
+ ### Installation via Signal K App Store (Recommended)
77
+ 1. Access your Signal K admin panel (`http://<boat-ip>:3000`).
78
+ 2. Navigate to **App Store** -> **Available**.
79
+ 3. Search for `@sailingrotevista/rotevista-dash` and click **Install**.
80
+ 4. Go to **Plugins Config**, activate the **Rotevista Dash Configuration** plugin, and configure your boat's safety thresholds (Draft, alarm offsets, and strategic chart timelines).
81
+ 5. Click **Save**. The Signal K server will restart, apply the configurations, and initiate background history logging in RAM.
82
+
83
+ ### Accessing the Dashboard
84
+ Once installed, the dashboard is accessible on your local network by typing into your tablet or computer browser:
85
+ ```text
86
+ http://<boat-ip>:3000/@sailingrotevista/rotevista-dash/
87
+ For the best experience in the cockpit, tap your browser's share button and select "Add to Home Screen" to run it as a standalone, distraction-free application.
88
+
89
+ License
90
+ This project is licensed under the MIT License - see the LICENSE file for details.
package/app.js CHANGED
@@ -79,7 +79,7 @@ const store = {
79
79
  herculesScales: {}, // Memoria per i limiti attivi della modalità Hercules
80
80
  smoothBuf: { hdg: [], cog: [], awa: [], twa: [], twd: [] },
81
81
  longBuf: { hdg: [], cog: [], awa: [], twa: [], twd: [] },
82
- histories: { stw: [], sog: [], depth: [], tws: [], vmg: [], aws: [] },
82
+ histories: { stw: [], sog: [], depth: [], tws: [], vmg: [], aws: [], twd: [] },
83
83
  graphTempBuf: { stw: [], sog: [], depth: [], tws: [], vmg: [], aws: [] },
84
84
  lastUpdates: { stw: 0, sog: 0, depth: 0, tws: 0, vmg: 0, aws: 0 }
85
85
  };
@@ -121,8 +121,12 @@ function getShortestRotation(curr, target) {
121
121
  */
122
122
  function safeSetText(el, text) {
123
123
  if (!el) return;
124
- if (el.innerHTML !== text) {
125
- el.innerHTML = text;
124
+ // Se l'elemento è parte di un SVG, usiamo textContent, altrimenti innerHTML
125
+ const isSVG = el instanceof SVGElement;
126
+ if (isSVG) {
127
+ if (el.textContent !== text) el.textContent = text;
128
+ } else {
129
+ if (el.innerHTML !== text) el.innerHTML = text;
126
130
  }
127
131
  }
128
132
 
@@ -182,7 +186,8 @@ function getCircularAverageFromBuffer(bufferArray, windowMs, signed = false, now
182
186
  const clampedDiff = Math.sign(diffRad) * limitRad;
183
187
  const clampedRad = pilotRad + clampedDiff;
184
188
  finalSin = Math.sin(clampedRad);
185
- finalCos = Math.cos(clampedRad);
189
+ const relativeCos = Math.cos(clampedRad);
190
+ finalCos = relativeCos;
186
191
  } else {
187
192
  finalSin = item.sin;
188
193
  finalCos = item.cos;
@@ -343,13 +348,14 @@ function computeTrueWind() {
343
348
  // Altrimenti eseguiamo il calcolo vettoriale tattico sull'acqua
344
349
  tws_water = Math.sqrt(aws * aws + stw * stw - 2 * aws * stw * Math.cos(awa));
345
350
  store.raw["environment.wind.speedTrue"] = tws_water;
346
-
347
- if (tws_water > 0.05) {
348
- const twa = Math.atan2(aws * Math.sin(awa), aws * Math.cos(awa) - stw);
349
- store.raw["environment.wind.angleTrueWater"] = twa;
350
- safePush(store.smoothBuf.twa, twa, now);
351
- safePush(store.longBuf.twa, twa, now);
352
- }
351
+ }
352
+
353
+ // BUG RISOLTO: Calcoliamo il TWA sempre, indipendentemente dal TWS nativo!
354
+ if (tws_water > 0.05) {
355
+ const twa = Math.atan2(aws * Math.sin(awa), aws * Math.cos(awa) - stw);
356
+ store.raw["environment.wind.angleTrueWater"] = twa;
357
+ safePush(store.smoothBuf.twa, twa, now);
358
+ safePush(store.longBuf.twa, twa, now);
353
359
  }
354
360
 
355
361
  // ==========================================================================
@@ -441,10 +447,39 @@ function processIncomingData(path, val, source, timeMs) {
441
447
  safePush(store.smoothBuf.awa, val, now);
442
448
  safePush(store.longBuf.awa, val, now);
443
449
  }
450
+
451
+ // BUG RISOLTO: Intercetta il TWD nativo e lo spinge nei buffer della bussola radar
452
+ if (path === "environment.wind.directionTrue") {
453
+ let directionVal = (val && typeof val === 'object' && val.val !== undefined) ? val.val : val;
454
+ safePush(store.smoothBuf.twd, directionVal, now);
455
+ safePush(store.longBuf.twd, directionVal, now);
456
+ }
457
+
458
+ // BUG RISOLTO: Intercetta il TWS nativo e lo memorizza in tempo reale
459
+ if (path === "environment.wind.speedTrue") {
460
+ let speedVal = (val && typeof val === 'object' && val.val !== undefined) ? val.val : val;
461
+ store.raw["environment.wind.speedTrue"] = speedVal;
462
+ }
463
+
464
+ // --- GESTIONE PRUA VERA / MAGNETICA CON AUTODIVIAZIONE ---
444
465
  if (path === "navigation.headingTrue") {
445
466
  safePush(store.smoothBuf.hdg, val, now);
446
467
  safePush(store.longBuf.hdg, val, now);
447
468
  }
469
+ else if (path === "navigation.headingMagnetic") {
470
+ // Se non abbiamo ricevuto una prua vera negli ultimi 5 secondi, convertiamo quella magnetica!
471
+ const hasTrueHdg = store.timestamps["navigation.headingTrue"] && (now - store.timestamps["navigation.headingTrue"] < 5000);
472
+ if (!hasTrueHdg) {
473
+ const variation = store.raw["navigation.magneticVariation"] || 0; // Legge la declinazione magnetica del GPS
474
+ const calculatedTrueHdg = (val + variation + 2 * Math.PI) % (2 * Math.PI);
475
+
476
+ // Registriamo il valore calcolato come Prua Vera temporanea
477
+ store.raw["navigation.headingTrue"] = calculatedTrueHdg;
478
+ safePush(store.smoothBuf.hdg, calculatedTrueHdg, now);
479
+ safePush(store.longBuf.hdg, calculatedTrueHdg, now);
480
+ }
481
+ }
482
+
448
483
  if (path === "navigation.courseOverGroundTrue") {
449
484
  safePush(store.smoothBuf.cog, val, now);
450
485
  safePush(store.longBuf.cog, val, now);
@@ -697,7 +732,7 @@ function startDisplayLoop() {
697
732
  else if (drift > 0.3) ui.sog.style.setProperty('color', '#00C851', 'important'); // Favore
698
733
  else ui.sog.style.setProperty('color', '#ffbb33', 'important'); // Neutro SOG
699
734
  } else {
700
- ui.sog.style.color = "";
735
+ ui.sog.style.removeProperty('color');
701
736
  }
702
737
  }
703
738
  }
@@ -1258,7 +1293,7 @@ function drawGraph(d, id, min, max, isTws, isHercules) {
1258
1293
  if (visibleData.length < 2) return;
1259
1294
 
1260
1295
  const colDanger = "#ff3b30", colWarning = "#ff9800", colTws = "#2c3e50", colAws = "#5c6bc0";
1261
- const colDepth = "#0088cc", colStw = "#00C851", colSog = "#ffbb33", colVmg = "#00b8d4";
1296
+ const colDepth = "#0088cc", colStw = "#00C851", colStwBorder = "#007a3d", colSog = "#ffbb33", colVmg = "#00b8d4";
1262
1297
 
1263
1298
  const getColorProps = (val) => {
1264
1299
  // Se siamo in Dual Screen (focus), aumentiamo lo spessore base della curva di un filino (da 1.6 a 2.2)
@@ -1573,6 +1608,27 @@ async function init() {
1573
1608
  }
1574
1609
  }
1575
1610
 
1611
+ // Watchdog per il risveglio dallo stato di sospensione / cambio scheda
1612
+ document.addEventListener('visibilitychange', () => {
1613
+ if (document.visibilityState === 'visible') {
1614
+ console.log("🔌 [Watchdog] Tab ritornato visibile. Verifica connessione...");
1615
+
1616
+ // Se il socket esiste ma non è attivo o se vogliamo forzare la pulizia delle connessioni fantasma:
1617
+ if (socket) {
1618
+ if (socket.readyState !== WebSocket.OPEN) {
1619
+ // Se era già chiuso o in errore, proviamo a riconnettere subito
1620
+ connect();
1621
+ } else {
1622
+ // Se risulta "OPEN" ma potrebbe essere una connessione fantasma,
1623
+ // la chiudiamo forzatamente per scatenare la riconnessione pulita e il download della cronologia
1624
+ console.log("🔌 [Watchdog] Riavvio precauzionale del WebSocket per evitare connessioni fantasma.");
1625
+ socket.close();
1626
+ }
1627
+ } else {
1628
+ connect();
1629
+ }
1630
+ }
1631
+ });
1576
1632
 
1577
1633
  window.addEventListener('load', init);
1578
1634
  window.addEventListener('pagehide', saveDashboardState);
package/index.html CHANGED
@@ -12,7 +12,6 @@
12
12
 
13
13
  <!-- Icona per Bookmark e schermata Home su Apple iPad, iPhone e Mac -->
14
14
  <link rel="apple-touch-icon" href="icons/dash.png">
15
-
16
15
  <title>Sailing Dashboard Pro</title>
17
16
  <link rel="stylesheet" href="style.css">
18
17
  </head>