Skip to content
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

Solved the LaTeX2exp error. Closes #2027 #2030

Merged
merged 13 commits into from
Nov 1, 2021
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
3 changes: 2 additions & 1 deletion R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,7 @@ italic <- function(x) paste("<i>", x, "</i>")

# if a vector that has one unique value (ignoring missings), return that value
uniq <- function(x) {
x <- remove_class(x, "TeX")
u <- unique(x)
if (identical(u, NA) || length(u) == 0) return(u)
u <- u[!is.na(u)]
Expand Down Expand Up @@ -1432,4 +1433,4 @@ getAesMap <- function(plot, layer) {
} else {
layer$mapping
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testthat/_snaps/latex2exp/latex2exp-rendering.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testthat/_snaps/plotly-area/add-area.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/helper-vdiffr.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ write_plotly_svg <- function(p, file) {

# strip out non-deterministic fullLayout.uid
# TODO: if and when plotly provides an API to pre-specify, use it!
svg_txt <- readLines(file, warn = FALSE)
svg_txt <- readLines(basename(file), warn = FALSE)
strextract <- function(str, pattern) regmatches(str, regexpr(pattern, str))
def <- strextract(svg_txt, 'defs id=\\"defs-[[:alnum:]]+\\"')
uid <- sub("defs-", "", strextract(def, "defs-[[:alnum:]]+"))
svg_txt <- gsub(uid, "", svg_txt, fixed = TRUE)
writeLines(svg_txt, file)
writeLines(svg_txt, basename(file))
Comment on lines +54 to +59
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had issues when using write_plotly_csv when not in the _snaps/test-file folder. You were already changing the working directory but if I passed in a name like _snaps/test/file_name.svg and I was in testthat folder the writeLines call would try to write to _snaps/test/file_name.svg from _snaps/test which would cause an issue.

}

# copied from vdiffr
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-latex2exp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
library(latex2exp)

test_that("latex2exp expressions render correctly", {
p <- qplot(1, "A")+
ylab(TeX("$\\frac{2hc^2}{\\lambda^\\beta}$"))+
xlab(TeX("$\\alpha$"))

expect_doppelganger(config(ggplotly(p), mathjax="cdn"), "latex2exp-rendering")
})
12 changes: 12 additions & 0 deletions tests/testthat/test-plotly-area.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("add_area() works", {
data(wind)
p <- plot_ly(wind, r = ~r, theta = ~t) %>%
add_area(color = ~nms) %>%
layout(
polar = list(
radialaxis = list(ticksuffix = "%"),
angularaxis = list(rotation = 90)
)
)
expect_doppelganger_built(p, "add-area")
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase these changes off of master (this diff shouldn't be here)