diff --git a/lib/cli/chart.js b/lib/cli/chart.js index 75e8f18..c763998 100644 --- a/lib/cli/chart.js +++ b/lib/cli/chart.js @@ -1,11 +1,13 @@ const chart = require('asciichart'); -// generate chart for caes or deaths +// generate chart for cases or deaths exports.generate = (data, type = 'cases') => { + const maxLength = Object.values(data.timeline[type]) + .reduce((a,c) => Math.max(a, c.toFixed().length), 0) const config = { height: 7, - format: (x, i) => (' ' + x.toFixed(0)).slice(-' '.length) + format: (x, i) => x.toFixed().padStart(maxLength) }; chartData = Object.values(data.timeline[type]).flat(); return chart.plot(chartData, config); -} \ No newline at end of file +}