|
6 | 6 | * LICENSE file in the root directory of this source tree.
|
7 | 7 | */
|
8 | 8 |
|
9 |
| - |
10 | 9 | 'use strict';
|
11 | 10 |
|
| 11 | +var layoutAttributes = require('./layout_attributes'); |
| 12 | + |
12 | 13 | module.exports = function handleCategoryModeDefaults(containerIn, containerOut, coerce) {
|
13 | 14 |
|
14 |
| - if(containerIn.type === 'category') { |
| 15 | + if(containerIn.type !== 'category') return; |
15 | 16 |
|
16 |
| - var validCategories = ['trace', 'category ascending', 'category descending', 'array']; |
| 17 | + var validCategories = layoutAttributes.categorymode.values; |
17 | 18 |
|
18 |
| - var properCategoryList = Array.isArray(containerIn.categorylist) && containerIn.categorylist.length > 0; |
| 19 | + var properCategoryList = Array.isArray(containerIn.categorylist) && containerIn.categorylist.length > 0; |
19 | 20 |
|
20 |
| - if(validCategories.indexOf(containerIn.categorymode) === -1 && properCategoryList) { |
| 21 | + if(validCategories.indexOf(containerIn.categorymode) === -1 && properCategoryList) { |
21 | 22 |
|
22 |
| - // when unspecified or invalid, use the default, unless categorylist implies 'array' |
23 |
| - coerce('categorymode', 'array'); // promote to 'array' |
| 23 | + // when unspecified or invalid, use the default, unless categorylist implies 'array' |
| 24 | + coerce('categorymode', 'array'); // promote to 'array' |
24 | 25 |
|
25 |
| - } else if(containerIn.categorymode === 'array' && !properCategoryList) { |
| 26 | + } else if(containerIn.categorymode === 'array' && !properCategoryList) { |
26 | 27 |
|
27 |
| - // when mode is 'array' but no list is given, revert to default |
| 28 | + // when mode is 'array' but no list is given, revert to default |
28 | 29 |
|
29 |
| - containerIn.categorymode = 'trace'; // revert to default |
30 |
| - coerce('categorymode'); |
| 30 | + containerIn.categorymode = 'trace'; // revert to default |
| 31 | + coerce('categorymode'); |
31 | 32 |
|
32 |
| - } else { |
| 33 | + } else { |
33 | 34 |
|
34 |
| - // otherwise use the supplied mode, or the default one if unsupplied or invalid |
35 |
| - coerce('categorymode'); |
| 35 | + // otherwise use the supplied mode, or the default one if unsupplied or invalid |
| 36 | + coerce('categorymode'); |
36 | 37 |
|
37 |
| - } |
38 | 38 | }
|
39 | 39 | };
|
0 commit comments