@sailingrotevista/rotevista-dash 4.0.7 → 4.0.8

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 (2) hide show
  1. package/app.js +36 -19
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -559,34 +559,32 @@ function startDisplayLoop() {
559
559
  // ==========================================================================
560
560
  // 8. CONFIGURAZIONE E GRAFICI UTILS
561
561
  // ==========================================================================
562
+
562
563
  /**
563
- * Recupera la configurazione provando i percorsi standard e quelli "scoped".
564
- * Gestisce il parsing dei numeri e la mappatura dei grafici.
564
+ * Recupera la configurazione dal server Signal K.
565
+ * Prova i percorsi API ufficiali e quelli scoped (@sailingrotevista).
566
+ * Converte i testi in numeri per garantire la precisione dei calcoli.
565
567
  */
566
568
  async function fetchServerConfig() {
567
569
  if (!window.location.protocol.includes("http")) return;
568
570
 
569
- // Elenco di tutti i percorsi dove Signal K potrebbe aver salvato i settings
570
571
  const urls = [
571
- '/plugins/rotevista-dash/settings',
572
- '/plugins/@sailingrotevista%2frotevista-dash/settings',
573
- '/signalk/v1/api/plugins/rotevista-dash/settings',
574
- '/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash/settings',
575
- '/plugins/rotevista-dash/config' // Quello che ti ha dato 401
572
+ '/signalk/v1/api/plugins/rotevista-dash',
573
+ '/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash',
574
+ '/plugins/rotevista-dash/settings'
576
575
  ];
577
576
 
578
577
  for (let url of urls) {
579
578
  try {
580
579
  const response = await fetch(url);
581
-
582
580
  if (response.ok) {
583
581
  const data = await response.json();
584
582
 
585
- // Signal K può restituire i dati direttamente, in 'configuration' o in 'settings'
583
+ // Signal K può incapsulare i dati in settings o configuration
586
584
  const actual = data.settings || data.configuration || data.options || data;
587
585
 
588
586
  if (actual && (actual.alarms || actual.averaging || actual.graphs)) {
589
- // FUNZIONE DI PARSING: Trasforma i testi in numeri per i calcoli
587
+ // FUNZIONE DI PARSING: Trasforma eventuali testi "12.5" in numeri 12.5 reali
590
588
  const parseNumbers = (obj) => {
591
589
  for (let k in obj) {
592
590
  if (typeof obj[k] === 'object') parseNumbers(obj[k]);
@@ -597,7 +595,7 @@ async function fetchServerConfig() {
597
595
  };
598
596
  parseNumbers(actual);
599
597
 
600
- // APPLICAZIONE CONFIGURAZIONE (Ora include anche i grafici!)
598
+ // MAPPATURA INTEGRALE NEL CONFIG LOCALE
601
599
  if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
602
600
  if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
603
601
  if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
@@ -606,13 +604,14 @@ async function fetchServerConfig() {
606
604
  CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
607
605
  }
608
606
  }
609
- console.log("✅ CONFIGURAZIONE CARICATA DA:", url);
610
- return; // Abbiamo trovato i dati, usciamo dal loop
607
+ console.log("✅ Configurazione caricata correttamente da:", url);
608
+ return;
611
609
  }
612
610
  }
613
- } catch (e) { }
611
+ } catch (e) {
612
+ console.warn(`⚠️ Tentativo fallito su ${url}`);
613
+ }
614
614
  }
615
- console.warn("⚠️ Nessun dato di configurazione trovato nei percorsi standard. Uso i default.");
616
615
  }
617
616
 
618
617
  function manageHistory(t, v) {
@@ -637,12 +636,24 @@ function calculateScale(type, data, mode) {
637
636
  return { min: 0, max: Math.max(s.stdMax, Math.ceil(aMax / s.step) * s.step) };
638
637
  }
639
638
 
640
- function updateScaleLabels(t, min, max) { const el = document.getElementById(t + '-scale'); if (el) el.innerHTML = `<span>${Math.round(max)}</span><span>${Math.round((min+max)/2)}</span><span>${Math.round(min)}</span>`; }
639
+ function updateScaleLabels(t, min, max) {
640
+ const el = document.getElementById(t + '-scale');
641
+ if (el) el.innerHTML = `<span>${Math.round(max)}</span><span>${Math.round((min+max)/2)}</span><span>${Math.round(min)}</span>`;
642
+ }
641
643
 
644
+ /**
645
+ * drawGraph: Disegna i grafici con griglia temporale intelligente
646
+ */
642
647
  function drawGraph(d, id, min, max, isTws, isHercules) {
643
648
  const svg = document.getElementById(id); if (!svg || d.length < 2) return;
644
649
  const w = 200, h = 40, range = max - min || 1;
645
- let grids = ""; [0.25, 0.5, 0.75].forEach(p => { grids += `<line x1="0" y1="${h-(p*h)}" x2="${w}" y2="${h-(p*h)}" stroke="rgba(0,0,0,0.12)" stroke-width="0.5" />`; });
650
+
651
+ // Griglia orizzontale
652
+ let grids = "";
653
+ [0.25, 0.5, 0.75].forEach(p => {
654
+ grids += `<line x1="0" y1="${h-(p*h)}" x2="${w}" y2="${h-(p*h)}" stroke="rgba(0,0,0,0.12)" stroke-width="0.5" />`;
655
+ });
656
+
646
657
  /**
647
658
  * Griglia Temporale Intelligente:
648
659
  * - Storia <= 15 min: linee ogni 1 minuto.
@@ -654,18 +665,24 @@ function drawGraph(d, id, min, max, isTws, isHercules) {
654
665
  const x = w - (m / CONFIG.graphs.historyMinutes) * w;
655
666
  grids += `<line x1="${x}" y1="0" x2="${x}" y2="${h}" stroke="rgba(0,0,0,0.08)" stroke-width="0.5" />`;
656
667
  }
668
+
657
669
  let pD = ""; let cS = "";
658
670
  d.forEach((v, i) => {
659
671
  const x = (i/(CONFIG.graphs.samples-1))*w, y = h-(Math.max(0,Math.min(1,(v-min)/range))*h); pD += `${i===0?'M':'L'} ${x} ${y} `;
660
672
  if (isTws && i > 0) {
661
673
  const px = ((i-1)/(CONFIG.graphs.samples-1))*w, py = h-(Math.max(0,Math.min(1,(d[i-1]-min)/range))*h);
662
674
  let c = (v >= CONFIG.graphs.reef2) ? "#e74c3c" : (v >= CONFIG.graphs.reef1 ? "#e67e22" : "#000");
675
+ // Aggiunta della classe 'tws-reef-line' per la gestione Night Mode
663
676
  cS += `<line x1="${px}" y1="${py}" x2="${x}" y2="${y}" stroke="${c}" class="tws-reef-line ${isHercules?'line-hercules':''}" />`;
664
677
  }
665
678
  });
679
+
666
680
  const clrs = { 'stw-graph': '#2ecc71', 'sog-graph': '#f39c12', 'depth-graph': '#3498db', 'tws-graph': '#000' };
667
681
  const colorKey = id === 'sog-graph' && displayModeSog === 'VMG' ? '#16a085' : clrs[id];
668
- svg.innerHTML = isTws ? `${grids}<path d="${pD} L ${((d.length-1)/(CONFIG.graphs.samples-1))*w} ${h} L 0 ${h} Z" fill="rgba(0,0,0,0.05)" stroke="none" />${cS}` : `${grids}<path d="${pD} L ${((d.length-1)/(CONFIG.graphs.samples-1))*w} ${h} L 0 ${h} Z" fill="${colorKey}22" stroke="none" /><path d="${pD}" class="${isHercules?'line-hercules':''}" fill="none" stroke="${colorKey}" />`;
682
+
683
+ svg.innerHTML = isTws ?
684
+ `${grids}<path d="${pD} L ${((d.length-1)/(CONFIG.graphs.samples-1))*w} ${h} L 0 ${h} Z" fill="rgba(0,0,0,0.05)" stroke="none" />${cS}` :
685
+ `${grids}<path d="${pD} L ${((d.length-1)/(CONFIG.graphs.samples-1))*w} ${h} L 0 ${h} Z" fill="${colorKey}22" stroke="none" /><path d="${pD}" class="${isHercules?'line-hercules':''}" fill="none" stroke="${colorKey}" />`;
669
686
  }
670
687
 
671
688
  // ==========================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "4.0.7",
3
+ "version": "4.0.8",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {