Skip to content
Open
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
*pids.txt
*~
.vscode/settings.json
/node_modules
/node_modules.DS_Store
.DS_Store
12 changes: 9 additions & 3 deletions inst/htmljs/animint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,12 +1134,18 @@ var animint = function (to_select, json_file) {
var get_style_on_stroke_width = get_size;

// stroke_width for geom_point
var stroke_width = 1; // by default ggplot2 has 0.5, animint has 1
var stroke_width = 1; // default

// Make stroke more visible when color_off is used
if(aes.hasOwnProperty("color_off")){
stroke_width = 2;
}

var get_stroke_width;
if(aes.hasOwnProperty("stroke")){
get_stroke_width = get_attr("stroke");
get_stroke_width = get_attr("stroke");
}else{
get_stroke_width = function(d){
get_stroke_width = function(d){
return stroke_width;
};
}
Expand Down
37 changes: 37 additions & 0 deletions tests/testthat/Untitledtest-renderer-bisection_hard_test_trial.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
library(ggplot2)
library(animint2)

# Make iteration a factor
bisection_df <- data.frame(
x = seq(-2, 2, length.out = 100),
y = (seq(-2, 2, length.out = 100))^3 - seq(-2, 2, length.out = 100),
iteration = factor(rep(1:5, each = 20))
)

interval_df <- data.frame(
m = c(-1, -0.5, 0, 0.5, 1),
iteration = factor(1:5)
)

# Create the animint2 object using showSelected as a parameter
bisection_animint2 <- animint(
plot1 = ggplot(bisection_df, aes(x = x, y = y)) +
geom_line(showSelected = "iteration") + # parameter, not inside aes()
geom_segment(
data = interval_df,
aes(x = m, xend = m, y = -Inf, yend = Inf),
showSelected = "iteration", # parameter here
color = "red"
) +
labs(title = "Bisection Method Visualization", x = "x", y = "f(x)"),

# Animation settings
time = list(variable = "iteration", ms = 2000)
)

# Render
animint2dir(
bisection_animint2,
out.dir = "~/Desktop/animint-gallery/bisection_animint2_render",
open.browser = TRUE
)
20 changes: 20 additions & 0 deletions tests/testthat/test-renderer-selectors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test_that("animint renderer works without Selectors.hasOwnProperty", {
skip_on_cran()

library(animint2)

df <- data.frame(
x = 1:3,
y = 1:3,
grp = c("a", "b", "c")
)

p <- ggplot(df, aes(x, y)) +
geom_point(clickSelects = "grp")

tmp <- withr::local_tempdir()

expect_silent(
animint(list(plot = p), out.dir = tmp)
)
})