Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92cbd0f

Browse files
committed
rewrite 'categoryorder' and 'categoryarray' defaults step:
- trimmed down the logic - make sure that axis.categoryarray is filled in - use containerOut.type instead of containerIn.type (even though they are the same, we should always use the 'full' value of attributes after they get coerced)
1 parent d097d6a commit 92cbd0f

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/plots/cartesian/category_order_defaults.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,25 @@
88

99
'use strict';
1010

11-
var layoutAttributes = require('./layout_attributes');
1211

1312
module.exports = function handleCategoryOrderDefaults(containerIn, containerOut, coerce) {
13+
if(containerOut.type !== 'category') return;
1414

15-
if(containerIn.type !== 'category') return;
15+
var arrayIn = containerIn.categoryarray,
16+
orderDefault;
1617

17-
var validCategories = layoutAttributes.categoryorder.values;
18+
var isValidArray = (Array.isArray(arrayIn) && arrayIn.length);
1819

19-
var propercategoryarray = Array.isArray(containerIn.categoryarray) && containerIn.categoryarray.length > 0;
20+
// override default 'categoryorder' value when non-empty array is supplied
21+
if(isValidArray) orderDefault = 'array';
2022

21-
if(validCategories.indexOf(containerIn.categoryorder) === -1 && propercategoryarray) {
23+
var order = coerce('categoryorder', orderDefault);
2224

23-
// when unspecified or invalid, use the default, unless categoryarray implies 'array'
24-
coerce('categoryorder', 'array'); // promote to 'array'
25-
26-
} else if(containerIn.categoryorder === 'array' && !propercategoryarray) {
27-
28-
// when mode is 'array' but no list is given, revert to default
29-
30-
containerIn.categoryorder = 'trace'; // revert to default
31-
coerce('categoryorder');
32-
33-
} else {
34-
35-
// otherwise use the supplied mode, or the default one if unsupplied or invalid
36-
coerce('categoryorder');
25+
// coerce 'categoryarray' only in array order case
26+
if(order === 'array') coerce('categoryarray');
3727

28+
// cannot set 'categoryorder' to 'array' with an invalid 'categoryarray'
29+
if(!isValidArray && order === 'array') {
30+
containerOut.categoryorder = 'trace';
3831
}
3932
};

0 commit comments

Comments
 (0)