-
Notifications
You must be signed in to change notification settings - Fork 634
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?
Changes from 1 commit
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 |
---|---|---|
|
@@ -551,7 +551,15 @@ verify_attr <- function(proposed, schema, layoutAttr = FALSE) { | |
|
||
# do the same for "sub-attributes" | ||
if (identical(role, "object") && is.recursive(proposed[[attr]])) { | ||
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 commentThe 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 ![]() ![]() 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thx for the review and the suggestions. Just added and comitted. |
||
proposed[[attr]] <- lapply(proposed[[attr]], \(x) { | ||
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.
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 for the reminder. Should have thought of that myself. |
||
verify_attr(x, attrSchema$items$dimension, layoutAttr = layoutAttr) | ||
}) | ||
} else { | ||
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr) | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
expect_traces <- function(p, n.traces, name) { | ||
stopifnot(is.numeric(n.traces)) | ||
L <- expect_doppelganger_built(p, paste0("plotly-", name)) | ||
expect_equivalent(length(L$data), n.traces) | ||
L | ||
} | ||
|
||
test_that("values property has a class of AsIs", { | ||
p <- plot_ly( | ||
dimensions = list( | ||
list(values = "A"), | ||
list(values = "B") | ||
), | ||
type = "parcats" | ||
) | ||
l <- expect_traces(p, 1, "parcats-data-array") | ||
tr <- l$data[[1]]$dimensions | ||
expect_true(inherits(tr[[1]]$values, "AsIs")) | ||
expect_true(inherits(tr[[2]]$values, "AsIs")) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
expect_traces <- function(p, n.traces, name) { | ||
stopifnot(is.numeric(n.traces)) | ||
L <- expect_doppelganger_built(p, paste0("plotly-", name)) | ||
expect_equivalent(length(L$data), n.traces) | ||
L | ||
} | ||
|
||
test_that("values property has a class of AsIs", { | ||
p <- plot_ly( | ||
dimensions = list( | ||
list(label = "A", values = 3), | ||
list(label = "B", values = 8) | ||
), | ||
type = "parcoords" | ||
) | ||
l <- expect_traces(p, 1, "parcoords-data-array") | ||
tr <- l$data[[1]]$dimensions | ||
expect_true(inherits(tr[[1]]$values, "AsIs")) | ||
expect_true(inherits(tr[[2]]$values, "AsIs")) | ||
}) |
Uh oh!
There was an error while loading. Please reload this page.