-
Notifications
You must be signed in to change notification settings - Fork 636
Fix. Account for the "data_array" property of the "values" attribute of the "dimensions" attribute. Closes #2385 #2387
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
base: master
Are you sure you want to change the base?
Conversation
…e data_array propery of the "values" attribute. Closes plotly#2385. * Add tests to check that "values" property has class "AsIs" for "parcoords", "parcats" and "splom" traces. * Add NEWS entry
R/utils.R
Outdated
| proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr) | ||
| # The "dimensions" attribute requires a special treatment as | ||
| # it is an unnamed list and hence will be skipped by `for (attr in names(proposed)) | ||
| if (attr == "dimensions") { |
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.
Seems there is actually a more general problem here that's beyond just dimensions. Some attributes say role: object, but are actually expecting a list of objects. Here is the schema for both dimensions and transforms:
So, I think this code should be closer to:
if (identical(role, "object") && is.recursive(proposed[[attr]])) {
# Some attributes (e.g., dimensions, transforms) are actually
# a list of objects (even though they, confusingly, have role: object)
# In those cases, we actually want to verify each list element
attr_ <- sub("s$", "", attr)
is_list_attr <- ("items" %in% names(attrSchema)) &&
(attr_ %in% names(attrSchema$items))
if (is_list_attr) {
proposed[[attr]] <- lapply(proposed[[attr]], function(x) {
verify_attr(x, attrSchema$items[[attr_]])
})
} else {
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr)
}
}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.
Thx for the review and the suggestions. Just added and comitted.
R/utils.R
Outdated
| if (attr == "dimensions") { | ||
| proposed[[attr]] <- lapply(proposed[[attr]], \(x) { |
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.
\(x) was added fairly recently to R, so please use function(x) instead
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 for the reminder. Should have thought of that myself.
Co-authored-by: Carson Sievert <[email protected]>
Co-authored-by: Carson Sievert <[email protected]>
This PR proposes a fix to account for the "data_array" property of the "values" attribute of the "dimensions" attribute used in special traces like "parcoords", "parcats" and "splom" traces thereby closing #2385.
Currently, when an attribute has the "data_array" attribute it gets wrapped in
AsIsinsideverify_attr. However, this check gets skipped for thedimensionsattribute as it is an unnamed list. Additionally, the schema specs for thevaluesattribute are somewhat nested.To account for that the PR adds some special treatment for
dimensionsattribute toverify_attrwhich useslapplyto loop over the items of thedimensionslist.With the proposed fix the examples documented in #2385 work fine, e.g. for
"parcats":Created on 2024-08-31 with reprex v2.1.1