-
Notifications
You must be signed in to change notification settings - Fork 633
fixed problem with equal axes #223
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f6f2105
fixed problem with equal axes
13bzhang 86fbec5
add testthat test for my new features
13bzhang 31a1ef6
fixed the expect_traces function
13bzhang ba738b9
add space to the end of test
13bzhang 79257be
coordinate fixed range from data
13bzhang 955da5e
Merge branch 'master' of https://github.com/ropensci/plotly into baob…
13bzhang 2dc1453
delete an extra line in test
13bzhang 7cefa02
Merge branch 'master' into baobao-equal_axes
13bzhang 5d9deca
made test different from ggplotly
13bzhang b969dee
test expect_equal with tolerance
13bzhang af4fd33
added parameter name, made tolerance smaller
13bzhang b7f1645
Merge branch 'baobao-equal_axes' of https://github.com/ropensci/plotl…
cpsievert ad260ed
merge with master
cpsievert 0a85c90
avoid using random data
cpsievert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
context("Fixed coordinates") | ||
|
||
# Expect trace function | ||
expect_traces <- function(gg, n_traces, name) { | ||
stopifnot(is.ggplot(gg)) | ||
stopifnot(is.numeric(n_traces)) | ||
save_outputs(gg, paste0("coord_fixed-", name)) | ||
L <- gg2list(gg) | ||
all_traces <- L$data | ||
no_data <- sapply(all_traces, function(tr) { | ||
is.null(tr[["x"]]) && is.null(tr[["y"]]) | ||
}) | ||
has_data <- all_traces[!no_data] | ||
expect_equal(length(has_data), n_traces) | ||
list(traces = has_data, layout = L$layout) | ||
} | ||
|
||
# Force equal scaling | ||
p <- ggplot(mtcars, aes(mpg, qsec)) + geom_point() + coord_fixed() | ||
# Test | ||
test_that("coord_fixed() is translated to the right height-width ratio", { | ||
info <- expect_traces(p, 1, "force_equal_scaling") | ||
tr <- info$traces[[1]] | ||
la <- info$layout | ||
expect_identical(tr$type, "scatter") | ||
# height-width ratio check | ||
x_range <- range(p$data$mpg, na.rm = TRUE) | ||
y_range <- range(p$data$qsec, na.rm = TRUE) | ||
yx_ratio <- (y_range[2] - y_range[1]) / (x_range[2] - x_range[1]) | ||
expect_equal(la$height/la$width, yx_ratio * p$coordinates$ratio, tolerance = 0.10) | ||
}) | ||
|
||
# Equal scaling, with each 1 on the x axis the same length as y on x axis | ||
p <- ggplot(dat, aes(mpg, qsec)) + geom_point() + coord_fixed(1/3) | ||
# Test | ||
test_that("coord_fixed() is translated to the right height-width ratio", { | ||
info <- expect_traces(p, 1, "force_equal_scaling") | ||
tr <- info$traces[[1]] | ||
la <- info$layout | ||
expect_identical(tr$type, "scatter") | ||
# height-width ratio check | ||
x_range <- range(p$data$mpg, na.rm = TRUE) | ||
y_range <- range(p$data$qsec, na.rm = TRUE) | ||
yx_ratio <- (y_range[2] - y_range[1]) / (x_range[2] - x_range[1]) | ||
expect_equal(la$height/la$width, yx_ratio * p$coordinates$ratio, tolerance = 0.10) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coding the height/width is going to make for unpleasant htmlwidget experience. I think the best way to do it is pass this ratio to the HTMLwidget.resize method and impose the ratio on the height/width there. We should also provide a way to specify this ratio for non-ggplots