Skip to content

Commit

Permalink
Merge pull request #1968 from stormpython/fix/#1903
Browse files Browse the repository at this point in the history
Allow ordering of bars by count on term aggregation when x axis values are numbers
  • Loading branch information
stormpython committed Dec 1, 2014
2 parents d5d1d5c + 9267cd8 commit 0f133a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ define(function (require) {
return _.chain(objKeys)
.pairs()
.sortBy(function (d) {
if (d[1].isNumber) {
// sort by index
return +d[0];
}

// sort by index
return d[1].index;
})
.map(function (d) {
return d[1].isNumber ? +d[0] : d[0];
})
.value();
};
};
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,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 0f133a7

Please sign in to comment.