Skip to content

Commit 9ab52e1

Browse files
committed
Resolve merge conflicts with master
2 parents 8f937e0 + d9ecaf4 commit 9ab52e1

11 files changed

+349
-242
lines changed

.push_test_table.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ r_packages:
1212
- httr
1313

1414
before_script:
15-
- chmod 755 ./.push_test_table.sh
15+
- chmod 755 inst/testscripts/.push_test_table.sh
1616

1717
after_success:
18-
- ./.push_test_table.sh
18+
- inst/testscripts/.push_test_table.sh
1919

2020
notifications:
2121
slack:

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.28
4+
Version: 0.5.30
55
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"),
66
email = "[email protected]"),
77
person("Scott", "Chamberlain", role = "aut",

NEWS

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
0.5.28 -- 15 Apr 2015
1+
0.5.30 -- 5 May 2015
22

33
Add test-cookbook-lines.R and fix bugs that showed up in those tests.
44

5+
0.5.29 -- 16 April 2015
6+
7+
geom_density() as filled area chart #202
8+
9+
0.5.28 -- 15 April 2015
10+
11+
Let ggplot handle histogram binning. Fix #198
12+
513
0.5.27 -- 19 Mar 2015
614

715
Reimplement geom_ribbon as a basic polygon. Fix #191. Fix #192.

R/ggplotly.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,41 @@ gg2list <- function(p){
264264
if (!all(barmodes == barmodes[1]))
265265
warning(paste0("You have multiple barcharts or histograms with different positions; ",
266266
"Plotly's layout barmode will be '", layout$barmode, "'."))
267+
# for stacked bar charts, plotly cumulates bar heights, but ggplot doesn't
268+
if (layout$barmode == "stack") {
269+
# could speed up this function with environments or C/C++
270+
unStack <- function(vec) {
271+
n <- length(vec)
272+
if (n == 1) return(vec)
273+
seq.n <- seq_len(n)
274+
names(vec) <- seq.n
275+
vec <- sort(vec)
276+
for (k in seq(2, n)) {
277+
vec[k] <- vec[k] - sum(vec[seq(1, k-1)])
278+
}
279+
as.numeric(vec[as.character(seq.n)])
280+
}
281+
ys <- lapply(trace.list, "[[", "y")
282+
xs <- lapply(trace.list, "[[", "x")
283+
x.vals <- unique(unlist(xs))
284+
# if there are two or more y-values (for a particular x value),
285+
# then modify those y-values so they *add up* to the correct value(s)
286+
for (val in x.vals) {
287+
zs <- lapply(xs, function(x) which(x == val))
288+
ys.given.x <- Map(function(x, y) y[x], zs, ys)
289+
if (length(unlist(ys.given.x)) < 2) next
290+
st <- unStack(unlist(ys.given.x))
291+
lens <- sapply(ys.given.x, length)
292+
trace.seq <- seq_along(trace.list)
293+
ws <- split(st, rep(trace.seq, lens))
294+
for (tr in seq_along(ws)) {
295+
idx <- zs[[tr]]
296+
replacement <- ws[[tr]]
297+
if (length(idx) > 0 && length(replacement) > 0)
298+
trace.list[[tr]]$y[idx] <- replacement
299+
}
300+
}
301+
}
267302
}
268303

269304
# Bar Gap for histograms should be 0

R/trace_generation.R

Lines changed: 32 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,9 @@ layer2traces <- function(l, d, misc) {
4141
g$geom <- "smoothLine"
4242
}
4343
}
44-
# Barmode and bargap
45-
barmode <- "group"
46-
if (g$geom == "bar" || g$geom == "histogram") {
47-
if (l$stat$objname == "bin") {
48-
if (g$geom != "histogram") {
49-
warning("You may want to use geom_histogram.")
50-
}
51-
} else {
52-
bargap <- "default"
53-
}
54-
g$geom <- "bar" # histogram is just an alias for geom_bar + stat_bin
55-
pos <- l$position$.super$objname
56-
if (pos == "identity") {
57-
barmode <- "overlay"
58-
} else if (pos == "stack") {
59-
barmode <- "stack"
60-
}
61-
}
62-
if (g$geom == "density") {
44+
# histogram is essentially a bar chart with no gaps (after stats are computed)
45+
if (g$geom == "histogram") {
46+
g$geom <- "bar"
6347
bargap <- 0
6448
}
6549

@@ -187,15 +171,14 @@ layer2traces <- function(l, d, misc) {
187171
lapply(df.list, function(df){
188172
params <- basic$params
189173
params[invariable.names] <- if (ncol(x <- df[1, invariable.names]) > 0) x else NULL
190-
list(data=df[other.names],
174+
list(data=df[other.names],
191175
params=params)
192176
})
193177
}
194178
}
195-
196179
# Split hline and vline when multiple panels or intercepts:
197180
# Need multiple traces accordingly.
198-
if (g$geom == "hline" || g$geom == "vline") {
181+
if (g$geom %in% c("hline", "vline")) {
199182
intercept <- paste0(ifelse(g$geom == "hline", "y", "x"), "intercept")
200183
vec.list <- basic$data[c("PANEL", intercept)]
201184
df.list <- split(basic$data, vec.list, drop=TRUE)
@@ -221,7 +204,6 @@ layer2traces <- function(l, d, misc) {
221204
}
222205
traces <- NULL
223206
names.in.legend <- NULL
224-
225207
for (data.i in seq_along(data.list)) {
226208
data.params <- data.list[[data.i]]
227209
data.params$params$stat.type <- l$stat$objname
@@ -265,18 +247,19 @@ layer2traces <- function(l, d, misc) {
265247
if (is.null(tr$name) || tr$name %in% names.in.legend)
266248
tr$showlegend <- FALSE
267249
names.in.legend <- c(names.in.legend, tr$name)
268-
269-
if (g$geom == "bar")
270-
tr$barmode <- barmode
271-
272-
# Bar Gap
273-
if (exists("bargap")) {
274-
tr$bargap <- bargap
250+
251+
# special handling for bars
252+
if (g$geom == "bar") {
253+
tr$bargap <- if (exists("bargap")) bargap else "default"
254+
pos <- l$position$.super$objname
255+
tr$barmode <- if (pos %in% c("identity", "stack", "fill")) {
256+
"stack"
257+
} else "group"
275258
}
259+
276260
traces <- c(traces, list(tr))
277261
}
278262

279-
280263
sort.val <- sapply(traces, function(tr){
281264
rank.val <- unlist(tr$sort)
282265
if(is.null(rank.val)){
@@ -362,25 +345,19 @@ toBasic <- list(
362345
g$data <- g$prestats.data
363346
g
364347
},
365-
bar=function(g) {
366-
for(a in c("fill", "colour")){
367-
g$prestats.data[[a]] <-
368-
g$data[[a]][match(g$prestats.data$group, g$data$group)]
369-
}
370-
g$params$xstart <- min(g$data$xmin)
371-
g$params$xend <- max(g$data$xmax)
372-
g$data <- g$prestats.data
348+
bar=function(g){
349+
g <- group2NA(g, "bar")
350+
g$data <- g$data[!is.na(g$data$y), ]
373351
g
374352
},
375353
contour=function(g) {
376354
g$data <- g$prestats.data
377355
g
378356
},
379357
density=function(g) {
380-
g$params$xstart <- min(g$data$x)
381-
g$params$xend <- max(g$data$x)
382-
g$params$binwidth <- (max(g$data$x) - min(g$data$x))/30
383-
g$data <- g$prestats.data
358+
g$geom <- "area"
359+
if (is.null(g$data$fill) && is.null(g$params$alpha)) g$params$alpha <- 0
360+
if (is.null(g$data$colour)) g$params$colour <- "black"
384361
g
385362
},
386363
density2d=function(g) {
@@ -594,40 +571,25 @@ geom2trace <- list(
594571
L
595572
},
596573
bar=function(data, params) {
597-
L <- list(x=data$x,
574+
x <- if ("x.name" %in% names(data)) data$x.name else data$x
575+
if (inherits(x, "POSIXt")) {
576+
# Convert seconds into milliseconds
577+
x <- as.numeric(x) * 1000
578+
} else if (inherits(x, "Date")) {
579+
# Convert days into milliseconds
580+
x <- as.numeric(x) * 24 * 60 * 60 * 1000
581+
}
582+
L <- list(x=x,
583+
y=data$y,
584+
type="bar",
598585
name=params$name,
599586
text=data$text,
600587
marker=list(color=toRGB(params$fill)))
601-
602588
if (!is.null(params$colour)) {
603589
L$marker$line <- list(color=toRGB(params$colour))
604590
L$marker$line$width <- if (is.null(params$size)) 1 else params$size
605591
}
606-
607-
if (!is.null(params$alpha))
608-
L$opacity <- params$alpha
609-
610-
if (params$stat.type == "bin") {
611-
L$type <- "histogram"
612-
if (is.null(params$binwidth)) {
613-
L$autobinx <- TRUE
614-
} else {
615-
L$autobinx <- FALSE
616-
L$xbins=list(start=params$xstart,
617-
end=params$xend,
618-
size=params$binwidth)
619-
if (inherits(data$x.name, "POSIXt")) {
620-
# Convert seconds into milliseconds
621-
L$xbins <- lapply(L$xbins, function(x) x * 1000)
622-
} else if (inherits(data$x.name, "Date")) {
623-
# Convert days into milliseconds
624-
L$xbins <- lapply(L$xbins, function(x) x * 24 * 60 * 60 * 1000)
625-
}
626-
}
627-
} else {
628-
L$y <- data$y
629-
L$type <- "bar"
630-
}
592+
if (!is.null(params$alpha)) L$opacity <- params$alpha
631593
L
632594
},
633595
step=function(data, params) {
@@ -666,15 +628,6 @@ geom2trace <- list(
666628
L$contours=list(coloring="lines")
667629
L
668630
},
669-
density=function(data, params) {
670-
L <- list(x=data$x,
671-
name=params$name,
672-
text=data$text,
673-
marker=list(color=toRGB(params$fill)),
674-
type="histogram",
675-
autobinx=TRUE,
676-
histnorm="probability density")
677-
},
678631
density2d=function(data, params) {
679632
L <- list(x=data$x,
680633
y=data$y,

inst/testscripts/.push_test_table.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# exit on error
4+
set -e
5+
6+
# -----------------------------------------------------------------------
7+
# Travis does two types of builds:
8+
#
9+
# (1) A so-called "push". This essentially does a checkout on the most
10+
# recent commit of the pull request, but *doesn't* merge with master.
11+
# In this case, $TRAVIS_PULL_REQUEST = "false"
12+
# (2) A so-called "pr" (pull request). This *does* merge with master.
13+
# In this case, $TRAVIS_PULL_REQUEST contains the pull request number.
14+
# -----------------------------------------------------------------------
15+
16+
# We need the pull request number to talk to the GitHub API, make comments, etc.
17+
[ "${TRAVIS_PULL_REQUEST}" = "false" ] && exit 0
18+
19+
git config --global user.name "cpsievert"
20+
git config --global user.email "[email protected]"
21+
22+
cd ..
23+
git clone https://github.com/ropensci/plotly-test-table.git
24+
cd plotly-test-table
25+
git checkout gh-pages
26+
27+
# Read more about Travis environment variables --
28+
# http://docs.travis-ci.com/user/ci-environment/
29+
Rscript ../plotly/inst/testscripts/comment.R $TRAVIS_PULL_REQUEST $TRAVIS_BUILD_ID $TRAVIS_COMMIT $GH_TOKEN

0 commit comments

Comments
 (0)