Add percent tick formatter to timelion (#10917)

This commit is contained in:
Lukas Olson 2017-03-30 14:34:58 -07:00 committed by GitHub
parent bb258bc7ce
commit e8f1d33f2a
3 changed files with 25 additions and 1 deletions

View file

@ -91,7 +91,7 @@ describe('Tick Formatters', function () {
expect(currencyFormatter).to.be.a('function');
});
it('formats with $ by defalt', function () {
it('formats with $ by default', function () {
const axis = {
options: {
units: {}
@ -113,6 +113,26 @@ describe('Tick Formatters', function () {
});
});
describe('Percent mode', function () {
let percentFormatter;
beforeEach(function () {
percentFormatter = tickFormatters.percent;
});
it('is a function', function () {
expect(percentFormatter).to.be.a('function');
});
it('formats with %', function () {
const axis = {
options: {
units: {}
}
};
expect(percentFormatter(0.1234, axis)).to.equal('12.34%');
});
});
describe('Custom mode', function () {
let customFormatter;
beforeEach(function () {

View file

@ -59,6 +59,9 @@ define(function () {
'currency': function (val, axis) {
return val.toLocaleString('en', { style: 'currency', currency: axis.options.units.prefix || 'USD' });
},
'percent': function (val) {
return val * 100 + '%';
},
'custom': function (val, axis) {
const formattedVal = baseTickFormatter(val, axis);
const prefix = axis.options.units.prefix;

View file

@ -7,6 +7,7 @@ const tickFormatters = {
'bytes':'bytes',
'bytes/s':'bytes/s',
'currency':'currency(:ISO 4217 currency code)',
'percent':'percent',
'custom':'custom(:prefix:suffix)'
};
module.exports = new Chainable('yaxis', {