@sailingrotevista/rotevista-dash 4.0.6 → 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 -24
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -559,37 +559,32 @@ function startDisplayLoop() {
559
559
  // ==========================================================================
560
560
  // 8. CONFIGURAZIONE E GRAFICI UTILS
561
561
  // ==========================================================================
562
+
562
563
  /**
563
- * Recupera la configurazione tramite le API ufficiali di Signal K.
564
- * Sovrascrive i default locali con i parametri impostati nel server.
565
- */
566
- /**
567
- * Recupera la configurazione dal server Signal K provando diversi percorsi.
568
- * Gestisce i permessi e converte i dati in formato numerico.
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.
569
567
  */
570
568
  async function fetchServerConfig() {
571
569
  if (!window.location.protocol.includes("http")) return;
572
-
573
- // Elenco percorsi dal più probabile (WebApp Data) al più tecnico (Plugin API)
570
+
574
571
  const urls = [
575
- '/signalk/v1/applicationData/user/rotevista-dash/1.0/settings',
576
572
  '/signalk/v1/api/plugins/rotevista-dash',
577
- '/plugins/rotevista-dash/config'
573
+ '/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash',
574
+ '/plugins/rotevista-dash/settings'
578
575
  ];
579
576
 
580
577
  for (let url of urls) {
581
578
  try {
582
- console.log(`Tentativo di caricamento configurazione da: ${url}`);
583
579
  const response = await fetch(url);
584
-
585
580
  if (response.ok) {
586
581
  const data = await response.json();
587
582
 
588
- // Signal K può incapsulare i dati in 'settings', 'configuration' o 'value'
589
- const actual = data.settings || data.configuration || data.value || data;
590
-
583
+ // Signal K può incapsulare i dati in settings o configuration
584
+ const actual = data.settings || data.configuration || data.options || data;
585
+
591
586
  if (actual && (actual.alarms || actual.averaging || actual.graphs)) {
592
- // FUNZIONE DI PARSING: Garantisce che i valori siano numeri reali
587
+ // FUNZIONE DI PARSING: Trasforma eventuali testi "12.5" in numeri 12.5 reali
593
588
  const parseNumbers = (obj) => {
594
589
  for (let k in obj) {
595
590
  if (typeof obj[k] === 'object') parseNumbers(obj[k]);
@@ -600,7 +595,7 @@ async function fetchServerConfig() {
600
595
  };
601
596
  parseNumbers(actual);
602
597
 
603
- // APPLICAZIONE DEI PARAMETRI (Inclusi i grafici che prima mancavano)
598
+ // MAPPATURA INTEGRALE NEL CONFIG LOCALE
604
599
  if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
605
600
  if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
606
601
  if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
@@ -609,15 +604,14 @@ async function fetchServerConfig() {
609
604
  CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
610
605
  }
611
606
  }
612
- console.log("✅ Configurazione applicata con successo da:", url);
613
- return; // Uscita al primo successo
607
+ console.log("✅ Configurazione caricata correttamente da:", url);
608
+ return;
614
609
  }
615
610
  }
616
611
  } catch (e) {
617
- console.warn(`⚠️ Errore durante il fetch su ${url}:`, e.message);
612
+ console.warn(`⚠️ Tentativo fallito su ${url}`);
618
613
  }
619
614
  }
620
- console.warn("⚠️ Nessun percorso di configurazione valido trovato. Uso i default locali.");
621
615
  }
622
616
 
623
617
  function manageHistory(t, v) {
@@ -642,12 +636,24 @@ function calculateScale(type, data, mode) {
642
636
  return { min: 0, max: Math.max(s.stdMax, Math.ceil(aMax / s.step) * s.step) };
643
637
  }
644
638
 
645
- 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
+ }
646
643
 
644
+ /**
645
+ * drawGraph: Disegna i grafici con griglia temporale intelligente
646
+ */
647
647
  function drawGraph(d, id, min, max, isTws, isHercules) {
648
648
  const svg = document.getElementById(id); if (!svg || d.length < 2) return;
649
649
  const w = 200, h = 40, range = max - min || 1;
650
- 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
+
651
657
  /**
652
658
  * Griglia Temporale Intelligente:
653
659
  * - Storia <= 15 min: linee ogni 1 minuto.
@@ -659,18 +665,24 @@ function drawGraph(d, id, min, max, isTws, isHercules) {
659
665
  const x = w - (m / CONFIG.graphs.historyMinutes) * w;
660
666
  grids += `<line x1="${x}" y1="0" x2="${x}" y2="${h}" stroke="rgba(0,0,0,0.08)" stroke-width="0.5" />`;
661
667
  }
668
+
662
669
  let pD = ""; let cS = "";
663
670
  d.forEach((v, i) => {
664
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} `;
665
672
  if (isTws && i > 0) {
666
673
  const px = ((i-1)/(CONFIG.graphs.samples-1))*w, py = h-(Math.max(0,Math.min(1,(d[i-1]-min)/range))*h);
667
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
668
676
  cS += `<line x1="${px}" y1="${py}" x2="${x}" y2="${y}" stroke="${c}" class="tws-reef-line ${isHercules?'line-hercules':''}" />`;
669
677
  }
670
678
  });
679
+
671
680
  const clrs = { 'stw-graph': '#2ecc71', 'sog-graph': '#f39c12', 'depth-graph': '#3498db', 'tws-graph': '#000' };
672
681
  const colorKey = id === 'sog-graph' && displayModeSog === 'VMG' ? '#16a085' : clrs[id];
673
- 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}" />`;
674
686
  }
675
687
 
676
688
  // ==========================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {