Skip to content

Commit fc7da4f

Browse files
committed
Sketch framework to support barmode conversion
1 parent 03db5fa commit fc7da4f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

R/ggplotly.R

+13-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ aesConverters <-
100100
toRGB(col)
101101
},size=identity,alpha=identity,shape=function(pch){
102102
pch2symbol[as.character(pch)]
103+
}, barmode=function(bm) {
104+
position2barmode[bm][[1]]
103105
})
104106

105107
toBasic <-
@@ -170,7 +172,10 @@ geom2trace <-
170172
list(x=data$x,
171173
y=data$y,
172174
name=params$name,
173-
type="bar")
175+
text=data$text,
176+
type="bar",
177+
# barmode=paramORdefault(...),
178+
fillcolor=toRGB(params$fill))
174179
}
175180
)
176181

@@ -184,7 +189,7 @@ markLegends <-
184189
list(point=c("colour", "fill", "shape"),
185190
path=c("linetype", "size", "colour"),
186191
polygon=c("colour", "fill", "linetype", "size", "group"),
187-
bar=c("fill"))
192+
bar=c("fill", "barmode"))
188193

189194
markUnique <- as.character(unique(unlist(markLegends)))
190195

@@ -373,6 +378,8 @@ gg2list <- function(p){
373378
layout$margin$r <- 10
374379
layout$legend <- list(bordercolor="transparent", x=100, y=1/2)
375380

381+
## Barmode.
382+
# layout$barmode <- position2barmode[...][[1]]
376383
trace.list$kwargs <- list(layout=layout)
377384
trace.list
378385
}
@@ -572,3 +579,7 @@ toRGB <- function(x){
572579
ifelse(is.na(x), "none", rgb.css)
573580
}
574581

582+
#' Convert R position to plotly barmode
583+
position2barmode <- c("stack"="stack",
584+
"dodge"="group",
585+
"identity"="overlay")

inst/tests/test-ggplot-bar.R

-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ test_that("position_identity is translated to barmode=overlay", {
3434
expect_true(all(c("Math", "Bio") %in% trace.names))
3535
expect_identical(L$kwargs$layout$barmode, "overlay")
3636
})
37-

0 commit comments

Comments
 (0)