-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix relayout axis category #510
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
Changes from 1 commit
d097d6a
92cbd0f
05715bd
460e53a
b1892ce
c6075cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,32 +8,25 @@ | |
|
||
'use strict'; | ||
|
||
var layoutAttributes = require('./layout_attributes'); | ||
|
||
module.exports = function handleCategoryOrderDefaults(containerIn, containerOut, coerce) { | ||
if(containerOut.type !== 'category') return; | ||
|
||
if(containerIn.type !== 'category') return; | ||
var arrayIn = containerIn.categoryarray, | ||
orderDefault; | ||
|
||
var validCategories = layoutAttributes.categoryorder.values; | ||
var isValidArray = (Array.isArray(arrayIn) && arrayIn.length); | ||
|
||
var propercategoryarray = Array.isArray(containerIn.categoryarray) && containerIn.categoryarray.length > 0; | ||
// override default 'categoryorder' value when non-empty array is supplied | ||
if(isValidArray) orderDefault = 'array'; | ||
|
||
if(validCategories.indexOf(containerIn.categoryorder) === -1 && propercategoryarray) { | ||
var order = coerce('categoryorder', orderDefault); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, this made me learn a bit about the safety/necessity of doing the coercion unconditionally, off the bat. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not sure if it's better, but coercing off the bat is definitely the most common approach in our code base. |
||
|
||
// when unspecified or invalid, use the default, unless categoryarray implies 'array' | ||
coerce('categoryorder', 'array'); // promote to 'array' | ||
|
||
} else if(containerIn.categoryorder === 'array' && !propercategoryarray) { | ||
|
||
// when mode is 'array' but no list is given, revert to default | ||
|
||
containerIn.categoryorder = 'trace'; // revert to default | ||
coerce('categoryorder'); | ||
|
||
} else { | ||
|
||
// otherwise use the supplied mode, or the default one if unsupplied or invalid | ||
coerce('categoryorder'); | ||
// coerce 'categoryarray' only in array order case | ||
if(order === 'array') coerce('categoryarray'); | ||
|
||
// cannot set 'categoryorder' to 'array' with an invalid 'categoryarray' | ||
if(!isValidArray && order === 'array') { | ||
containerOut.categoryorder = 'trace'; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like the brevity of
a.length
rather thana.length > 0
but assume that most places want the more explicit version :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I'll change it to
arrayIn.length > 0