Skip to content

Commit

Permalink
plotly#189 categorymode defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
monfera committed Apr 13, 2016
1 parent e36d163 commit df9ee94
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/plots/cartesian/category_mode_defaults.js
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');

}
};

0 comments on commit df9ee94

Please sign in to comment.