send graph to display
This commit is contained in:
51
src/roast.ts
51
src/roast.ts
@@ -7,18 +7,19 @@ let targets: number[] = [];
|
|||||||
let currentTargetIndex = 0;
|
let currentTargetIndex = 0;
|
||||||
let interval: NodeJS.Timeout | null = null;
|
let interval: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
startTimer?: Function; // function to start the timer
|
startTimer: () => void;
|
||||||
stopTimer?: Function; // function to stop the timer
|
stopTimer: () => void;
|
||||||
logEvent?: Function; // function to log a new event
|
logEvent: (eventName: string) => void;
|
||||||
resetSystem?: Function; // function to reset all actions in the system
|
resetSystem: () => void;
|
||||||
setPlan?: Function; // function to update the temp event plan
|
setPlan: () => void;
|
||||||
navigateTemp?: Function; //function to navigate forward/back between events in the setPlan() temp plan
|
navigateTemp: (direction: number) => void;
|
||||||
logTemp?: Function; //function to log a temputure event
|
logTemp: (temp: number) => void;
|
||||||
exportCSV?: Function; //function to export the events to CSV
|
exportCSV: () => void;
|
||||||
showGraph?: Function; // function to render or display graphs using libraries like Chart.js for visual representation of logged events
|
showGraph: () => void;
|
||||||
hideGraph?: Function; //function to hind the graph popup
|
hideGraph: () => void;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -149,8 +150,26 @@ function updateLog(): void {
|
|||||||
`).join("");
|
`).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 {
|
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 blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
link.setAttribute("href", URL.createObjectURL(blob));
|
link.setAttribute("href", URL.createObjectURL(blob));
|
||||||
@@ -164,7 +183,7 @@ function exportCSV(): void {
|
|||||||
function showGraph(): void {
|
function showGraph(): void {
|
||||||
const graphContainer = document.getElementById("graph-container");
|
const graphContainer = document.getElementById("graph-container");
|
||||||
if (graphContainer) {
|
if (graphContainer) {
|
||||||
loadGraph(null);
|
loadGraph(createCSVData());
|
||||||
graphContainer.classList.remove("hidden");
|
graphContainer.classList.remove("hidden");
|
||||||
graphContainer.classList.add("graph-display-flex");
|
graphContainer.classList.add("graph-display-flex");
|
||||||
}
|
}
|
||||||
@@ -190,4 +209,6 @@ if (typeof window !== 'undefined') {
|
|||||||
window.exportCSV = exportCSV;
|
window.exportCSV = exportCSV;
|
||||||
window.showGraph = showGraph;
|
window.showGraph = showGraph;
|
||||||
window.hideGraph = hideGraph;
|
window.hideGraph = hideGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export {};
|
||||||
Reference in New Issue
Block a user