trigger drawing screen

This commit is contained in:
2025-07-13 12:35:58 -04:00
parent a02eae32a1
commit 96589039a4
2 changed files with 92 additions and 78 deletions

View File

@@ -1,4 +1,4 @@
import { loadGraph } from './tempgraph.ts';
let timer = 0; let timer = 0;
let isRunning = false; let isRunning = false;
@@ -164,6 +164,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);
graphContainer.classList.remove("hidden"); graphContainer.classList.remove("hidden");
graphContainer.classList.add("graph-display-flex"); graphContainer.classList.add("graph-display-flex");
} }

View File

@@ -2,10 +2,8 @@ import { Chart, registerables } from 'chart.js';
import annotationPlugin from 'chartjs-plugin-annotation'; import annotationPlugin from 'chartjs-plugin-annotation';
import { AnnotationOptions } from 'chartjs-plugin-annotation'; import { AnnotationOptions } from 'chartjs-plugin-annotation';
// Register all Chart.js components /* Test data if nothing is provided */
Chart.register(...registerables); function getTestData(): string[] {
Chart.register(annotationPlugin);
const sampleData = `Time,Event,Temperature const sampleData = `Time,Event,Temperature
0:00,Charge, 0:00,Charge,
0:00,Temp,139 0:00,Temp,139
@@ -18,18 +16,28 @@ const sampleData = `Time,Event,Temperature
0:24,First Crack, 0:24,First Crack,
0:30,Temp,208 0:30,Temp,208
0:31,Drop,`; 0:31,Drop,`;
return sampleData.split('\n');
}
// Register all Chart.js components
Chart.register(...registerables);
Chart.register(annotationPlugin);
const lines = sampleData.split('\n');
const data = lines.slice(1).map(line => {
const [time, event, temp] = line.split(',');
return { time, event, temp };
});
function parseTime(time: string): number { function parseTime(time: string): number {
const [mins, secs] = time.split(':').map(Number); const [mins, secs] = time.split(':').map(Number);
return mins * 60 + secs; return mins * 60 + secs;
} }
export function loadGraph(dataArray?: string[]): void {
const lines = dataArray || getTestData();
// Further code using `lines`...
const data = lines.slice(1).map(line => {
const [time, event, temp] = line.split(',');
return { time, event, temp };
});
const tempData = data const tempData = data
.filter(entry => entry.event === 'Temp') .filter(entry => entry.event === 'Temp')
.map(entry => { .map(entry => {
@@ -62,7 +70,11 @@ const annotationsArray: AnnotationOptions<'line'>[] = data
}; };
}); });
// Your Chart.js configuration remains the same: // Clear previous chart instance if exists
const oldChart = (ctx as any).chart;
if (oldChart) {
oldChart.destroy();
}
new Chart(ctx, { new Chart(ctx, {
type: 'line', type: 'line',
data: { data: {
@@ -98,10 +110,11 @@ new Chart(ctx, {
} }
} }
}, },
plugins: { // Correctly nested as per the previous answer plugins: {
annotation: { annotation: {
annotations: annotationsArray annotations: annotationsArray
} }
} }
} }
}); });
}