Spaces:
Paused
Paused
Download lib/summaryHelper/generateGraph.js from Adhyasta/gcs-backend-server: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/Adhyasta/gcs-backend-server/resolve/main/lib/summaryHelper/generateGraph.js
- Command line
-
hf download hf://spaces/Adhyasta/gcs-backend-server/lib/summaryHelper/generateGraph.js
-
curl -L -o generateGraph.js https://huggingface.co/spaces/Adhyasta/gcs-backend-server/resolve/main/lib/summaryHelper/generateGraph.js
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 | |