mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* do not filter out values that are not zero * do not call fit function when series is all null * simplify filter code * add another test case
This commit is contained in:
parent
15add96054
commit
70da63fa23
2 changed files with 49 additions and 1 deletions
|
@ -8,6 +8,50 @@ import _ from 'lodash';
|
|||
|
||||
describe(filename, function () {
|
||||
|
||||
describe('should not filter out zeros', function () {
|
||||
it('all zeros', function () {
|
||||
const seriesList = getSeriesList('', [
|
||||
[moment.utc('1980-01-01T00:00:00.000Z'), 0],
|
||||
[moment.utc('1981-01-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1982-01-01T00:00:00.000Z'), 0],
|
||||
[moment.utc('1983-01-01T00:00:00.000Z'), 0],
|
||||
]);
|
||||
|
||||
return invoke(fn, [seriesList, 'carry']).then(function (r) {
|
||||
expect(r.input[0].list[0].data[1][1]).to.equal(null);
|
||||
expect(_.map(r.output.list[0].data, 1)).to.eql([0, 0, 0, 0]);
|
||||
expect(r.output.list[0].data[1][0]).to.not.equal(r.output.list[0].data[0][0]);
|
||||
});
|
||||
});
|
||||
|
||||
it('mixed zeros and numbers', function () {
|
||||
const seriesList = getSeriesList('', [
|
||||
[moment.utc('1980-01-01T00:00:00.000Z'), 26],
|
||||
[moment.utc('1981-01-01T00:00:00.000Z'), 42],
|
||||
[moment.utc('1982-01-01T00:00:00.000Z'), 0],
|
||||
[moment.utc('1983-01-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1984-01-01T00:00:00.000Z'), 1],
|
||||
]);
|
||||
|
||||
return invoke(fn, [seriesList, 'carry']).then(function (r) {
|
||||
expect(_.map(r.output.list[0].data, 1)).to.eql([26, 42, 0, 0, 1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return original series when all values are null', function () {
|
||||
const seriesList = getSeriesList('', [
|
||||
[moment.utc('1980-01-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1981-01-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1982-01-01T00:00:00.000Z'), null],
|
||||
[moment.utc('1983-01-01T00:00:00.000Z'), null],
|
||||
]);
|
||||
|
||||
return invoke(fn, [seriesList, 'carry']).then(function (r) {
|
||||
expect(_.map(r.output.list[0].data, 1)).to.eql([null, null, null, null]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('carry', function () {
|
||||
it('should maintain the previous value until it changes', function () {
|
||||
const seriesList = getSeriesList('',[
|
||||
|
|
|
@ -20,7 +20,11 @@ export default new Chainable('fit', {
|
|||
fn: function absFn(args) {
|
||||
return alter(args, function (eachSeries, mode) {
|
||||
|
||||
const noNulls = _.filter(eachSeries.data, 1);
|
||||
const noNulls = eachSeries.data.filter((item) => (item[1] === 0 || item[1]));
|
||||
|
||||
if (noNulls.length === 0) {
|
||||
return eachSeries;
|
||||
}
|
||||
|
||||
eachSeries.data = fitFunctions[mode](noNulls, eachSeries.data);
|
||||
return eachSeries;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue