Skip to content

Commit 57de369

Browse files
committed
merge conflicts
2 parents fa8ab30 + 379b0f0 commit 57de369

14 files changed

+410
-53
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ Rapp.history
55
.Rhistory
66
.RData
77
Makefile
8+
.Rproj.user
9+
*.Rproj

.push_test_table.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# -----------------------------------------------------------------------
4+
# When pushing to a pull request on GitHub, Travis does two builds:
5+
# (1) One for the pull request itself. In this case, $TRAVIS_PULL_REQUEST
6+
# is 'false' and $TRAVIS_BRANCH contains the branch name
7+
# (2) One to *simulate* a merge with master. In this case, $TRAVIS_PULL_REQUEST
8+
# is the pull ID number and $TRAVIS_BRANCH = 'master'
9+
#
10+
# Read more about Travis environment variables --
11+
# http://docs.travis-ci.com/user/ci-environment/
12+
# -----------------------------------------------------------------------
13+
14+
# Only build test table if $TRAVIS_PULL_REQUEST is false
15+
[ "${TRAVIS_PULL_REQUEST}" != "false" ] && exit 0
16+
17+
git config --global user.name "cpsievert"
18+
git config --global user.email "[email protected]"
19+
20+
# Since Travis does `git clone --branch=$TRAVIS_BRANCH --depth=50`,
21+
# we can't simply `git checkout master`. As far as I can tell, we are
22+
# forced to re-clone -- https://gist.github.com/cpsievert/698c7f1404f972782e71
23+
24+
cd ..
25+
rm -rf plotly/
26+
git clone https://github.com/ropensci/plotly.git
27+
cd plotly
28+
echo "user,SHA1,label" >> ../code_commits.csv
29+
echo "ropensci,`git rev-parse HEAD`,master" >> ../code_commits.csv
30+
git checkout $TRAVIS_BRANCH
31+
echo "ropensci,`git rev-parse HEAD`,${TRAVIS_BRANCH}" >> ../code_commits.csv
32+
Rscript -e "devtools::install()"
33+
34+
cd ..
35+
git clone https://github.com/ropensci/plotly-test-table.git
36+
cd plotly-test-table
37+
git checkout gh-pages
38+
39+
mv ../code_commits.csv .
40+
cat code_commits.csv
41+
make
42+
43+
# add, commit, push to gh-pages branch of plotly-test-table
44+
git add tables/*/*.html data/*/*.png
45+
git commit -a -m "Travis build number ${TRAVIS_BUILD_NUMBER} of ${TRAVIS_REPO_SLUG}"
46+
# This post explains how this works -- http://rmflight.github.io/posts/2014/11/travis_ci_gh_pages.html
47+
GH_REPO="@github.com/ropensci/plotly-test-table.git"
48+
FULL_REPO="https://${GH_TOKEN}${GH_REPO}"
49+
git pull $FULL_REPO gh-pages
50+
git push $FULL_REPO gh-pages

