-
Notifications
You must be signed in to change notification settings - Fork 634
better handling of colorscale inputs #1485
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c6f96f4
better handling of colorscale inputs, fixes #1432
cpsievert 2055abd
more careful coercion of bare list of length 2
cpsievert a72d016
fix test
cpsievert 6ec50ff
another fix test
cpsievert 871ae81
check length of list elements and better check for numeric coercion
cpsievert 9a99a48
add missing value in test to marker.color
cpsievert 8776482
add new baselines
cpsievert 0941f05
more transparent logic
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
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,72 @@ | ||
context("colorscales") | ||
|
||
|
||
test_that("Can specify marker.colorscale", { | ||
p <- plot_ly( | ||
x = c(-9, -6, -5, -3, -1), | ||
y = c(0, 1, 4, 5, 7), | ||
marker = list( | ||
color = 1:5, | ||
colorscale='Rainbow', | ||
showscale = TRUE | ||
) | ||
) | ||
l <- expect_doppelganger_built(p, "marker.colorscale") | ||
}) | ||
|
||
test_that("Can specify contour colorscale", { | ||
p <- plot_ly( | ||
x = c(-9, -6, -5, -3, -1), | ||
y = c(0, 1, 4, 5, 7), | ||
z = matrix(c(10, 10.625, 12.5, 15.625, 20, 5.625, 6.25, 8.125, 11.25, 15.625, 2.5, 3.125, 5, 8.125, 12.5, 0.625, 1.25, 3.125, | ||
6.25, 10.625, 0, 0.625, 2.5, 5.625, 10), nrow = 5, ncol = 5), | ||
type = "contour", | ||
colorscale = 'Rainbow' | ||
) | ||
l <- expect_doppelganger_built(p, "contour-colorscale") | ||
}) | ||
|
||
test_that("Can provide a color interpolation function", { | ||
p <- plot_ly(x = 1:10, y = 1:10, color = 1:10, colors = scales::colour_ramp(c("red", "green"))) | ||
l <- expect_doppelganger_built(p, "colorRamp") | ||
}) | ||
|
||
test_that("Can specify contour colorscale", { | ||
|
||
plot_colorscale <- function(colorscale) { | ||
plot_ly( | ||
x = 1:10, | ||
y = 1:10, | ||
marker = list( | ||
color = 1:10, | ||
colorscale = colorscale, | ||
showscale = TRUE | ||
) | ||
) | ||
} | ||
cpsievert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
pal <- scales::colour_ramp(c("red", "green")) | ||
colorScale <- list( | ||
val = seq(0, 1, by = 0.1), | ||
col = pal(seq(0, 1, by = 0.1)) | ||
) | ||
test_list <- plot_colorscale(colorScale) | ||
test_df <- plot_colorscale(as.data.frame(colorScale)) | ||
test_matrix <- plot_colorscale(as.matrix(as.data.frame(colorScale))) | ||
|
||
expect_doppelganger_built(test_list, "test_list") | ||
expect_doppelganger_built(test_df, "test_df") | ||
expect_doppelganger_built(test_matrix, "test_matrix") | ||
|
||
test_list_2 <- plot_colorscale(list(list(0, "rgb(0,0,255)"), list(1, "rgb(0,255,0)"))) | ||
test_list_3 <- plot_colorscale(list(list(0, 1), list("rgb(0,0,255)", "rgb(0,255,0)"))) | ||
|
||
expect_doppelganger_built(test_list_2, "test_list_2") | ||
expect_doppelganger_built(test_list_3, "test_list_3") | ||
}) | ||
|
||
|
||
test_that("contour colorscale supports alpha", { | ||
p <- plot_ly(z = volcano, type = "contour", stroke = I("black"), alpha = 0.1) | ||
l <- expect_doppelganger_built(p, "contour-alpha") | ||
}) |
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.
Uh oh!
There was an error while loading. Please reload this page.