-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Introducing Plotly.validate(data, layout) #697
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
Conversation
- to determine if an attribute val is valid
- now only coerce numbers, dates and boolean to string
- to determine whether user 'data' and 'layout' are valid in plotly.js
assertErrorShape(out, [], 4); | ||
assertErrorContent(out.layout[0], 'schema', ['annotations[1]', 'arrowSymbol'], ''); | ||
assertErrorContent(out.layout[1], 'unused', ['xaxis', 'rangeselector', 'buttons[0]', 'count'], ''); | ||
assertErrorContent(out.layout[2], 'schema', ['xaxis', 'rangeselector', 'buttons[1]', 'title'], ''); |
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.
@mdtusz Plotly.validate
returns an array of nested keys, as you suggested.
Maybe we should also return the .join('.')
version for folks using Lib.nestedProperty
?
Moreover, I thought also about writing paths to _isLinkedToArray
attributes as e.g.
['xaxis', 'rangeselector', 'buttons', 1 'title']
// instead of
['xaxis', 'rangeselector', 'buttons[1]', 'title']
Thoughts?
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.
Moreover, I thought also about writing paths to
_isLinkedToArray
attributes as e.g.['xaxis', 'rangeselector', 'buttons', 1, 'title'] // instead of ['xaxis', 'rangeselector', 'buttons[1]', 'title']
I added your missing comma, but yes, if you're going to return an array like that, integers for array indices is the way to go so you could just loop through with container = container[path[i]]
. I would think though that, aside from our own internal uses (which can certainly use Lib.nestedProperty
unless we export these results to another language), folks will rarely want programmatic access to these items. Mostly they'd just want something easy to look at and spot their error, in which case I'd think the single string version is nicer.
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'd say go with the more split-up integer notation.
folks will rarely want programmatic access to these items
Chelsea will attest that they always want programmatic access. I don't think that the non-string version is really any more difficult to grok, and the all string version just adds more complexity to programatic usage for when the case arises.
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.
Why not output both then?
I think the workspace (cc @chriddyp) uses Lib.nestedProperty
(or some in-house version of it), so outputing an attribute string might be best for them.
But, I agree, an array of path parts is best for users just wanting to spot their errors.
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 decided to output both an array path
and an attribute string astr
field. The path field should be more readable while the astr
field will be useful for compatibility with Plotly.restyle
and Plotly.relayout
.
See tests here.
- only value that have same correct length and all item valid are consisdered valid.
- make Plotly.validate return a 1-level deep array of error objects - add 'container' and 'trace' key in each error object to locate the error in data trace or layout. - add 'astr' to error object (for easy plug into restyle and relayout)
|
||
// 'failed' just something mutable that won't be === anything else | ||
|
||
valObject.coerceFunction(value, propMock, failed, opts); |
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.
so the
failed = {}
out = failed
coerce(() => out = v)
out !== failed
dance is just checking to see if if propMock is fired by checking to see if the exising out === failed
reference is no longer valid?
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.
Exactly.
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.
would something like
var called = false;
var propMock = {set: function() { called = true }
valObject.coerceFunction(value, propMock, failed, opts);
return called;
also work?
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.
No. Because we want coerced values to be considered valid.
For example,
Lib.validate('1', { valType: 'number' }); // => true
even though 1
will be inserted in fullData
.
In other words, out
and failed
will be linked to different refs when the coerce function makes propMock
execute propMock.set(dflt)
.
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.
right makes sense
Looks good from my view! 💃 |
resolves #598
based off
plotly-validate
andlib-validate
.Example
In brief
This PR expose a top-level method allowing users to validate their input
data
andlayout
.Plotly.validate
callsPlots.supplyDefaults
andPlotSchema.get
and a newLib.validate
method internally to determine if:'object'
] a container key isn't linked to an object'array'
] an array container key isn't linked to an array'schema'
] a key was found in a trace or layout object that is not part of the plot schema'unused'
] a key was found in user input but isn't used in the plotting code (i.e. the key isn't foundfullData
orfullLayout
)'value'
] a value is invalid'invisible'
] a trace was madevisible = false
by an invalid set of attributesSome remaining questions
data
and non-objectlayout
input? Error out?, Output with different other error code?Plotly.validate
returntrue
? More generally, shouldPlotly.validate
always return the a{ data: [], layout: [] }
object?Those questions ⏫ were resolved in 54a6ed0