-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchartjs-action.js
More file actions
34 lines (27 loc) · 1 KB
/
chartjs-action.js
File metadata and controls
34 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { createCanvas } = require('canvas')
const { Chart } = require('chart.js/auto')
const yaml = require('yaml')
const path = require('path')
const fs = require('fs')
function createChart(chartData, options) {
const canvasWidth = options.width * 1
const canvasHeight = canvasWidth / 16 * 9
let canvas
if (options.format.match(/svg/i))
canvas = createCanvas(canvasWidth, canvasHeight, 'svg')
else
canvas = createCanvas(canvasWidth, canvasHeight)
new Chart(canvas.getContext('2d'), chartData)
if (options.format.match(/svg/i))
return canvas.toBuffer()
else
return canvas.toBuffer('image/png')
}
module.exports = function (content, options) {
let chartData = yaml.parse(content)
// overrider and deactivate all animations
chartData.options.animation = false
chartData.options.animations = { colors: false, x: false }
chartData.options.transitions = { active: { animation: { duration: 0 } } }
return createChart(chartData, options)
}