send graph to display

This commit is contained in:
2025-07-13 14:03:49 -04:00
parent 9784ff4f26
commit 6d0d27511f

View File

@@ -7,18 +7,19 @@ let targets: number[] = [];
let currentTargetIndex = 0;
let interval: NodeJS.Timeout | null = null;
interface Window {
startTimer?: Function; // function to start the timer
stopTimer?: Function; // function to stop the timer
logEvent?: Function; // function to log a new event
resetSystem?: Function; // function to reset all actions in the system
setPlan?: Function; // function to update the temp event plan
navigateTemp?: Function; //function to navigate forward/back between events in the setPlan() temp plan
logTemp?: Function; //function to log a temputure event
exportCSV?: Function; //function to export the events to CSV
showGraph?: Function; // function to render or display graphs using libraries like Chart.js for visual representation of logged events
hideGraph?: Function; //function to hind the graph popup
declare global {
interface Window {
startTimer: () => void;
stopTimer: () => void;
logEvent: (eventName: string) => void;
resetSystem: () => void;
setPlan: () => void;
navigateTemp: (direction: number) => void;
logTemp: (temp: number) => void;
exportCSV: () => void;
showGraph: () => void;
hideGraph: () => void;
}
}
@@ -149,8 +150,26 @@ function updateLog(): void {
`).join("");
}
// src/roast.ts
/**
* Generates an array of CSV strings line by line from log data.
*/
function createCSVData(): string[] {
const header = "Time,Event,Temperature";
const logEntries = log.map(entry => `${entry.time},${entry.event}${entry.temp !== null ? `,${entry.temp}` : ''}`);
return [header].concat(logEntries);
}
/**
* Creates CSV format content as a single string from the array returned by createCSVData().
*/
function generateCSVContent(): string {
return createCSVData().join("\n");
}
function exportCSV(): void {
const csvContent = "Time,Event,Temperature\n" + log.map(entry => `${entry.time},${entry.event},${entry.temp !== null ? entry.temp : ''}`).join("\n");
const csvContent = generateCSVContent();
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
const link = document.createElement("a");
link.setAttribute("href", URL.createObjectURL(blob));
@@ -164,7 +183,7 @@ function exportCSV(): void {
function showGraph(): void {
const graphContainer = document.getElementById("graph-container");
if (graphContainer) {
loadGraph(null);
loadGraph(createCSVData());
graphContainer.classList.remove("hidden");
graphContainer.classList.add("graph-display-flex");
}
@@ -190,4 +209,6 @@ if (typeof window !== 'undefined') {
window.exportCSV = exportCSV;
window.showGraph = showGraph;
window.hideGraph = hideGraph;
}
}
export {};