Skip to content

Commit 54ce776

Browse files
committed
provide a default colorscale to histogram2d
1 parent 19141eb commit 54ce776

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

R/plotly_build.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ map_size <- function(traces) {
413413
# appends a new (empty) trace to generate (plot-wide) colorbar/colorscale
414414
map_color <- function(traces, title = "", na.color = "transparent") {
415415
color <- lapply(traces, function(x) {
416-
x[["color"]] %||% if (has_attr(x$type, "colorscale")) x[["z"]] else NULL
416+
x[["color"]] %||% if (identical("histogram2d", x[["type"]])) c(0, 1) else if (has_attr(x[["type"]], "colorscale")) x[["z"]] else NULL
417417
})
418418
isConstant <- vapply(color, function(x) inherits(x, "AsIs") || is.null(x), logical(1))
419419
isNumeric <- vapply(color, is.numeric, logical(1)) & !isConstant
@@ -428,7 +428,9 @@ map_color <- function(traces, title = "", na.color = "transparent") {
428428
hasLine <- has_line(types, modes)
429429
hasText <- has_text(types, modes)
430430
hasZ <- has_attr(types, "colorscale") &
431-
any(vapply(traces, function(tr) !is.null(tr$z), logical(1)))
431+
any(vapply(traces, function(tr) {
432+
!is.null(tr[["z"]]) || identical("histogram2d", tr[["type"]])
433+
}, logical(1)))
432434

433435
colorDefaults <- traceColorDefaults()
434436
for (i in which(isConstant)) {

0 commit comments

Comments
 (0)