Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions asciichart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
cfg = (typeof cfg !== 'undefined') ? cfg : {}
let offset = (typeof cfg.offset !== 'undefined') ? cfg.offset : 3
let padding = (typeof cfg.padding !== 'undefined') ? cfg.padding : ' '
let precision = (typeof cfg.precision !== 'undefined') ? cfg.precision : 2
let height = (typeof cfg.height !== 'undefined') ? cfg.height : range
let ratio = height / range
let min2 = Math.round (min * ratio)
let max2 = Math.round (max * ratio)
let rows = Math.abs (max2 - min2)
let width = series.length + offset
let format = (typeof cfg.format !== 'undefined') ? cfg.format : function (x) {
return (padding + x.toFixed (2)).slice (-padding.length)
return (padding + x.toFixed (precision)).slice (-padding.length)
}

let result = new Array (rows + 1) // empty space
Expand Down Expand Up @@ -62,4 +63,4 @@
return result.map (function (x) { return x.join ('') }).join ('\n')
}

}) (typeof exports === 'undefined' ? /* istanbul ignore next */ this['asciichart'] = {} : exports);
}) (typeof exports === 'undefined' ? /* istanbul ignore next */ this['asciichart'] = {} : exports);