Skip to content

Fix parcats category order when dimension only includes numbers #4973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/traces/parcats/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var colorscaleCalc = require('../../components/colorscale/calc');
var filterUnique = require('../../lib/filter_unique.js');
var Drawing = require('../../components/drawing');
var Lib = require('../../lib');
var isNumeric = require('fast-isnumeric');

/**
* Create a wrapped ParcatsModel object from trace
Expand All @@ -40,9 +41,19 @@ module.exports = function calc(gd, trace) {
// then add extra to the end in trace order
categoryValues = dim.categoryarray;
} else {
// Get all categories up front so we can order them
// Should we check for numbers as sort numerically?
categoryValues = filterUnique(dim.values).sort();
// Get all categories up front
categoryValues = filterUnique(dim.values);

// order them
var allNumeric = true;
for(var i = 0; i < categoryValues.length; i++) {
if(!isNumeric(categoryValues[i])) {
allNumeric = false;
break;
}
}
categoryValues.sort(allNumeric ? Lib.sorterAsc : undefined);

if(dim.categoryorder === 'category descending') {
categoryValues = categoryValues.reverse();
}
Expand Down
Binary file added test/image/baselines/parcats_numeric_sort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions test/image/mocks/parcats_numeric_sort.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"data": [
{
"type": "parcats",
"dimensions": [
{
"label": "A",
"values": [
1,
2,
3
],
"categoryorder": "category ascending"
},
{
"label": "B",
"values": [
9,
10,
11
],
"categoryorder": "category ascending"
}
]
}
],
"layout": {
"width": 320,
"height": 200,
"margin": {
"t": 20,
"b": 20,
"l": 20,
"r": 20
},
"font": {
"size": 16
}
}
}
2 changes: 2 additions & 0 deletions test/jasmine/tests/mock_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ var list = [
'parcats_hoveron_color',
'parcats_hoveron_dimension',
'parcats_invisible_dimension',
'parcats_numeric_sort',
'parcats_reordered',
'parcats_unbundled',
'percent_error_bar',
Expand Down Expand Up @@ -1785,6 +1786,7 @@ figs['parcats_grid_subplots'] = require('@mocks/parcats_grid_subplots');
figs['parcats_hoveron_color'] = require('@mocks/parcats_hoveron_color');
figs['parcats_hoveron_dimension'] = require('@mocks/parcats_hoveron_dimension');
figs['parcats_invisible_dimension'] = require('@mocks/parcats_invisible_dimension');
figs['parcats_numeric_sort'] = require('@mocks/parcats_numeric_sort');
figs['parcats_reordered'] = require('@mocks/parcats_reordered');
figs['parcats_unbundled'] = require('@mocks/parcats_unbundled');
figs['percent_error_bar'] = require('@mocks/percent_error_bar');
Expand Down