Skip to content

Commit e63b5b6

Browse files
committed
merge with master
2 parents f54ffa7 + 9124570 commit e63b5b6

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
* `subplot()` now bumps annotation `xref`/`yref` anchors correctly (#1181).
1717
* `subplot()` now accumulates images, repositions paper coordinates, and reanchors axis references (#1332).
18+
* Information emitted by in `event_data()` for heatmaps with atomic vectors for `x`/`y`/`z` is now correct (#1141).
19+
* Fixed issue where **dplyr** groups caused a problem in the ordering of data arrays passed to `marker` objects (#1351).
1820
* In some cases, a `ggplotly()` colorbar would cause issues with hover behavior, which is now fixed (#1381).
1921
* Recursive attribute validation is now only performed on recursive objects (#1315).
2022

R/plotly_build.R

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,24 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
131131
class = oldClass(x)
132132
)
133133

134+
# determine trace type (if not specified, can depend on the # of data points)
135+
# note that this should also determine a sensible mode, if appropriate
136+
trace <- verify_type(trace)
137+
# verify orientation of boxes/bars
138+
trace <- verify_orientation(trace)
139+
134140
# attach crosstalk info, if necessary
135141
if (crosstalk_key() %in% names(dat) && isTRUE(trace[["inherit"]] %||% TRUE)) {
136142
trace[["key"]] <- trace[["key"]] %||% dat[[crosstalk_key()]]
137143
trace[["set"]] <- trace[["set"]] %||% attr(dat, "set")
138144
}
139145

140146
# if appropriate, tack on a group index
141-
grps <- tryCatch(
142-
as.character(dplyr::groups(dat)),
143-
error = function(e) character(0)
144-
)
145-
147+
grps <- if (has_group(trace)) tryNULL(dplyr::group_vars(dat))
146148
if (length(grps) && any(lengths(trace) == NROW(dat))) {
147149
trace[[".plotlyGroupIndex"]] <- interaction(dat[, grps, drop = F])
148150
}
149151

150-
# determine trace type (if not specified, can depend on the # of data points)
151-
# note that this should also determine a sensible mode, if appropriate
152-
trace <- verify_type(trace)
153-
# verify orientation of boxes/bars
154-
trace <- verify_orientation(trace)
155-
156152
# add sensible axis names to layout
157153
for (i in c("x", "y", "z")) {
158154
nm <- paste0(i, "axis")

inst/htmlwidgets/plotly.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,15 @@ HTMLWidgets.widget({
243243
var gd = document.getElementById(el.id);
244244
var trace = gd.data[pt.curveNumber];
245245

246-
// Add other attributes here, if desired
246+
// Heatmap z event data should derive from _z calc attribute
247+
// https://github.com/ropensci/plotly/issues/1141
248+
var z = trace.type === "heatmap" ? "_z" : "z";
247249
if (!trace._isSimpleKey) {
248-
var attrsToAttach = ["key", "z"];
250+
var attrsToAttach = ["key", z];
249251
} else {
250252
// simple keys fire the whole key
251253
obj.key = trace.key;
252-
var attrsToAttach = ["z"];
254+
var attrsToAttach = [z];
253255
}
254256

255257
for (var i = 0; i < attrsToAttach.length; i++) {

tests/figs/plotly-group/plotly-no-nas-for-irrelevant-group.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/plotly-group/simple-scatter-marker-color-group.svg

Lines changed: 1 addition & 0 deletions
Loading

tests/testthat/test-plotly-group.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,22 @@ test_that("Groups are ignored if grouping is irrelevant for the geom", {
6565
expect_length(l$data[[1]][["x"]], 32)
6666
expect_length(l$data[[1]][["y"]], 32)
6767
})
68+
69+
70+
test_that("Ordering of marker.color should not change in a simple scatterplot", {
71+
72+
# https://github.com/ropensci/plotly/issues/1351
73+
l <- mtcars %>%
74+
mutate(id = seq_len(nrow(.))) %>%
75+
group_by(cyl) %>%
76+
plot_ly(
77+
x = ~mpg, y = ~wt, text = ~id,
78+
marker = list(color = ~ifelse(id == 1, "black", "red")),
79+
mode = "marker+text", textposition = "right"
80+
) %>%
81+
expect_doppelganger_built("simple-scatter-marker-color-group")
82+
83+
expect_true(
84+
all(l$data[[1]]$marker$color == c("black", rep("red", 31)))
85+
)
86+
})

0 commit comments

Comments
 (0)