This commit is contained in:
anto
2025-01-08 15:27:41 +01:00
parent faf5264015
commit e60f704518
2 changed files with 51 additions and 27 deletions

View File

@@ -34,16 +34,13 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<table class="table table-striped" id="table-metrics"> <select name="metriques" id="metric_selector">
<thead> <option value="hygrometry">hygrométrie</option>
<tr> <option value="temperature">Température</option>
<th>date</th> </select>
<th>Hygrométrie</th> <div id="metric_viewer_placeholder">
<th>température</th> <canvas id="metric_viewer"></canvas>
</tr> </div>
</thead>
<tbody></tbody>
</table>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div id="content1" class="hiddenTable"> <div id="content1" class="hiddenTable">
@@ -79,6 +76,7 @@
<footer> <footer>
<p>&copy; 2024 Timelapse. All rights reserved.</p> <p>&copy; 2024 Timelapse. All rights reserved.</p>
</footer> </footer>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="../js/globals.js"></script> <script src="../js/globals.js"></script>
<script src="../js/projet_detail.js"></script> <script src="../js/projet_detail.js"></script>

View File

@@ -1,18 +1,7 @@
function display_metrics(metrics_datas) { let myChart; // Declare a global variable to hold the chart instance
// Get data from API and then generate HTML code to display the data in a table
const table = document.getElementById("table-metrics"); function display_metrics() {
let datas = ` // Implementation for display_metrics function
<tr><th>Date</th> <th>Température</th> <th>Hygrométrie</th>
</tr>`;
for (let i = 0; i < metrics_datas.length; i++) {
datas += `
<tr>
<th>${formatDate(metrics_datas[i].date_metrique)}</th>
<th>${metrics_datas[i].temperature}</th>
<th>${metrics_datas[i].hygrometrie}</th>
</tr>`;
}
table.innerHTML = datas;
} }
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
@@ -33,6 +22,12 @@ document.addEventListener("DOMContentLoaded", () => {
document.getElementById("name_project").innerHTML = document.getElementById("name_project").innerHTML =
global_project_list[projectId - 1].titre; global_project_list[projectId - 1].titre;
generateViewMetric();
document.getElementById("metric_selector").addEventListener("change", () => {
generateViewMetric();
});
fetch("https://timelapse.kerboul.me/api/smile") fetch("https://timelapse.kerboul.me/api/smile")
.then((response) => response.blob()) .then((response) => response.blob())
.then((blob) => { .then((blob) => {
@@ -63,11 +58,42 @@ document.addEventListener("DOMContentLoaded", () => {
if (tableImage.classList.contains("hiddenTable")) { if (tableImage.classList.contains("hiddenTable")) {
tableImage.classList.remove("hiddenTable"); tableImage.classList.remove("hiddenTable");
tableImage.classList.add("full-view"); tableImage.classList.add("full-view");
document.getElementById("toggle-view").innerHTML="See first images" document.getElementById("toggle-view").innerHTML = "See first images";
} else { } else {
tableImage.classList.remove("full-view"); tableImage.classList.remove("full-view");
tableImage.classList.add("hiddenTable"); tableImage.classList.add("hiddenTable");
document.getElementById("toggle-view").innerHTML="See all images" document.getElementById("toggle-view").innerHTML = "See all images";
} }
}); });
}); });
function generateViewMetric() {
const ctx = document.getElementById("metric_viewer").getContext("2d");
// Destroy the existing chart instance if it exists
if (myChart) {
myChart.destroy();
}
// Create a new chart instance
myChart = new Chart(ctx, {
type: "bar",
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [
{
label: "# of Votes",
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1,
},
],
},
options: {
scales: {
y: {
beginAtZero: true,
},
},
},
});
}