Skip to content

Commit

Permalink
Closes elastic#1903. Results are returned in the order that elasticse…
Browse files Browse the repository at this point in the history
…arch sends them. That is, in descending order with the biggest values first. Changed the index which is recorded from the highest to the lowest. So the lowest index position is taken for an x value instead of the highest. In addition, we were not actually sorting by indexed position before, so this fixes that bug.
  • Loading branch information
stormpython committed Nov 25, 2014
1 parent 02fec5b commit e54e641
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ define(function (require) {

flattenedData.forEach(function (d, i) {
var key = d.x;
console.log(d.x, i);

if (uniqueXValues[key] === void 0) {
uniqueXValues[key] = {
Expand All @@ -30,7 +29,7 @@ define(function (require) {
};
} else {
uniqueXValues[key] = {
index: Math.max(i, uniqueXValues[key].index),
index: Math.min(i, uniqueXValues[key].index),
isNumber: _.isNumber(key)
};
}
Expand Down
35 changes: 35 additions & 0 deletions test/unit/specs/vislib/components/zero_injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,35 @@ define(function (require) {
]
};

var multiSeriesNumberedData = {
series: [
{
label: '200',
values: [
{x: 1, y: 234},
{x: 2, y: 34},
{x: 3, y: 834},
{x: 4, y: 1234},
{x: 5, y: 4}
]
},
{
label: '404',
values: [
{x: 1, y: 1234},
{x: 3, y: 234},
{x: 5, y: 34}
]
},
{
label: '503',
values: [
{x: 3, y: 834}
]
}
]
};

var ordered = {};
var childrenObject = {
children: []
Expand All @@ -80,6 +109,7 @@ define(function (require) {
var injectZeros;
var sample1;
var sample2;
var sample3;

beforeEach(function () {
module('ZeroInjectionUtilService');
Expand All @@ -90,6 +120,7 @@ define(function (require) {
injectZeros = Private(require('components/vislib/components/zero_injection/inject_zeros'));
sample1 = injectZeros(seriesData);
sample2 = injectZeros(multiSeriesData);
sample3 = injectZeros(multiSeriesNumberedData);
});
});

Expand Down Expand Up @@ -165,6 +196,10 @@ define(function (require) {
expect(sample2.series[2].values[0].y).to.be(0);
expect(sample2.series[2].values[1].y).to.be(0);
expect(sample2.series[2].values[4].y).to.be(0);
expect(sample3.series[1].values[1].y).to.be(0);
expect(sample3.series[2].values[0].y).to.be(0);
expect(sample3.series[2].values[1].y).to.be(0);
expect(sample3.series[2].values[4].y).to.be(0);
});

it('should return values arrays with the same x values', function () {
Expand Down

0 comments on commit e54e641

Please sign in to comment.