@sailingrotevista/rotevista-dash 4.0.7 โ 4.0.9
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/app.js +135 -46
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -559,60 +559,131 @@ function startDisplayLoop() {
|
|
|
559
559
|
// ==========================================================================
|
|
560
560
|
// 8. CONFIGURAZIONE E GRAFICI UTILS
|
|
561
561
|
// ==========================================================================
|
|
562
|
+
|
|
562
563
|
/**
|
|
563
|
-
* Recupera la configurazione
|
|
564
|
-
*
|
|
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
|
-
if (!window.location.protocol.
|
|
568
|
-
|
|
569
|
-
|
|
569
|
+
if (!window.location.protocol.startsWith("http")) {
|
|
570
|
+
console.warn("Non in ambiente HTTP");
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
|
|
570
574
|
const urls = [
|
|
571
|
-
'/plugins/rotevista-dash/
|
|
572
|
-
'/plugins/@sailingrotevista%2frotevista-dash/
|
|
573
|
-
'/signalk/v1/api/plugins/rotevista-dash
|
|
574
|
-
'/
|
|
575
|
-
'/plugins/rotevista-dash/config' // Quello che ti ha dato 401
|
|
575
|
+
'/signalk/v1/api/plugins/rotevista-dash/config',
|
|
576
|
+
'/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash/config',
|
|
577
|
+
'/signalk/v1/api/plugins/rotevista-dash',
|
|
578
|
+
'/plugins/rotevista-dash/settings'
|
|
576
579
|
];
|
|
577
580
|
|
|
578
|
-
for (
|
|
581
|
+
for (const url of urls) {
|
|
579
582
|
try {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
583
|
+
console.log(`๐ Provo: ${url}`);
|
|
584
|
+
|
|
585
|
+
const response = await fetch(url, {
|
|
586
|
+
method: 'GET',
|
|
587
|
+
headers: {
|
|
588
|
+
'Accept': 'application/json'
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
console.log(`Status ${response.status}`);
|
|
593
|
+
|
|
594
|
+
if (!response.ok) continue;
|
|
595
|
+
|
|
596
|
+
const text = await response.text();
|
|
597
|
+
|
|
598
|
+
console.log("RAW RESPONSE:", text);
|
|
599
|
+
|
|
600
|
+
let data;
|
|
601
|
+
|
|
602
|
+
try {
|
|
603
|
+
data = JSON.parse(text);
|
|
604
|
+
} catch (e) {
|
|
605
|
+
console.warn("โ Non รจ JSON valido");
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
console.log("JSON:", data);
|
|
610
|
+
|
|
611
|
+
const actual =
|
|
612
|
+
data.settings ||
|
|
613
|
+
data.configuration ||
|
|
614
|
+
data.options ||
|
|
615
|
+
data;
|
|
616
|
+
|
|
617
|
+
if (!actual || typeof actual !== 'object') {
|
|
618
|
+
console.warn("โ Config non valida");
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const parseNumbers = (obj) => {
|
|
623
|
+
if (!obj || typeof obj !== 'object') return;
|
|
624
|
+
|
|
625
|
+
for (const k in obj) {
|
|
626
|
+
const v = obj[k];
|
|
627
|
+
|
|
628
|
+
if (v && typeof v === 'object') {
|
|
629
|
+
parseNumbers(v);
|
|
630
|
+
}
|
|
631
|
+
else if (
|
|
632
|
+
typeof v === 'string' &&
|
|
633
|
+
v.trim() !== '' &&
|
|
634
|
+
!isNaN(v)
|
|
635
|
+
) {
|
|
636
|
+
obj[k] = parseFloat(v);
|
|
608
637
|
}
|
|
609
|
-
console.log("โ
CONFIGURAZIONE CARICATA DA:", url);
|
|
610
|
-
return; // Abbiamo trovato i dati, usciamo dal loop
|
|
611
638
|
}
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
parseNumbers(actual);
|
|
642
|
+
|
|
643
|
+
console.log("CONFIG PARSATA:", actual);
|
|
644
|
+
|
|
645
|
+
if (actual.alarms) {
|
|
646
|
+
CONFIG.alarms = {
|
|
647
|
+
...CONFIG.alarms,
|
|
648
|
+
...actual.alarms
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (actual.graphs) {
|
|
653
|
+
CONFIG.graphs = {
|
|
654
|
+
...CONFIG.graphs,
|
|
655
|
+
...actual.graphs
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// ATTENZIONE:
|
|
660
|
+
// averaging -> averages
|
|
661
|
+
if (actual.averaging) {
|
|
662
|
+
CONFIG.averages = {
|
|
663
|
+
...CONFIG.averages,
|
|
664
|
+
...actual.averaging
|
|
665
|
+
};
|
|
612
666
|
}
|
|
613
|
-
|
|
667
|
+
|
|
668
|
+
if (actual.scales) {
|
|
669
|
+
for (const k in actual.scales) {
|
|
670
|
+
CONFIG.scales[k] = {
|
|
671
|
+
...CONFIG.scales[k],
|
|
672
|
+
...actual.scales[k]
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
console.log(`โ
Config caricata da ${url}`);
|
|
678
|
+
|
|
679
|
+
return actual;
|
|
680
|
+
|
|
681
|
+
} catch (e) {
|
|
682
|
+
console.error(`โ Errore su ${url}`, e);
|
|
683
|
+
}
|
|
614
684
|
}
|
|
615
|
-
|
|
685
|
+
|
|
686
|
+
console.error("โ Nessuna configurazione trovata");
|
|
616
687
|
}
|
|
617
688
|
|
|
618
689
|
function manageHistory(t, v) {
|
|
@@ -637,12 +708,24 @@ function calculateScale(type, data, mode) {
|
|
|
637
708
|
return { min: 0, max: Math.max(s.stdMax, Math.ceil(aMax / s.step) * s.step) };
|
|
638
709
|
}
|
|
639
710
|
|
|
640
|
-
function updateScaleLabels(t, min, max) {
|
|
711
|
+
function updateScaleLabels(t, min, max) {
|
|
712
|
+
const el = document.getElementById(t + '-scale');
|
|
713
|
+
if (el) el.innerHTML = `<span>${Math.round(max)}</span><span>${Math.round((min+max)/2)}</span><span>${Math.round(min)}</span>`;
|
|
714
|
+
}
|
|
641
715
|
|
|
716
|
+
/**
|
|
717
|
+
* drawGraph: Disegna i grafici con griglia temporale intelligente
|
|
718
|
+
*/
|
|
642
719
|
function drawGraph(d, id, min, max, isTws, isHercules) {
|
|
643
720
|
const svg = document.getElementById(id); if (!svg || d.length < 2) return;
|
|
644
721
|
const w = 200, h = 40, range = max - min || 1;
|
|
645
|
-
|
|
722
|
+
|
|
723
|
+
// Griglia orizzontale
|
|
724
|
+
let grids = "";
|
|
725
|
+
[0.25, 0.5, 0.75].forEach(p => {
|
|
726
|
+
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" />`;
|
|
727
|
+
});
|
|
728
|
+
|
|
646
729
|
/**
|
|
647
730
|
* Griglia Temporale Intelligente:
|
|
648
731
|
* - Storia <= 15 min: linee ogni 1 minuto.
|
|
@@ -654,18 +737,24 @@ function drawGraph(d, id, min, max, isTws, isHercules) {
|
|
|
654
737
|
const x = w - (m / CONFIG.graphs.historyMinutes) * w;
|
|
655
738
|
grids += `<line x1="${x}" y1="0" x2="${x}" y2="${h}" stroke="rgba(0,0,0,0.08)" stroke-width="0.5" />`;
|
|
656
739
|
}
|
|
740
|
+
|
|
657
741
|
let pD = ""; let cS = "";
|
|
658
742
|
d.forEach((v, i) => {
|
|
659
743
|
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
744
|
if (isTws && i > 0) {
|
|
661
745
|
const px = ((i-1)/(CONFIG.graphs.samples-1))*w, py = h-(Math.max(0,Math.min(1,(d[i-1]-min)/range))*h);
|
|
662
746
|
let c = (v >= CONFIG.graphs.reef2) ? "#e74c3c" : (v >= CONFIG.graphs.reef1 ? "#e67e22" : "#000");
|
|
747
|
+
// Aggiunta della classe 'tws-reef-line' per la gestione Night Mode
|
|
663
748
|
cS += `<line x1="${px}" y1="${py}" x2="${x}" y2="${y}" stroke="${c}" class="tws-reef-line ${isHercules?'line-hercules':''}" />`;
|
|
664
749
|
}
|
|
665
750
|
});
|
|
751
|
+
|
|
666
752
|
const clrs = { 'stw-graph': '#2ecc71', 'sog-graph': '#f39c12', 'depth-graph': '#3498db', 'tws-graph': '#000' };
|
|
667
753
|
const colorKey = id === 'sog-graph' && displayModeSog === 'VMG' ? '#16a085' : clrs[id];
|
|
668
|
-
|
|
754
|
+
|
|
755
|
+
svg.innerHTML = isTws ?
|
|
756
|
+
`${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}` :
|
|
757
|
+
`${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
758
|
}
|
|
670
759
|
|
|
671
760
|
// ==========================================================================
|