Skip to content

Commit 5e0ad36

Browse files
committed
Merge pull request #562 from ropensci/bug
Disambiguate classnames
2 parents ffbd5b5 + 89ee03b commit 5e0ad36

File tree

13 files changed

+127
-69
lines changed

13 files changed

+127
-69
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via 'plotly.js'
3-
Version: 3.5.0
3+
Version: 3.5.1
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "cpsievert1@gmail.com"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NAMESPACE

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ S3method(geom2trace,GeomText)
1212
S3method(geom2trace,GeomTile)
1313
S3method(geom2trace,default)
1414
S3method(print,figure)
15-
S3method(print,plotly)
15+
S3method(print,plotly_built)
16+
S3method(print,plotly_hash)
1617
S3method(to_basic,GeomAbline)
1718
S3method(to_basic,GeomArea)
1819
S3method(to_basic,GeomBoxplot)
@@ -49,7 +50,8 @@ export(get_figure)
4950
export(gg2list)
5051
export(ggplotly)
5152
export(knit_print.figure)
52-
export(knit_print.plotly)
53+
export(knit_print.plotly_built)
54+
export(knit_print.plotly_hash)
5355
export(last_plot)
5456
export(layout)
5557
export(offline)

NEWS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
3.6.0 -- 26 Apr 2016
2+
3+
CHANGES:
4+
5+
Upgrade to plotlyjs v1.10.0 -- https://github.com/plotly/plotly.js/releases/tag/v1.9.0
6+
7+
Distinguish between "built" (plotly_built) and "non-built" (plotly_hash) plotly objects. See #562
8+
9+
110
3.5.0 -- 19 Apr 2016
211

312
NEW FEATURES:

R/imports.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
#' @importFrom viridis viridis
88
#' @importFrom jsonlite toJSON fromJSON
99
#' @importFrom httr GET POST PATCH content config add_headers stop_for_status
10+
#' @importFrom htmlwidgets createWidget sizingPolicy
1011
NULL

R/plotly.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ plotly_build <- function(l = last_plot()) {
331331
x$layout$hovermode <- x$layout$hovermode %||% "closest"
332332
}
333333
# add plotly class mainly for printing method
334-
structure(x, class = unique("plotly", class(x)))
334+
structure(x, class = unique("plotly_built", class(x)))
335335
}
336336

337337
# returns a _list of traces_.

R/print.R

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,36 @@
33
#' @param x a plotly object
44
#' @param ... additional arguments
55
#' @export
6-
#' @importFrom htmlwidgets createWidget
7-
#' @importFrom htmlwidgets sizingPolicy
8-
print.plotly <- function(x, ...) {
9-
if (!inherits(x, "htmlwidget")) x <- as.widget(x)
10-
get("print.htmlwidget", envir = asNamespace("htmlwidgets"))(x, ...)
6+
print.plotly_hash <- function(x, ...) {
7+
x <- as.widget(x)
8+
print(x, ...)
119
}
1210

11+
#' Print a 'built' plotly object
12+
#'
13+
#' @param x a plotly object
14+
#' @param ... additional arguments
15+
#' @export
16+
print.plotly_built <- print.plotly_hash
17+
1318
#' Print a plotly object in a knitr doc
1419
#'
1520
#' @param x a plotly object
1621
#' @param options knitr options.
1722
#' @param ... additional arguments
1823
#' @export
19-
knit_print.plotly <- function(x, options, ...) {
20-
if (!inherits(x, "htmlwidget")) x <- as.widget(x)
21-
get("knit_print.htmlwidget", envir = asNamespace("htmlwidgets"))(x, options = options, ...)
24+
knit_print.plotly_hash <- function(x, options, ...) {
25+
x <- as.widget(x)
26+
knitr::knit_print(x, options, ...)
2227
}
2328

29+
#' Print a 'built' plotly object in a knitr doc
30+
#'
31+
#' @param x a plotly object
32+
#' @param ... additional arguments
33+
#' @export
34+
knit_print.plotly_built <- knit_print.plotly_hash
35+
2436
#' Convert a plotly object to an htmlwidget object
2537
#'
2638
#' @param x a plotly object.
@@ -34,22 +46,22 @@ knit_print.plotly <- function(x, options, ...) {
3446

3547
as.widget <- function(x, ...) {
3648
if (inherits(x, "htmlwidget")) return(x)
37-
p <- plotly_build(x)
49+
if (!inherits(x, "plotly_built")) x <- plotly_build(x)
3850
# set some margin defaults if none are provided
39-
p$layout$margin <- modifyList(
51+
x$layout$margin <- modifyList(
4052
list(b = 40, l = 60, t = 25, r = 10),
41-
p$layout$margin %||% list()
53+
x$layout$margin %||% list()
4254
)
43-
p$config$modeBarButtonsToRemove <-
44-
i(p$config$modeBarButtonsToRemove %||% "sendDataToCloud")
45-
p$base_url <- get_domain()
55+
x$config$modeBarButtonsToRemove <-
56+
i(x$config$modeBarButtonsToRemove %||% "sendDataToCloud")
57+
x$base_url <- get_domain()
4658
# customize the JSON serializer (for htmlwidgets)
47-
attr(p, 'TOJSON_FUNC') <- to_JSON
59+
attr(x, 'TOJSON_FUNC') <- to_JSON
4860
htmlwidgets::createWidget(
4961
name = "plotly",
50-
x = p,
51-
width = p$width,
52-
height = p$height,
62+
x = x,
63+
width = x$width,
64+
height = x$height,
5365
sizingPolicy = htmlwidgets::sizingPolicy(
5466
padding = 5,
5567
browser.fill = TRUE

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ hash_plot <- function(df, p) {
3636
assign(hash, p, envir = plotlyEnv)
3737
attr(df, "plotly_hash") <- hash
3838
# add plotly class mainly for printing method
39-
class(df) <- unique(c("plotly", class(df)))
39+
class(df) <- unique(c("plotly_hash", class(df)))
4040
# return a data frame to be compatible with things like dplyr
4141
df
4242
}

inst/htmlwidgets/lib/plotlyjs/plotly-latest.min.js

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/plotly.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies:
22
- name: plotlyjs
3-
version: 1.9.0
3+
version: 1.10.0
44
src: "htmlwidgets/lib/plotlyjs"
55
script: plotly-latest.min.js
66
stylesheet: plotly-htmlwidgets.css

man/knit_print.plotly_built.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/knit_print.plotly.Rd renamed to man/knit_print.plotly_hash.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/print.plotly_built.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/print.plotly.Rd renamed to man/print.plotly_hash.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)