Skip to content

Commit c837359

Browse files
authored
Merge pull request #863 from john-soklaski/category_ascending_bug
Fix off by one error in flattenUniqueSort
2 parents b8a893a + cc3012a commit c837359

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/plots/cartesian/ordered_categories.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function flattenUniqueSort(axisLetter, sortFunction, data) {
4141
insertionIndex = bisector(categoryArray, category);
4242

4343
// skip loop on already encountered values
44-
if(insertionIndex < categoryArray.length - 1 && categoryArray[insertionIndex] === category) continue;
44+
if(insertionIndex < categoryArray.length && categoryArray[insertionIndex] === category) continue;
4545

4646
// insert value
4747
categoryArray.splice(insertionIndex, 0, category);

test/jasmine/tests/calcdata_test.js

+12
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ describe('calculated data and points', function() {
137137
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 0, y: 13}));
138138
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 2, y: 14}));
139139
});
140+
141+
it('should combine duplicate categories', function() {
142+
Plotly.plot(gd, [{x: [ '1', '1'], y: [10, 20]}], { xaxis: {
143+
type: 'category',
144+
categoryorder: 'category ascending'
145+
}});
146+
147+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 0, y: 10}));
148+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 0, y: 20}));
149+
150+
expect(gd._fullLayout.xaxis._categories).toEqual(['1']);
151+
});
140152
});
141153

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

0 commit comments

Comments
 (0)