Skip to content

Commit f0c815b

Browse files
committed
Merge branch 'master' into async
2 parents 4b40e5b + 742a70b commit f0c815b

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

NEWS.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@
4848
### `plot_ly()` specific fixes
4949

5050
* The `limits` argument of `colorbar()` wasn't being applied to `line.color`/`line.cmin`/`line.cmax` (#1236).
51+
* The `legendgroup` can now properly map data values (#1148).
5152

5253
### Other fixes relevant for all **plotly** objects
5354

5455
* Bug fix for linking views with crosstalk where the source of the selection is an aggregated trace (#1218).
56+
* Resizing behavior, after updating `height`/`width` via **shiny** reactive values, is now correct (#1068).
5557
* Fixed algorithm for coercing the proposed layout to the plot schema (#1156).
5658
* `add_*()` no longer inherits `crosstalk::SharedData` key information when `inherit = FALSE` (#1242).
5759

5860

59-
6061
# 4.7.1
6162

6263
## NEW FEATURES & IMPROVEMENTS

R/plotly_build.R

+2-6
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
189189
dataArrayAttrs, special_attrs(trace), npscales(), "frame",
190190
# for some reason, text isn't listed as a data array in some traces
191191
# I'm looking at you scattergeo...
192-
".plotlyGroupIndex", "text", "key", "fillcolor", "name"
192+
".plotlyGroupIndex", "text", "key", "fillcolor", "name", "legendgroup"
193193
)
194194
tr <- trace[names(trace) %in% allAttrs]
195195
# TODO: does it make sense to "train" matrices/2D-tables (e.g. z)?
@@ -210,11 +210,7 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
210210
if (any(isSplit)) {
211211
paste2 <- function(x, y) if (identical(x, y)) x else paste(x, y, sep = br())
212212
splitVars <- builtData[isSplit]
213-
traceIndex <- Reduce(paste2, splitVars)
214-
if (!is.null(trace$name)) {
215-
traceIndex <- paste2(traceIndex, trace$name)
216-
}
217-
builtData[[".plotlyTraceIndex"]] <- traceIndex
213+
builtData[[".plotlyTraceIndex"]] <- Reduce(paste2, splitVars)
218214
# in registerFrames() we need to strip the frame from .plotlyTraceIndex
219215
# so keep track of which variable it is...
220216
trace$frameOrder <- which(names(splitVars) %in% "frame")

R/utils.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ verify_attr <- function(proposed, schema) {
492492
proposed[[attr]] <- structure(proposed[[attr]], apiSrc = TRUE)
493493
}
494494

495-
if (length(proposed$name) > 0) {
495+
if (length(proposed[["name"]]) > 0) {
496496
proposed$name <- uniq(proposed$name)
497497
}
498498

tests/testthat/test-plotly.R

+28
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,31 @@ test_that("Vector of redundant text is reduced to string when hoveron=fills", {
251251
d[[2]]$text == '<br> <b>Example</b> of <em>custom</em> hover text <br> B <br> xyz <br>.'
252252
)
253253
})
254+
255+
256+
test_that("Can map data to legendgroup", {
257+
d <- data.frame(
258+
x = 1:100,
259+
y = runif(100),
260+
group = letters[1:5]
261+
)
262+
263+
l <- plot_ly(data = d, x = ~x, y = ~y) %>%
264+
add_bars(color = ~group, legendgroup = ~group) %>%
265+
add_markers(color = ~group, legendgroup = ~group) %>%
266+
plotly_build()
267+
268+
expect_length(l$x$data, 10)
269+
270+
markers <- compact(lapply(l$x$data, function(tr) if (tr$type == "scatter") tr))
271+
for (i in seq_along(markers)) {
272+
expect_length(markers[[i]]$legendgroup, 1)
273+
expect_true(markers[[i]]$legendgroup == letters[[i]])
274+
}
275+
276+
bars <- compact(lapply(l$x$data, function(tr) if (tr$type == "bar") tr))
277+
for (i in seq_along(bars)) {
278+
expect_length(bars[[i]]$legendgroup, 1)
279+
expect_true(bars[[i]]$legendgroup == letters[[i]])
280+
}
281+
})

0 commit comments

Comments
 (0)