Skip to content

Commit 0581ef5

Browse files
cpsievertclaude
andcommitted
Fix #2446: Date class preserved in colorbar trace
The colorbar trace now preserves Date/POSIXct classes when computing x/y ranges. Previously, unlist() converted Date objects to numeric (days since epoch), which could confuse plotly.js axis handling. Changed to use do.call(c, ...) which preserves the original class. Fixes #2446 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4be6198 commit 0581ef5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

R/plotly_build.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,10 @@ map_color <- function(traces, stroke = FALSE, title = "", colorway, na.color = "
877877
# add an "empty" trace with the colorbar
878878
colorObj$color <- rng
879879
colorObj$showscale <- default(TRUE)
880+
# Use do.call(c, ...) instead of unlist() to preserve Date/POSIXct classes
880881
colorBarTrace <- list(
881-
x = range(unlist(lapply(traces, "[[", "x")), na.rm = TRUE),
882-
y = range(unlist(lapply(traces, "[[", "y")), na.rm = TRUE),
882+
x = range(do.call(c, lapply(traces, "[[", "x")), na.rm = TRUE),
883+
y = range(do.call(c, lapply(traces, "[[", "y")), na.rm = TRUE),
883884
type = if (any(types %in% glTypes())) "scattergl" else "scatter",
884885
mode = "markers",
885886
opacity = 0,
@@ -890,7 +891,7 @@ map_color <- function(traces, stroke = FALSE, title = "", colorway, na.color = "
890891
# 3D needs a z property
891892
if ("scatter3d" %in% types) {
892893
colorBarTrace$type <- "scatter3d"
893-
colorBarTrace$z <- range(unlist(lapply(traces, "[[", "z")), na.rm = TRUE)
894+
colorBarTrace$z <- range(do.call(c, lapply(traces, "[[", "z")), na.rm = TRUE)
894895
}
895896
if (length(type <- intersect(c("scattergeo", "scattermapbox"), types))) {
896897
colorBarTrace$type <- type

0 commit comments

Comments
 (0)