.travis.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
language: c
2-
script: "./travis-tool.sh run_tests"
2+
env:
3+
global:
4+
- secure: "cJ1bDRrAdIRjG+JnsQI9CdA4wQJhJJ2DdCNQ3frl8dotk69z61EiGCFW1Ir1cAY5V/NbHvFHp91HDiSo28ggwqRkEPBOGE44ico5gtVaELu3M/EnkWc2ZwQoN1273Vfdm26QYidqrvWrpLZ0XkFl7Q8xgvBswx30MF7y61+0Hv4="
35
before_script:
46
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
57
- chmod 755 ./travis-tool.sh
6-
- "./travis-tool.sh bootstrap"
7-
- "./travis-tool.sh install_deps - ./travis-tool.sh install_r RCurl RJSONIO lattice"
8+
- chmod 755 ./.push_test_table.sh
9+
- ./travis-tool.sh bootstrap
10+
- ./travis-tool.sh install_deps
11+
- ./travis-tool.sh install_r RCurl RJSONIO lattice xtable
12+
script:
13+
- ./travis-tool.sh run_tests
14+
after_success:
15+
- ./.push_test_table.sh
816
notifications:
917
slack:
1018
secure: YvyGtGRFC4HJGD4d2Vx6fHU93EliJCHbcf/k9/Rbpl3wtYFZfWKbKL1FHvPw/g3auVebonz8hScnYzR0uYnR3dHSlmj3QrJ3NOePv5QAZRHy7aY/XKRr5JR1Ji/vX1yfbrJDmiYuGMxJVE8l/kbu0TxwDdLletY5nJpwlkHfaW8=

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: plotly
22
Type: Package
33
Title: Interactive, publication-quality graphs online.
4-
Version: 0.5.21
4+
Version: 0.5.22
55
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"),
66
email = "[email protected]"),
77
person("Scott", "Chamberlain", role = "aut",

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.5.22 -- 2 March 2015.
2+
3+
Fixes for ylim() #171.
4+
15
0.5.21 -- 23 February 2015.
26

37
Fixes for error bars and tick marks.

R/ggplotly.R

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ gg2list <- function(p){
6969
}
7070
# Always use identity size scale so that plot.ly gets the real
7171
# units for the size variables.
72+
original.p <- p
7273
p <- tryCatch({
7374
# this will be an error for discrete variables.
7475
suppressMessages({
@@ -117,7 +118,8 @@ gg2list <- function(p){
117118
ggsizemin <- min(unlist(sizerange))
118119
ggsizemax <- max(unlist(sizerange))
119120
}
120-
121+
122+
layer.legends <- list()
121123
for(i in seq_along(built$plot$layers)){
122124
# This is the layer from the original ggplot object.
123125
L <- p$layers[[i]]
@@ -134,14 +136,14 @@ gg2list <- function(p){
134136
# sent to plotly as characters, not as numeric data (which is
135137
# what ggplot_build gives us).
136138
misc <- list()
137-
for(a in c("fill", "colour", "x", "y")){
139+
for(a in c("fill", "colour", "x", "y", "size")){
138140
for(data.type in c("continuous", "date", "datetime", "discrete")){
139141
fun.name <- sprintf("scale_%s_%s", a, data.type)
140142
misc.name <- paste0("is.", data.type)
141143
misc[[misc.name]][[a]] <- tryCatch({
142144
fun <- get(fun.name)
143145
suppressMessages({
144-
with.scale <- p+fun()
146+
with.scale <- original.p + fun()
145147
})
146148
ggplot_build(with.scale)
147149
TRUE
@@ -152,13 +154,16 @@ gg2list <- function(p){
152154
}
153155

154156
# scales are needed for legend ordering.
157+
misc$breaks <- list()
155158
for(sc in p$scales$scales){
156-
a <- sc$aesthetics
157-
if(length(a) == 1){
159+
a.vec <- sc$aesthetics
160+
default.breaks <- inherits(sc$breaks, "waiver")
161+
if (length(a.vec) == 1 && (!default.breaks) ) {
162+
# TODO: generalize for x/y scales too.
158163
br <- sc$breaks
159164
ranks <- seq_along(br)
160165
names(ranks) <- br
161-
misc$breaks[[sc$aesthetics]] <- ranks
166+
misc$breaks[[a.vec]] <- ranks
162167
}
163168
## store if this is a reverse scale so we can undo that later.
164169
if(is.character(sc$trans$name)){
@@ -205,6 +210,10 @@ gg2list <- function(p){
205210

206211
# This extracts essential info for this geom/layer.
207212
traces <- layer2traces(L, df, misc)
213+
214+
possible.legends <- markLegends[[L$geom$objname]]
215+
actual.legends <- possible.legends[possible.legends %in% names(L$mapping)]
216+
layer.legends[[paste(i)]] <- actual.legends
208217

209218
# Do we really need to coord_transform?
210219
# g$data <- ggplot2:::coord_transform(built$plot$coord, g$data,
@@ -308,17 +317,33 @@ gg2list <- function(p){
308317
ax.list$tickangle <- -tick.text$angle
309318
}
310319
ax.list$tickfont <- theme2font(tick.text)
320+
321+
## determine axis type first, since this information is used later
322+
## (trace.order.list is only used for type=category).
323+
title.text <- e(s("axis.title.%s"))
324+
ax.list$titlefont <- theme2font(title.text)
325+
ax.list$type <- if (misc$is.continuous[[xy]]){
326+
"linear"
327+
} else if (misc$is.discrete[[xy]]){
328+
"category"
329+
} else if (misc$is.date[[xy]] || misc$is.datetime[[xy]]){
330+
"date"
331+
} else {
332+
stop("unrecognized data type for ", xy, " axis")
333+
}
311334

312335
# Translate axes labels.
313336
scale.i <- which(p$scales$find(xy))
314337
ax.list$title <- if(length(scale.i)){
315338
sc <- p$scales$scales[[scale.i]]
316-
trace.order.list[[xy]] <- sc$limits
317-
if(is.character(sc$breaks)){
318-
if(is.character(sc$labels)){
319-
trace.name.map[sc$breaks] <- sc$labels
339+
if(ax.list$type == "category"){
340+
trace.order.list[[xy]] <- sc$limits
341+
if(is.character(sc$breaks)){
342+
if(is.character(sc$labels)){
343+
trace.name.map[sc$breaks] <- sc$labels
344+
}
345+
##TODO: if(is.function(sc$labels)){
320346
}
321-
##TODO: if(is.function(sc$labels)){
322347
}
323348
if (is.null(sc$breaks)) {
324349
ax.list$showticklabels <- FALSE
@@ -354,18 +379,6 @@ gg2list <- function(p){
354379
p$labels[[xy]]
355380
}
356381

357-
title.text <- e(s("axis.title.%s"))
358-
ax.list$titlefont <- theme2font(title.text)
359-
ax.list$type <- if(misc$is.continuous[[xy]]){
360-
"linear"
361-
}else if(misc$is.discrete[[xy]]){
362-
"category"
363-
}else if(misc$is.date[[xy]] || misc$is.datetime[[xy]]){
364-
"date"
365-
}else{
366-
stop("unrecognized data type for ", xy, " axis")
367-
}
368-
369382
ax.list$zeroline <- FALSE # ggplot2 plots do not show zero lines
370383
# Lines drawn around the plot border.
371384
ax.list$showline <- !is.blank("panel.border", TRUE)
@@ -532,7 +545,27 @@ gg2list <- function(p){
532545
if (any(names(layer.aes) %in% markUnique[markUnique != "x"]) == FALSE)
533546
layout$showlegend <- FALSE
534547

535-
if (layout$showlegend && length(p$data)) {
548+
## Legend hiding when guides(fill="none").
549+
legends.present <- unique(unlist(layer.legends))
550+
is.false <- function(x){
551+
is.logical(x) && length(x) == 1 && x == FALSE
552+
}
553+
is.none <- function(x){
554+
is.character(x) && length(x) == 1 && x == "none"
555+
}
556+
is.hidden <- function(x){
557+
is.false(x) || is.none(x)
558+
}
559+
for(a in legends.present){
560+
if(is.hidden(p$guides[[a]])){
561+
layout$showlegend <- FALSE
562+
}
563+
}
564+
565+
# Only show a legend title if there is at least 1 trace with
566+
# showlegend=TRUE.
567+
trace.showlegend <- sapply(trace.list, "[[", "showlegend")
568+
if (any(trace.showlegend) && layout$showlegend && length(p$data)) {
536569
# Retrieve legend title
537570
legend.elements <- sapply(traces, "[[", "name")
538571
legend.title <- ""
@@ -691,7 +724,13 @@ gg2list <- function(p){
691724
}
692725

693726
# Put the traces in correct order, according to any manually
694-
# specified scales.
727+
# specified scales. This seems to be repetitive with the trace$rank
728+
# attribute in layer2traces (which is useful for sorting traces that
729+
# get different legend entries but come from the same geom, as in
730+
# test-ggplot-legend.R), but in fact this is better since it could
731+
# be used for sorting traces that come from different geoms
732+
# (currently we don't have a test for this). TODO: write such a
733+
# test, delete the trace$rank code, and have it work here instead.
695734
trace.order <- unlist(trace.order.list)
696735
ordered.traces <- if(length(trace.order)){
697736
trace.order.score <- seq_along(trace.order)

R/trace_generation.R

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,24 @@ layer2traces <- function(l, d, misc) {
210210
}
211211
}
212212
name.names <- grep("[.]name$", names(data.params$params), value=TRUE)
213-
if (length(name.names)) {
214-
for(a.name in name.names){
213+
not.group <- grep("group", name.names, value=TRUE, invert=TRUE)
214+
if (length(not.group)) {
215+
for(a.name in not.group){
215216
a <- sub("[.]name$", "", a.name)
216-
a.value <- as.character(data.params$params[[a.name]])
217-
ranks <- misc$breaks[[a]]
218-
if(length(ranks)){
219-
tr$sort[[a.name]] <- ranks[[a.value]]
217+
tr$sort[[a.name]] <- if (a %in% names(misc$breaks)){
218+
# Custom breaks were specified.
219+
a.value <- as.character(data.params$params[[a.name]])
220+
ranks <- misc$breaks[[a]]
221+
if (a.value %in% names(ranks)){
222+
ranks[[a.value]]
223+
} else {
224+
Inf # sorts to the end, when there are less breaks than classes.
225+
}
226+
} else { # custom breaks were not specified.
227+
1 # sort them all the same.
220228
}
221229
}
222-
name.list <- data.params$params[name.names]
230+
name.list <- data.params$params[not.group]
223231
tr$name <- paste(unlist(name.list), collapse=".")
224232
if (length(unique(name.list)) < 2)
225233
tr$name <- as.character(name.list[[1]])
@@ -257,14 +265,25 @@ layer2traces <- function(l, d, misc) {
257265
0
258266
}
259267
})
260-
268+
261269
ord <- order(sort.val)
262270
no.sort <- traces[ord]
263271
for(tr.i in seq_along(no.sort)){
272+
s <- no.sort[[tr.i]]$sort
273+
no.sort[[tr.i]]$showlegend <-
274+
if (is.numeric(s)) {
275+
if (s == Inf){
276+
FALSE
277+
} else {
278+
TRUE
279+
}
280+
} else { # no legend.
281+
FALSE
282+
}
264283
no.sort[[tr.i]]$sort <- NULL
265284
}
266285
no.sort
267-
}
286+
}#layer2traces
268287

269288

270289
# Preprocess data and params.
@@ -309,7 +328,10 @@ toBasic <- list(
309328
bar=function(g) {
310329
if (any(is.na(g$prestats.data$x)))
311330
g$prestats.data$x <- g$prestats.data$x.name
312-
g$prestats.data$fill <- g$data$fill[match(g$prestats.data$group, g$data$group)]
331+
for(a in c("fill", "colour")){
332+
g$prestats.data[[a]] <-
333+
g$data[[a]][match(g$prestats.data$group, g$data$group)]
334+
}
313335
g$params$xstart <- min(g$data$xmin)
314336
g$params$xend <- max(g$data$xmax)
315337
g$data <- g$prestats.data

tests/testthat/test-ggplot-abline.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ test_that("Second trace be the a-b line", {
1111
geom_abline(intercept=1.1, slope=0.9, colour="red", size=4)
1212

1313
L <- gg2list(gg)
14-
14+
1515
expect_equal(length(L), 3)
1616
expect_true(L[[2]]$x[1] <= 0)
1717
expect_true(L[[2]]$x[2] >= 3.5)
1818
expect_identical(L[[2]]$mode, "lines")
1919
expect_identical(L[[2]]$line$shape, "linear")
2020
expect_equal(L[[2]]$line$width, 8)
2121

22+
expect_identical(L[[1]]$showlegend, FALSE)
23+
expect_identical(L[[2]]$showlegend, FALSE)
24+
2225
save_outputs(gg, "abline")
2326
})

0 commit comments

Comments
 (0)