Skip to content

Commit 51dddcf

Browse files
committed
Fix numeric color sorting in parcats bundles
1 parent 21da158 commit 51dddcf

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

src/traces/parcats/parcats.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ function compareRawColor(a, b) {
370370
}
371371
}
372372

373+
function compareArrays(a, b) {
374+
for(var i = 0; i < Math.min(a.length, b.length); i++) {
375+
if(a[i] < b[i]) {
376+
return -1;
377+
} else if(a[i] > b[i]) {
378+
return 1;
379+
}
380+
}
381+
382+
return a.length - b.length;
383+
}
384+
373385
/**
374386
* Handle path mouseover
375387
* @param {PathViewModel} d
@@ -1734,15 +1746,8 @@ function updatePathViewModels(parcatsViewModel) {
17341746
sortArray2.unshift(v2.rawColor);
17351747
}
17361748

1737-
// colors equal, sort by display categories
1738-
if(sortArray1 < sortArray2) {
1739-
return -1;
1740-
}
1741-
if(sortArray1 > sortArray2) {
1742-
return 1;
1743-
}
1744-
1745-
return 0;
1749+
// Sort by color, then display categories
1750+
return compareArrays(sortArray1, sortArray2);
17461751
});
17471752

17481753
// Create path models

test/jasmine/tests/parcats_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,29 @@ describe('Basic parcats trace', function() {
284284
.then(done, done.fail);
285285
});
286286

287+
it('should sort bundled paths by numeric color values', function(done) {
288+
var trace = {
289+
type: 'parcats',
290+
dimensions: [
291+
{values: ['a', 'a', 'a', 'a']},
292+
{values: ['b', 'b', 'b', 'b']}
293+
],
294+
line: {color: [1, 10, 2, 20]},
295+
bundlecolors: true
296+
};
297+
298+
Plotly.newPlot(gd, [trace])
299+
.then(function() {
300+
var parcatsViewModel = d3Select('g.trace.parcats').datum();
301+
var pathColors = parcatsViewModel.paths.map(function(path) {
302+
return path.model.rawColor;
303+
});
304+
305+
expect(pathColors).toEqual([1, 2, 10, 20]);
306+
})
307+
.then(done, done.fail);
308+
});
309+
287310
it('should compute initial model views properly', function(done) {
288311
Plotly.newPlot(gd, basicMock)
289312
.then(function() {

0 commit comments

Comments
 (0)