Skip to content

Fix bar chart conversion for position="dodge" (barmode="group" in Plotly) #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: plotly
Type: Package
Title: Interactive, publication-quality graphs online.
Version: 0.5.2
Version: 0.5.3
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"),
email = "[email protected]"),
person("Scott", "Chamberlain", role = "aut",
Expand Down
19 changes: 18 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
0.5.3 -- 21 October 2014.

Support conversion of geom_bar() with position_dodge().

0.5.2 -- 18 October 2014.

Support aesthetic shape in geom_path() and, hence, geom_line() (conversion).

0.5.1 -- 15 October 2014.

Do not show zero lines by default (as in ggplot2 plots).

0.5.0 -- 15 October 2014.

From now on, version numbers are meaningful again...
Many changes meanwhile, especially support for more geoms.

0.4 -- 7 April 2014.

Re-write geom to trace conversion code.
Expand All @@ -22,4 +39,4 @@ For ggplotly:

Merge ggplotly code.

0.3.5
0.3.5
6 changes: 5 additions & 1 deletion R/trace_generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ layer2traces <- function(l, d, misc) {
}
}
name.names <- grep("[.]name$", names(data.params$params), value=TRUE)
if(length(name.names)){
if (length(name.names)) {
for(a.name in name.names){
a <- sub("[.]name$", "", a.name)
a.value <- as.character(data.params$params[[a.name]])
Expand All @@ -189,6 +189,8 @@ layer2traces <- function(l, d, misc) {
}
name.list <- data.params$params[name.names]
tr$name <- paste(unlist(name.list), collapse=".")
if (length(unique(name.list)) < 2)
tr$name <- as.character(name.list[[1]])
}

dpd <- data.params$data
Expand Down Expand Up @@ -268,6 +270,8 @@ toBasic <- list(
g
},
bar=function(g) {
if (any(is.na(g$prestats.data$x)))
g$prestats.data$x <- g$prestats.data$x.name
g$prestats.data$fill <- g$data$fill[match(g$prestats.data$group, g$data$group)]
g$params$xstart <- min(g$data$xmin)
g$params$xend <- max(g$data$xmax)
Expand Down
7 changes: 4 additions & 3 deletions run_tests_with_outputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ save_outputs <- function(gg, name, ignore_ggplot=FALSE) {
if (!ignore_ggplot) {
ggsave(paste0("test-ggplot-", name, "-ggplot2.png"), plot=gg, w=7, h=5)
}

# save the json
writeLines(getURL(paste0(plotlyUrl, ".json")), paste0("test-ggplot-", name, ".json"))

# Save the json
writeLines(getURL(paste0(plotlyUrl, ".json")), paste0("test-ggplot-", name,
".json"))
}

test_check("plotly")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
library(testthat)
save_outputs <- function(gg, name, ignore_ggplot=FALSE) {
print(paste("running", name))
print(paste("running", name))
}
test_check("plotly")
Binary file removed tests/testthat/test-ggplot-abline-ggplot2.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-abline-plotly.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-area-ggplot2.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-area-plotly.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-bar-dates-ggplot2.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-bar-dates-plotly.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-bar-dodge-ggplot2.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-bar-dodge-plotly.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-bar-identity-ggplot2.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-bar-identity-plotly.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-bar-stack-ggplot2.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-bar-stack-plotly.png
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/testthat/test-ggplot-bar.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ test_that("position_dodge is translated to barmode=group", {
trace.names <- sapply(L[1:2], "[[", "name")
expect_true(all(c("Math", "Bio") %in% trace.names))
expect_identical(L$kwargs$layout$barmode, "group")
# Check x values
expect_identical(as.character(L[[1]]$x[1]), "Canada")
expect_identical(as.character(L[[1]]$x[2]), "Germany")
expect_identical(as.character(L[[2]]$x[1]), "Canada")
expect_identical(as.character(L[[2]]$x[2]), "USA")

save_outputs(gg.dodge, "bar-dodge")
})
Expand Down
Binary file not shown.
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-boxplot-ggplot2.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-boxplot-plotly.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-contour-ggplot2.png
Binary file not shown.
Binary file removed tests/testthat/test-ggplot-contour-plotly.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-date-strings-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-date-strings-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-density-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-density-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-density2d-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-density2d-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-errorbar-ggplot2.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-errorbar-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-heatmap-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-heatmap-plotly.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-hline-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-hline-plotly.png
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-labels-angles-plotly.png
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-labels-ggtitle-plotly.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-labels-ylab-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-labels-ylab-plotly.png
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-legend-hidden-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-legend-order-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-legend-order-plotly.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-linetype-types-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-names-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-names-plotly.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-path-colors-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-path-colors-plotly.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-ribbon-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-ribbon-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-segment-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-segment-plotly.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-stack-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-stack-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-step-gg.hv-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-step-gg.hv-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-step-gg.hvh-plotly.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-step-gg.vh-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-step-gg.vh-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-step-gg.vhv-plotly.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-text-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-text-plotly.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-violin-ggplot2.png
Diff not rendered.
Binary file removed tests/testthat/test-ggplot-violin-plotly.png
Diff not rendered.