File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright 2012-2016, Plotly, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ 'use strict' ;
10
+
11
+ var layoutAttributes = require ( './layout_attributes' ) ;
12
+
13
+ module . exports = function handleCategoryModeDefaults ( containerIn , containerOut , coerce ) {
14
+
15
+ if ( containerIn . type !== 'category' ) return ;
16
+
17
+ var validCategories = layoutAttributes . categorymode . values ;
18
+
19
+ var properCategoryList = Array . isArray ( containerIn . categorylist ) && containerIn . categorylist . length > 0 ;
20
+
21
+ if ( validCategories . indexOf ( containerIn . categorymode ) === - 1 && properCategoryList ) {
22
+
23
+ // when unspecified or invalid, use the default, unless categorylist implies 'array'
24
+ coerce ( 'categorymode' , 'array' ) ; // promote to 'array'
25
+
26
+ } else if ( containerIn . categorymode === 'array' && ! properCategoryList ) {
27
+
28
+ // when mode is 'array' but no list is given, revert to default
29
+
30
+ containerIn . categorymode = 'trace' ; // revert to default
31
+ coerce ( 'categorymode' ) ;
32
+
33
+ } else {
34
+
35
+ // otherwise use the supplied mode, or the default one if unsupplied or invalid
36
+ coerce ( 'categorymode' ) ;
37
+
38
+ }
39
+ } ;
You can’t perform that action at this time.
0 commit comments