-
-
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 all commits
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 > 0); | ||
|
||
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.
@etpinard a quick chat or pointer about containerIn vs Out would be interesting as I kept using the former.
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.
As a rule, user data (i.e.
gd.data
/gd.layout
or their nestedcontainerIn
objects) should not be used anywhere after the supply-defautls step. They are a few exceptions to that rule (namelyscene.camera
), but we should try to keep the number of exceptions as small as possible.Previously,
orderedCategories
was usingcontainerIn.categoryorder
. In the case wherecategoryorder
was coerced to'array'
viacatgoryarray
here,orderedCategories
was not given the correctcategoryorder
value.In order words, user data/layout is (exactly) what the user inputs, whereas full data/layout is what plotly.js uses to compute and draw things.
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.
Thanks @etpinard! It's so useful it would deserve to stick around as a block comment in the code. Sometimes the thoughts and concepts behind coding choices are easily unravelled, but I definitely missed some.
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.
It would deserve more than a block comment in my opinion.
We should try tackling #66 soon.
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.
@monfera I'm refactoring our top-level supply-defaults functions in #491 , I'll add the info you're requesting to the
Plots.supplyDefaults
jsDoc in PR #491 .