myio-js-library 0.1.136 → 0.1.137
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/dist/index.cjs +121 -16
- package/dist/index.js +121 -16
- package/dist/myio-js-library.umd.js +121 -16
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
|
@@ -6983,8 +6983,8 @@ ${rangeText}`;
|
|
|
6983
6983
|
total_current: { label: "Corrente Total", unit: "A", icon: "\u{1F50C}", decimals: 2 },
|
|
6984
6984
|
current: { label: "Corrente", unit: "A", icon: "\u{1F50C}", decimals: 2 },
|
|
6985
6985
|
// Power and Energy
|
|
6986
|
-
consumption: { label: "
|
|
6987
|
-
power: { label: "Pot\xEAncia", unit: "
|
|
6986
|
+
consumption: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
|
|
6987
|
+
power: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
|
|
6988
6988
|
energy: { label: "Energia", unit: "kWh", icon: "\u{1F4CA}", decimals: 1 },
|
|
6989
6989
|
activePower: { label: "Pot\xEAncia Ativa", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
|
|
6990
6990
|
reactivePower: { label: "Pot\xEAncia Reativa", unit: "kVAr", icon: "\u{1F504}", decimals: 2 },
|
|
@@ -7040,7 +7040,9 @@ ${rangeText}`;
|
|
|
7040
7040
|
let refreshIntervalId = null;
|
|
7041
7041
|
let isPaused = false;
|
|
7042
7042
|
let telemetryHistory = /* @__PURE__ */ new Map();
|
|
7043
|
+
let lastKnownValues = /* @__PURE__ */ new Map();
|
|
7043
7044
|
let chart = null;
|
|
7045
|
+
let selectedChartKey = "consumption";
|
|
7044
7046
|
const overlay = document.createElement("div");
|
|
7045
7047
|
overlay.className = "myio-realtime-telemetry-overlay";
|
|
7046
7048
|
overlay.innerHTML = `
|
|
@@ -7201,7 +7203,27 @@ ${rangeText}`;
|
|
|
7201
7203
|
}
|
|
7202
7204
|
|
|
7203
7205
|
.myio-telemetry-chart {
|
|
7204
|
-
height:
|
|
7206
|
+
height: 250px;
|
|
7207
|
+
}
|
|
7208
|
+
|
|
7209
|
+
.myio-telemetry-selector {
|
|
7210
|
+
padding: 8px 12px;
|
|
7211
|
+
border: 1px solid #ddd;
|
|
7212
|
+
border-radius: 6px;
|
|
7213
|
+
font-size: 14px;
|
|
7214
|
+
background: white;
|
|
7215
|
+
cursor: pointer;
|
|
7216
|
+
transition: border-color 0.2s;
|
|
7217
|
+
}
|
|
7218
|
+
|
|
7219
|
+
.myio-telemetry-selector:hover {
|
|
7220
|
+
border-color: #667eea;
|
|
7221
|
+
}
|
|
7222
|
+
|
|
7223
|
+
.myio-telemetry-selector:focus {
|
|
7224
|
+
outline: none;
|
|
7225
|
+
border-color: #667eea;
|
|
7226
|
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
7205
7227
|
}
|
|
7206
7228
|
|
|
7207
7229
|
.myio-realtime-telemetry-footer {
|
|
@@ -7311,7 +7333,16 @@ ${rangeText}`;
|
|
|
7311
7333
|
<div class="myio-telemetry-cards-grid" id="telemetry-cards"></div>
|
|
7312
7334
|
|
|
7313
7335
|
<div class="myio-telemetry-chart-container" id="chart-container" style="display: none;">
|
|
7314
|
-
<
|
|
7336
|
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
|
|
7337
|
+
<h3 class="myio-telemetry-chart-title" id="chart-title" style="margin: 0;">Hist\xF3rico de Telemetria</h3>
|
|
7338
|
+
<select id="chart-key-selector" class="myio-telemetry-selector">
|
|
7339
|
+
<option value="consumption">Pot\xEAncia</option>
|
|
7340
|
+
<option value="total_current">Corrente Total</option>
|
|
7341
|
+
<option value="voltage_a">Tens\xE3o Fase A</option>
|
|
7342
|
+
<option value="voltage_b">Tens\xE3o Fase B</option>
|
|
7343
|
+
<option value="voltage_c">Tens\xE3o Fase C</option>
|
|
7344
|
+
</select>
|
|
7345
|
+
</div>
|
|
7315
7346
|
<canvas class="myio-telemetry-chart" id="telemetry-chart"></canvas>
|
|
7316
7347
|
</div>
|
|
7317
7348
|
</div>
|
|
@@ -7353,6 +7384,7 @@ ${rangeText}`;
|
|
|
7353
7384
|
const telemetryCards = document.getElementById("telemetry-cards");
|
|
7354
7385
|
const chartContainer = document.getElementById("chart-container");
|
|
7355
7386
|
const chartCanvas = document.getElementById("telemetry-chart");
|
|
7387
|
+
const chartKeySelector = document.getElementById("chart-key-selector");
|
|
7356
7388
|
const statusIndicator = document.getElementById("status-indicator");
|
|
7357
7389
|
const statusText = document.getElementById("status-text");
|
|
7358
7390
|
const lastUpdateText = document.getElementById("last-update-text");
|
|
@@ -7444,16 +7476,42 @@ ${rangeText}`;
|
|
|
7444
7476
|
}
|
|
7445
7477
|
const history = telemetryHistory.get(tel.key);
|
|
7446
7478
|
history.push({ x: now, y: tel.value });
|
|
7479
|
+
lastKnownValues.set(tel.key, tel.value);
|
|
7447
7480
|
if (history.length > historyPoints) {
|
|
7448
7481
|
history.shift();
|
|
7449
7482
|
}
|
|
7450
7483
|
}
|
|
7451
|
-
|
|
7452
|
-
const
|
|
7453
|
-
|
|
7484
|
+
for (const key of telemetryKeys) {
|
|
7485
|
+
const receivedKeys = values.map((v) => v.key);
|
|
7486
|
+
if (!receivedKeys.includes(key) && lastKnownValues.has(key)) {
|
|
7487
|
+
if (!telemetryHistory.has(key)) {
|
|
7488
|
+
telemetryHistory.set(key, []);
|
|
7489
|
+
}
|
|
7490
|
+
const history = telemetryHistory.get(key);
|
|
7491
|
+
const lastValue = lastKnownValues.get(key);
|
|
7492
|
+
history.push({ x: now, y: lastValue });
|
|
7493
|
+
if (history.length > historyPoints) {
|
|
7494
|
+
history.shift();
|
|
7495
|
+
}
|
|
7496
|
+
}
|
|
7497
|
+
}
|
|
7498
|
+
if (telemetryHistory.has(selectedChartKey) && chart) {
|
|
7499
|
+
const selectedHistory = telemetryHistory.get(selectedChartKey);
|
|
7500
|
+
chart.data.datasets[0].data = selectedHistory;
|
|
7454
7501
|
chart.update("none");
|
|
7455
7502
|
}
|
|
7456
7503
|
}
|
|
7504
|
+
function getFormattedValue(key, value) {
|
|
7505
|
+
const config = TELEMETRY_CONFIG[key];
|
|
7506
|
+
if (!config) return value.toFixed(2);
|
|
7507
|
+
if (key === "consumption" || key === "power") {
|
|
7508
|
+
if (value >= 1e3) {
|
|
7509
|
+
return `${(value / 1e3).toFixed(2)} kW`;
|
|
7510
|
+
}
|
|
7511
|
+
return `${value.toFixed(0)} W`;
|
|
7512
|
+
}
|
|
7513
|
+
return `${value.toFixed(config.decimals)} ${config.unit}`;
|
|
7514
|
+
}
|
|
7457
7515
|
function initializeChart() {
|
|
7458
7516
|
const Chart = window.Chart;
|
|
7459
7517
|
if (!Chart) {
|
|
@@ -7461,23 +7519,26 @@ ${rangeText}`;
|
|
|
7461
7519
|
return;
|
|
7462
7520
|
}
|
|
7463
7521
|
chartContainer.style.display = "block";
|
|
7522
|
+
const config = TELEMETRY_CONFIG[selectedChartKey] || { label: selectedChartKey, unit: "" };
|
|
7464
7523
|
chart = new Chart(chartCanvas, {
|
|
7465
7524
|
type: "line",
|
|
7466
7525
|
data: {
|
|
7467
7526
|
datasets: [{
|
|
7468
|
-
label:
|
|
7527
|
+
label: config.label,
|
|
7469
7528
|
data: [],
|
|
7470
7529
|
borderColor: "#667eea",
|
|
7471
7530
|
backgroundColor: "rgba(102, 126, 234, 0.1)",
|
|
7472
7531
|
borderWidth: 2,
|
|
7473
7532
|
fill: true,
|
|
7474
7533
|
tension: 0.4,
|
|
7475
|
-
pointRadius:
|
|
7534
|
+
pointRadius: 3,
|
|
7535
|
+
pointHoverRadius: 5
|
|
7476
7536
|
}]
|
|
7477
7537
|
},
|
|
7478
7538
|
options: {
|
|
7479
7539
|
responsive: true,
|
|
7480
7540
|
maintainAspectRatio: false,
|
|
7541
|
+
animation: false,
|
|
7481
7542
|
plugins: {
|
|
7482
7543
|
legend: { display: false },
|
|
7483
7544
|
tooltip: {
|
|
@@ -7485,10 +7546,18 @@ ${rangeText}`;
|
|
|
7485
7546
|
title: function(context) {
|
|
7486
7547
|
const timestamp = context[0].parsed.x;
|
|
7487
7548
|
const date = new Date(timestamp);
|
|
7488
|
-
return date.
|
|
7549
|
+
return date.toLocaleString(locale, {
|
|
7550
|
+
day: "2-digit",
|
|
7551
|
+
month: "2-digit",
|
|
7552
|
+
year: "numeric",
|
|
7553
|
+
hour: "2-digit",
|
|
7554
|
+
minute: "2-digit",
|
|
7555
|
+
second: "2-digit"
|
|
7556
|
+
});
|
|
7489
7557
|
},
|
|
7490
7558
|
label: function(context) {
|
|
7491
|
-
|
|
7559
|
+
const value = context.parsed.y;
|
|
7560
|
+
return getFormattedValue(selectedChartKey, value);
|
|
7492
7561
|
}
|
|
7493
7562
|
}
|
|
7494
7563
|
}
|
|
@@ -7497,23 +7566,57 @@ ${rangeText}`;
|
|
|
7497
7566
|
x: {
|
|
7498
7567
|
type: "linear",
|
|
7499
7568
|
ticks: {
|
|
7569
|
+
maxRotation: 45,
|
|
7570
|
+
minRotation: 0,
|
|
7500
7571
|
callback: function(value) {
|
|
7501
7572
|
const date = new Date(value);
|
|
7502
|
-
return date.toLocaleTimeString(locale, {
|
|
7573
|
+
return date.toLocaleTimeString(locale, {
|
|
7574
|
+
hour: "2-digit",
|
|
7575
|
+
minute: "2-digit",
|
|
7576
|
+
second: "2-digit"
|
|
7577
|
+
});
|
|
7503
7578
|
}
|
|
7579
|
+
},
|
|
7580
|
+
title: {
|
|
7581
|
+
display: true,
|
|
7582
|
+
text: "Hora"
|
|
7504
7583
|
}
|
|
7505
7584
|
},
|
|
7506
7585
|
y: {
|
|
7507
7586
|
beginAtZero: true,
|
|
7587
|
+
ticks: {
|
|
7588
|
+
callback: function(value) {
|
|
7589
|
+
if (selectedChartKey === "consumption" || selectedChartKey === "power") {
|
|
7590
|
+
if (value >= 1e3) {
|
|
7591
|
+
return `${(value / 1e3).toFixed(1)} kW`;
|
|
7592
|
+
}
|
|
7593
|
+
return `${value} W`;
|
|
7594
|
+
}
|
|
7595
|
+
return `${value} ${config.unit}`;
|
|
7596
|
+
}
|
|
7597
|
+
},
|
|
7508
7598
|
title: {
|
|
7509
7599
|
display: true,
|
|
7510
|
-
text: "
|
|
7600
|
+
text: selectedChartKey === "consumption" || selectedChartKey === "power" ? "W" : config.unit
|
|
7511
7601
|
}
|
|
7512
7602
|
}
|
|
7513
7603
|
}
|
|
7514
7604
|
}
|
|
7515
7605
|
});
|
|
7516
7606
|
}
|
|
7607
|
+
function updateChartKey(newKey) {
|
|
7608
|
+
selectedChartKey = newKey;
|
|
7609
|
+
if (chart) {
|
|
7610
|
+
chart.destroy();
|
|
7611
|
+
chart = null;
|
|
7612
|
+
}
|
|
7613
|
+
initializeChart();
|
|
7614
|
+
if (telemetryHistory.has(selectedChartKey)) {
|
|
7615
|
+
const selectedHistory = telemetryHistory.get(selectedChartKey);
|
|
7616
|
+
chart.data.datasets[0].data = selectedHistory;
|
|
7617
|
+
chart.update("none");
|
|
7618
|
+
}
|
|
7619
|
+
}
|
|
7517
7620
|
async function refreshData() {
|
|
7518
7621
|
try {
|
|
7519
7622
|
const data = await fetchLatestTelemetry();
|
|
@@ -7525,9 +7628,7 @@ ${rangeText}`;
|
|
|
7525
7628
|
if (loadingState.style.display !== "none") {
|
|
7526
7629
|
loadingState.style.display = "none";
|
|
7527
7630
|
telemetryContent.style.display = "block";
|
|
7528
|
-
|
|
7529
|
-
initializeChart();
|
|
7530
|
-
}
|
|
7631
|
+
initializeChart();
|
|
7531
7632
|
}
|
|
7532
7633
|
} catch (error) {
|
|
7533
7634
|
console.error("[RealTimeTelemetry] Error fetching data:", error);
|
|
@@ -7595,6 +7696,10 @@ ${rangeText}`;
|
|
|
7595
7696
|
closeBtn.addEventListener("click", closeModal);
|
|
7596
7697
|
pauseBtn.addEventListener("click", togglePause);
|
|
7597
7698
|
exportBtn.addEventListener("click", exportToCSV2);
|
|
7699
|
+
chartKeySelector.addEventListener("change", (e) => {
|
|
7700
|
+
const newKey = e.target.value;
|
|
7701
|
+
updateChartKey(newKey);
|
|
7702
|
+
});
|
|
7598
7703
|
overlay.addEventListener("click", (e) => {
|
|
7599
7704
|
if (e.target === overlay) {
|
|
7600
7705
|
closeModal();
|