mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Add percent tick formatter to timelion (#10917)
This commit is contained in:
parent
bb258bc7ce
commit
e8f1d33f2a
3 changed files with 25 additions and 1 deletions
|
@ -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 () {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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', {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue