-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Layout grids #2399
Layout grids #2399
Changes from 8 commits
001bd9b
606a601
f01db07
82fbae2
cd6e823
1aec7f7
446f9f9
40dd784
670bdd5
6b8d461
4b43e35
794669b
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 |
---|---|---|
|
@@ -257,19 +257,56 @@ exports.valObjectMeta = { | |
'An {array} of plot information.' | ||
].join(' '), | ||
requiredOpts: ['items'], | ||
otherOpts: ['dflt', 'freeLength'], | ||
// set dimensions=2 for a 2D array | ||
// `items` may be a single object instead of an array, in which case | ||
// `freeLength` must be true. | ||
otherOpts: ['dflt', 'freeLength', 'dimensions'], | ||
coerceFunction: function(v, propOut, dflt, opts) { | ||
|
||
// simplified coerce function just for array items | ||
function coercePart(v, opts, dflt) { | ||
var out; | ||
var propPart = {set: function(v) { out = v; }}; | ||
|
||
if(dflt === undefined) dflt = opts.dflt; | ||
|
||
exports.valObjectMeta[opts.valType].coerceFunction(v, propPart, dflt, opts); | ||
|
||
return out; | ||
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. I had change this section to support non-array 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. Amazing thanks! |
||
} | ||
|
||
var twoD = opts.dimensions === 2; | ||
|
||
if(!Array.isArray(v)) { | ||
propOut.set(dflt); | ||
return; | ||
} | ||
|
||
var items = opts.items, | ||
vOut = []; | ||
var items = opts.items; | ||
var vOut = []; | ||
var arrayItems = Array.isArray(items); | ||
var len = arrayItems ? items.length : v.length; | ||
|
||
var i, j, len2, vNew; | ||
|
||
dflt = Array.isArray(dflt) ? dflt : []; | ||
|
||
for(var i = 0; i < items.length; i++) { | ||
exports.coerce(v, vOut, items, '[' + i + ']', dflt[i]); | ||
if(twoD) { | ||
for(i = 0; i < len; i++) { | ||
vOut[i] = []; | ||
var row = Array.isArray(v[i]) ? v[i] : []; | ||
len2 = arrayItems ? items[i].length : row.length; | ||
for(j = 0; j < len2; j++) { | ||
vNew = coercePart(row[j], arrayItems ? items[i][j] : items, (dflt[i] || [])[j]); | ||
if(vNew !== undefined) vOut[i][j] = vNew; | ||
} | ||
} | ||
} | ||
else { | ||
for(i = 0; i < len; i++) { | ||
vNew = coercePart(v[i], arrayItems ? items[i] : items, dflt[i]); | ||
if(vNew !== undefined) vOut[i] = vNew; | ||
} | ||
} | ||
|
||
propOut.set(vOut); | ||
|
@@ -278,15 +315,25 @@ exports.valObjectMeta = { | |
if(!Array.isArray(v)) return false; | ||
|
||
var items = opts.items; | ||
var arrayItems = Array.isArray(items); | ||
var twoD = opts.dimensions === 2; | ||
|
||
// when free length is off, input and declared lengths must match | ||
if(!opts.freeLength && v.length !== items.length) return false; | ||
|
||
// valid when all input items are valid | ||
for(var i = 0; i < v.length; i++) { | ||
var isItemValid = exports.validate(v[i], opts.items[i]); | ||
|
||
if(!isItemValid) return false; | ||
if(twoD) { | ||
if(!Array.isArray(v[i]) || (!opts.freeLength && v[i].length !== items[i].length)) { | ||
return false; | ||
} | ||
for(var j = 0; j < v[i].length; j++) { | ||
if(!exports.validate(v[i][j], arrayItems ? items[i][j] : items)) { | ||
return false; | ||
} | ||
} | ||
} | ||
else if(!exports.validate(v[i], arrayItems ? items[i] : items)) return false; | ||
} | ||
|
||
return true; | ||
|
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 needed 1D and 2D arbitrary-length
info_array
for specifying axes and/or subplots for the grid. I didn't actually end up usingcoerce
with these, since there's validation involved where allowed values depend on both the available axes/subplots and on earlier elements in the same array; but it's still important for documentation, and forPlotly.react
it's important that these are marked asinfo_array
and notdata_array
.Anyway, they work, in case we find a need in the future... tested below.
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.
Good stuff!
Would you mind updating the updatemenus and sliders attributes
so that they use
items: {}
instead of the not-as-generalitems: [{}, {}, {}]
.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.
These ones are for function arguments, and we know that the functions being called have a maximum of 3 arguments. The
[{}, {}, {}]
form ensures we never go past three args. I suppose it probably wouldn't hurt to change it, but I didn't feel like taking that risk as I'm not sure how well tested the edge cases are for these components.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.
Good point here about
args
being at-most a three-item array. Let's keep that as it 👌But this has me thinking: should we change attributes like
ticktext
andtickvals
to free-lengthinfo_array
instead of their currentdata_array
val type? That way, we could get rid of this ugly hack.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.
Hmm, possibly... would certainly be nice to keep
data_array
out oflayout
, but those are potentially long enough (and likely enough to be connected to a data source) to still warrant being calleddata_array
so I'm a bit ambivalent about it. We could discuss this in a separate issue.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.
Sounds good 👍
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.
Let's continue that discussion in -> #1894