Skip to content

Commit a942aaf

Browse files
committed
Merge branch 'master' into relative-dependency-paths
2 parents c20823d + 4cca561 commit a942aaf

17 files changed

+88
-32
lines changed

NEWS.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
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-
* In some cases, a `ggplotly()` colorbar would cause issues with hover behavior, which is now fixed (#1381).
18+
* `event_data("plotly_selected")` is no longer too eager to clear. That is, it is no longer set to `NULL` when clicking on a plot *after* triggering the "plotly_selected" event (#1121) (#1122).
19+
* The colorscale generated via the `color` argument in `plot_ly()` now uses an evenly spaced grid of values instead of quantiles (#1308).
20+
* The `color` and `stroke` arguments now work as expected for trace types with `fillcolor` but no `fill` attribute (e.g. `box` traces) (#1292).
21+
* Information emitted by in `event_data()` for heatmaps with atomic vectors for `x`/`y`/`z` is now correct (#1141).
22+
* Fixed issue where **dplyr** groups caused a problem in the ordering of data arrays passed to `marker` objects (#1351).
23+
* In some cases, a `ggplotly()` colorbar would cause issues with hover behavior, which is now fixed (#1381).
24+
* An articial marker no longer appears when clearing a crosstalk selection of a plot with a colorbar (#1406).
1925
* Recursive attribute validation is now only performed on recursive objects (#1315).
2026

2127
# 4.8.0

R/plotly_build.R

Lines changed: 18 additions & 13 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")
@@ -775,7 +771,7 @@ map_color <- function(traces, stroke = FALSE, title = "", colorway, na.color = "
775771
colScale <- scales::col_numeric(pal, rng, na.color = na.color)
776772
# generate the colorscale to be shared across traces
777773
vals <- if (diff(rng) > 0) {
778-
as.numeric(stats::quantile(allColor, probs = seq(0, 1, length.out = 25), na.rm = TRUE))
774+
seq(rng[1], rng[2], length.out = 25)
779775
} else {
780776
c(0, 1)
781777
}
@@ -1005,4 +1001,13 @@ supplyUserPalette <- function(default, user) {
10051001

10061002
# helper functions
10071003
array_ok <- function(attr) isTRUE(tryNULL(attr$arrayOk))
1008-
has_fill <- function(trace) isTRUE(trace$fill %in% c('tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'))
1004+
has_fill <- function(trace) {
1005+
trace_type <- trace[["type"]] %||% "scatter"
1006+
# if trace type has fillcolor, but no fill attribute, then fill is always relevant
1007+
has_fillcolor <- has_attr(trace_type, "fillcolor")
1008+
has_fill <- has_attr(trace_type, "fill")
1009+
if (has_fillcolor && !has_fill) return(TRUE)
1010+
fill <- trace[["fill"]] %||% "none"
1011+
if (has_fillcolor && isTRUE(fill != "none")) return(TRUE)
1012+
FALSE
1013+
}

inst/htmlwidgets/plotly.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ HTMLWidgets.widget({
230230
x: pt.x,
231231
y: pt.y
232232
};
233+
234+
// If 'z' is reported with the event data, then use it!
235+
if (pt.hasOwnProperty("z")) {
236+
obj.z = pt.z;
237+
}
238+
233239
/*
234240
TL;DR: (I think) we have to select the graph div (again) to attach keys...
235241
@@ -243,13 +249,12 @@ HTMLWidgets.widget({
243249
var gd = document.getElementById(el.id);
244250
var trace = gd.data[pt.curveNumber];
245251

246-
// Add other attributes here, if desired
247252
if (!trace._isSimpleKey) {
248-
var attrsToAttach = ["key", "z"];
253+
var attrsToAttach = ["key"];
249254
} else {
250255
// simple keys fire the whole key
251256
obj.key = trace.key;
252-
var attrsToAttach = ["z"];
257+
var attrsToAttach = [];
253258
}
254259

255260
for (var i = 0; i < attrsToAttach.length; i++) {
@@ -287,10 +292,18 @@ HTMLWidgets.widget({
287292
);
288293
});
289294
graphDiv.on('plotly_selected', function(d) {
290-
Shiny.onInputChange(
291-
".clientValue-plotly_selected-" + x.source,
292-
JSON.stringify(eventDataWithKey(d))
293-
);
295+
// If 'plotly_selected' has already been fired, and you click
296+
// on the plot afterwards, this event fires `undefined`?!?
297+
// That might be considered a plotly.js bug, but it doesn't make
298+
// sense for this input change to occur if `d` is falsy because,
299+
// even in the empty selection case, `d` is truthy (an object),
300+
// and the 'plotly_deselect' event will reset this input
301+
if (d) {
302+
Shiny.onInputChange(
303+
".clientValue-plotly_selected-" + x.source,
304+
JSON.stringify(eventDataWithKey(d))
305+
);
306+
}
294307
});
295308
graphDiv.on('plotly_unhover', function(eventData) {
296309
Shiny.onInputChange(".clientValue-plotly_hover-" + x.source, null);
@@ -520,7 +533,7 @@ function TraceManager(graphDiv, highlight) {
520533
// avoid doing this over and over
521534
this.origOpacity = [];
522535
for (var i = 0; i < this.origData.length; i++) {
523-
this.origOpacity[i] = this.origData[i].opacity || 1;
536+
this.origOpacity[i] = this.origData[i].opacity === 0 ? 0 : (this.origData[i].opacity || 1);
524537
}
525538

526539
// key: group name, value: null or array of keys representing the

tests/figs/colorbar/plotly-colorbar-expand.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/colorbar/plotly-colorbar-restrict.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/colorbar/plotly-colorbar-z-expand.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/colorbar/plotly-colorbar-z-restrict.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/colorbar/plotly-colorbar.svg

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 0 deletions
Loading

tests/figs/plotly-color/plotly-color-scatterplot-color-numeric-custom.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/plotly-color/plotly-color-scatterplot-color-numeric.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)