Skip to content

Axis category ordering - adds feature #189 #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 18, 2016
Prev Previous commit
Next Next commit
#189 categorymode defaults
  • Loading branch information
monfera committed Apr 13, 2016
commit df9ee94c412eda079916b68c98a8aa11125bcb24
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');

}
};