forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var layoutAttributes = require('./layout_attributes'); | ||
|
||
module.exports = function handleCategoryModeDefaults(containerIn, containerOut, coerce) { | ||
|
||
if(containerIn.type !== 'category') return; | ||
|
||
var validCategories = layoutAttributes.categorymode.values; | ||
|
||
var properCategoryList = Array.isArray(containerIn.categorylist) && containerIn.categorylist.length > 0; | ||
|
||
if(validCategories.indexOf(containerIn.categorymode) === -1 && properCategoryList) { | ||
|
||
// when unspecified or invalid, use the default, unless categorylist implies 'array' | ||
coerce('categorymode', 'array'); // promote to 'array' | ||
|
||
} else if(containerIn.categorymode === 'array' && !properCategoryList) { | ||
|
||
// when mode is 'array' but no list is given, revert to default | ||
|
||
containerIn.categorymode = 'trace'; // revert to default | ||
coerce('categorymode'); | ||
|
||
} else { | ||
|
||
// otherwise use the supplied mode, or the default one if unsupplied or invalid | ||
coerce('categorymode'); | ||
|
||
} | ||
}; |