Skip to content

Commit c40657a

Browse files
committed
Fix. Add special treatment of dimensions attrbute to account for the 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
1 parent 3cf17c0 commit c40657a

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
* Closed #2337: Creating a new `event_data()` handler no longer causes a spurious reactive update of existing `event_data()`s. (#2339)
1414

15+
* Closed #2385: `"parcoords"`, `"parcats"` and `"splom"` traces now work with one-dimensional data by accounting for the "data_array" property of the "values" attribute of "dimensions".
16+
1517
# 4.10.4
1618

1719
## Improvements

R/utils.R

+9-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,15 @@ verify_attr <- function(proposed, schema, layoutAttr = FALSE) {
551551

552552
# do the same for "sub-attributes"
553553
if (identical(role, "object") && is.recursive(proposed[[attr]])) {
554-
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr)
554+
# The "dimensions" attribute requires a special treatment as
555+
# it is an unnamed list and hence will be skipped by `for (attr in names(proposed))
556+
if (attr == "dimensions") {
557+
proposed[[attr]] <- lapply(proposed[[attr]], \(x) {
558+
verify_attr(x, attrSchema$items$dimension, layoutAttr = layoutAttr)
559+
})
560+
} else {
561+
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr)
562+
}
555563
}
556564
}
557565

tests/testthat/test-plotly-parcats.R

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
expect_traces <- function(p, n.traces, name) {
2+
stopifnot(is.numeric(n.traces))
3+
L <- expect_doppelganger_built(p, paste0("plotly-", name))
4+
expect_equivalent(length(L$data), n.traces)
5+
L
6+
}
7+
8+
test_that("values property has a class of AsIs", {
9+
p <- plot_ly(
10+
dimensions = list(
11+
list(values = "A"),
12+
list(values = "B")
13+
),
14+
type = "parcats"
15+
)
16+
l <- expect_traces(p, 1, "parcats-data-array")
17+
tr <- l$data[[1]]$dimensions
18+
expect_true(inherits(tr[[1]]$values, "AsIs"))
19+
expect_true(inherits(tr[[2]]$values, "AsIs"))
20+
})
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
expect_traces <- function(p, n.traces, name) {
2+
stopifnot(is.numeric(n.traces))
3+
L <- expect_doppelganger_built(p, paste0("plotly-", name))
4+
expect_equivalent(length(L$data), n.traces)
5+
L
6+
}
7+
8+
test_that("values property has a class of AsIs", {
9+
p <- plot_ly(
10+
dimensions = list(
11+
list(label = "A", values = 3),
12+
list(label = "B", values = 8)
13+
),
14+
type = "parcoords"
15+
)
16+
l <- expect_traces(p, 1, "parcoords-data-array")
17+
tr <- l$data[[1]]$dimensions
18+
expect_true(inherits(tr[[1]]$values, "AsIs"))
19+
expect_true(inherits(tr[[2]]$values, "AsIs"))
20+
})

tests/testthat/test-plotly-splom.R

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
2-
1+
expect_traces <- function(p, n.traces, name) {
2+
stopifnot(is.numeric(n.traces))
3+
L <- expect_doppelganger_built(p, paste0("plotly-", name))
4+
expect_equivalent(length(L$data), n.traces)
5+
L
6+
}
37

48
test_that("No cartesian axes are supplied to a splom chart", {
59

@@ -12,3 +16,17 @@ test_that("No cartesian axes are supplied to a splom chart", {
1216
)
1317

1418
})
19+
20+
test_that("values property has a class of AsIs", {
21+
p <- plot_ly(
22+
type = "splom",
23+
dimensions = list(
24+
list(values = 1, label = "A"),
25+
list(values = 2, label = "B")
26+
)
27+
)
28+
l <- expect_traces(p, 1, "parcats-data-array")
29+
tr <- l$data[[1]]$dimensions
30+
expect_true(inherits(tr[[1]]$values, "AsIs"))
31+
expect_true(inherits(tr[[2]]$values, "AsIs"))
32+
})

0 commit comments

Comments
 (0)