Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added default precision modifier #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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);