gcs-backend-server / lib /summaryHelper /generateGraph.js
github-actions[bot]
chore: deploy from GitHub Actions (2026-03-08T13:13:40Z)
d9d886e
Raw History Blame Contribute Delete
1.51 kB
const { ChartJSNodeCanvas } = require('chartjs-node-canvas')
const width = 1130
const height = 300
const chartCallback = (ChartJS) => {
console.log('chart built')
}
// Initialize the Altitude Chart
const canvasRenderService = new ChartJSNodeCanvas({ width, height, chartCallback })
const generateGraph = async (data) => {
try {
const zs = data.plotInterface[8].mavData[0].data
const timeFrame = data.plotInterface[8].timeFrame
const configuration = {
type: 'line',
data: {
labels: timeFrame,
datasets: [{
label: 'Altitude',
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
data: zs,
fill: true
}]
},
options: {
responsive: true,
spanGaps: true,
animation: false,
scales: {
x: {
display: true
},
y: {
display: true
}
},
elements: {
point: {
radius: 0
},
aspectRatio: 1
},
plugins: {
legend: {
position: 'top',
labels: {
usePointStyle: true
}
}
}
}
}
// Generate the chart image
const dataUrl = await canvasRenderService.renderToDataURL(configuration)
return dataUrl
} catch (error) {
console.error('Error generating graph:', error)
throw error
}
}
module.exports = generateGraph