From 6d0d27511f32be1261ee7b3b4d1cae112be871ffc8f32396b6721a44d5da7b3e Mon Sep 17 00:00:00 2001 From: Terrence Ezrol Date: Sun, 13 Jul 2025 14:03:49 -0400 Subject: [PATCH] send graph to display --- src/roast.ts | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/src/roast.ts b/src/roast.ts index d72668d..1ef3284 100644 --- a/src/roast.ts +++ b/src/roast.ts @@ -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; -} \ No newline at end of file +} + +export {}; \ No newline at end of file