Skip to content

Commit

Permalink
plotly#189 adding a path for when categorymode is not in ['array', 'c…
Browse files Browse the repository at this point in the history
…ategory ascending', 'category descending']
  • Loading branch information
monfera committed Apr 8, 2016
1 parent 5f33a7b commit f4214cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/plots/cartesian/ordered_categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ module.exports = function orderedCategories(axisLetter, categorymode, categoryli

// ... or take the union of all encountered tick keys and sort them as specified
// (could be simplified with lodash-fp or ramda)
[].concat.apply([], data.map(function(d) {return d[axisLetter];}))
.filter(function(element, index, array) {return index === array.indexOf(element);})
.sort(({
'category ascending': d3.ascending,
'category descending': d3.descending
})[categorymode]);

['category ascending', 'category descending'].indexOf(categorymode) > -1 ?

[].concat.apply([], data.map(function(d) {return d[axisLetter];}))
.filter(function(element, index, array) {return index === array.indexOf(element);})
.sort(({
'category ascending': d3.ascending,
'category descending': d3.descending
})[categorymode]) :

[].slice();
};
4 changes: 2 additions & 2 deletions test/jasmine/tests/calcdata_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('calculated data and points', function() {
});
});

fdescribe('explicit category ordering', function() {
describe('explicit category ordering', function() {

it('should output categories in explicitly supplied order, independent of trace order', function() {

Expand Down Expand Up @@ -252,7 +252,7 @@ describe('calculated data and points', function() {
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 3, y: 14}));
});

fit('should output categories in explicitly supplied order first, if not all categories are covered', function() {
it('should output categories in explicitly supplied order first, if not all categories are covered', function() {

Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
Expand Down

0 comments on commit f4214cb

Please sign in to comment.