diff --git a/src/plots/cartesian/ordered_categories.js b/src/plots/cartesian/ordered_categories.js index 546578ecb15..2666bb71170 100644 --- a/src/plots/cartesian/ordered_categories.js +++ b/src/plots/cartesian/ordered_categories.js @@ -41,7 +41,7 @@ function flattenUniqueSort(axisLetter, sortFunction, data) { insertionIndex = bisector(categoryArray, category); // skip loop on already encountered values - if(insertionIndex < categoryArray.length - 1 && categoryArray[insertionIndex] === category) continue; + if(insertionIndex < categoryArray.length && categoryArray[insertionIndex] === category) continue; // insert value categoryArray.splice(insertionIndex, 0, category); diff --git a/test/jasmine/tests/calcdata_test.js b/test/jasmine/tests/calcdata_test.js index fb9c3049994..1a6b1c01d4b 100644 --- a/test/jasmine/tests/calcdata_test.js +++ b/test/jasmine/tests/calcdata_test.js @@ -137,6 +137,18 @@ describe('calculated data and points', function() { expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 0, y: 13})); expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 2, y: 14})); }); + + it('should combine duplicate categories', function() { + Plotly.plot(gd, [{x: [ '1', '1'], y: [10, 20]}], { xaxis: { + type: 'category', + categoryorder: 'category ascending' + }}); + + expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 0, y: 10})); + expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 0, y: 20})); + + expect(gd._fullLayout.xaxis._categories).toEqual(['1']); + }); }); describe('explicit category ordering', function() {