mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[vislib/yAxis] calculate the tickFormat when it is used
This commit is contained in:
parent
a1948a3ee4
commit
0a7596149c
3 changed files with 11 additions and 24 deletions
|
@ -1,7 +1,5 @@
|
|||
define(function (require) {
|
||||
return function ColumnHandler(d3, Private) {
|
||||
var $ = require('jquery');
|
||||
|
||||
var injectZeros = Private(require('components/vislib/components/zero_injection/inject_zeros'));
|
||||
var Handler = Private(require('components/vislib/lib/handler/handler'));
|
||||
var Data = Private(require('components/vislib/lib/data'));
|
||||
|
@ -27,9 +25,6 @@ define(function (require) {
|
|||
data = new Data(vis.data, vis._attr);
|
||||
}
|
||||
|
||||
var isPercentage = (vis._attr.mode === 'percentage');
|
||||
var tickFormat = isPercentage ? d3.format('%') : data.get('yAxisFormatter', d3.format('n'));
|
||||
|
||||
return new Handler(vis, {
|
||||
data: data,
|
||||
legend: new Legend(vis, vis.el, data.labels, data.color, vis._attr),
|
||||
|
@ -49,7 +44,7 @@ define(function (require) {
|
|||
yMin : data.getYMin(),
|
||||
yMax : data.getYMax(),
|
||||
_attr: vis._attr,
|
||||
tickFormat: tickFormat
|
||||
tickFormat: data.get('yAxisFormatter')
|
||||
})
|
||||
});
|
||||
};
|
||||
|
|
|
@ -2,7 +2,6 @@ define(function (require) {
|
|||
return function YAxisFactory(d3, Private) {
|
||||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
var numeral = require('numeral');
|
||||
var errors = require('errors');
|
||||
|
||||
var ErrorHandler = Private(require('components/vislib/lib/_error_handler'));
|
||||
|
@ -18,7 +17,7 @@ define(function (require) {
|
|||
this.el = args.el;
|
||||
this.yMin = args.yMin;
|
||||
this.yMax = args.yMax;
|
||||
this.tickFormat = args.tickFormat;
|
||||
this.yAxisFormatter = args.yAxisFormatter;
|
||||
this._attr = args._attr || {};
|
||||
}
|
||||
|
||||
|
@ -104,6 +103,13 @@ define(function (require) {
|
|||
.nice();
|
||||
};
|
||||
|
||||
YAxis.prototype.tickFormat = function () {
|
||||
var isPercentage = this._attr.mode === 'percentage';
|
||||
if (isPercentage) return d3.format('%');
|
||||
if (this.yAxisFormatter) return this.yAxisFormatter;
|
||||
return d3.format('n');
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the d3 y axis function
|
||||
*
|
||||
|
@ -122,7 +128,7 @@ define(function (require) {
|
|||
// Create the d3 yAxis function
|
||||
this.yAxis = d3.svg.axis()
|
||||
.scale(yScale)
|
||||
.tickFormat(this.tickFormat)
|
||||
.tickFormat(this.tickFormat())
|
||||
.ticks(this.tickScale(height))
|
||||
.orient('left');
|
||||
|
||||
|
|
|
@ -206,20 +206,6 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
|
||||
describe('formatAxisLabel method', function () {
|
||||
var num = 1e9;
|
||||
var val;
|
||||
|
||||
beforeEach(function () {
|
||||
createData(defaultGraphData);
|
||||
val = yAxis.formatAxisLabel(num);
|
||||
});
|
||||
|
||||
it('should return a string with suffix B', function () {
|
||||
expect(val).to.be('1b');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getScaleType method', function () {
|
||||
var fnNames = ['linear', 'log', 'square root'];
|
||||
|
||||
|
@ -361,4 +347,4 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue