Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6b5ac29
test: add failing test for update_axes duration issue #276
ANAMASGARD Nov 20, 2025
6cf4beb
fix: use selector duration in update_axes instead of hardcoded 1000ms
ANAMASGARD Nov 20, 2025
c04f99c
Fix #276: update_axes uses selector duration instead of hardcoded 1000ms
ANAMASGARD Nov 21, 2025
2af87da
Fix #276: check hasOwnProperty for duration to handle duration=0
ANAMASGARD Nov 25, 2025
d5fb8b3
Fix #276: add type check for duration property
ANAMASGARD Nov 25, 2025
2dadc24
Fix test: add showSelected to create axis_domains
ANAMASGARD Nov 25, 2025
d1c3f71
Simplify duration check and fix test per maintainer feedback
ANAMASGARD Nov 25, 2025
44fd488
Fix test: pass axis node to getTickDiff instead of HTML doc
ANAMASGARD Nov 25, 2025
5a0c3ef
use hasOwnProperty, animint(), expect_false
ANAMASGARD Nov 27, 2025
4043b97
use expect_gt instead of expect_false per maintainer feedback
ANAMASGARD Nov 27, 2025
7ec225c
fix: remove incorrect array indexing from tick diff comparison
ANAMASGARD Nov 27, 2025
72e6a69
use unequal() with tolerance parameter instead of magic numbers
ANAMASGARD Nov 28, 2025
2346121
use expect_gt with 0 instead of expect_true, remove tolerance magic n…
ANAMASGARD Nov 28, 2025
4f719d9
Merge branch 'master' into fix-update-axes-duration
ANAMASGARD Dec 3, 2025
ef9a2ff
guard update_axes duration when selector is missing
ANAMASGARD Dec 3, 2025
8e9d103
fix indentation: only duration change from 1000 to milliseconds
ANAMASGARD Dec 3, 2025
65843c2
Fix #276: update_axes uses selector duration and correct plot_id sele…
ANAMASGARD Dec 4, 2025
a2b5bbd
Merge branch 'master' into fix-update-axes-duration
ANAMASGARD Dec 4, 2025
83b57c8
Fix #276: update_axes uses selector duration and correct plot_id sele…
ANAMASGARD Dec 4, 2025
fb218b7
Add safety check for plot_id in update_axes and update_grids
ANAMASGARD Dec 5, 2025
1d3343a
Add safety checks for empty selectors array in initialization
ANAMASGARD Dec 5, 2025
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
24 changes: 16 additions & 8 deletions inst/htmljs/animint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ var animint = function (to_select, json_file) {
// We update the current selection of the plot every time
// and use it to index the correct domain
var curr_select = axis_domains[xyaxis].curr_select;
if(axis_domains[xyaxis].selectors.indexOf(v_name) > -1){
if(v_name && axis_domains[xyaxis].selectors.indexOf(v_name) > -1){
curr_select[v_name] = value;
var str = use_panel+".";
for(selec in curr_select){
Expand All @@ -1982,7 +1982,7 @@ var animint = function (to_select, json_file) {
// Once scales are updated, update the axis ticks if needed
if(draw_axes){
// Tick values are same as major grid lines
update_axes(p_name, xyaxis, panel_i, grid_vals[1]);
update_axes(p_name, xyaxis, panel_i, grid_vals[1], v_name);
}
// Update major and minor grid lines
update_grids(p_name, xyaxis, panel_i, grid_vals, scales);
Expand All @@ -1994,7 +1994,7 @@ var animint = function (to_select, json_file) {

// Update the axis ticks etc. once plot is zoomed in/out
// currently called from update_scales.
function update_axes(p_name, axes, panel_i, tick_vals){
function update_axes(p_name, axes, panel_i, tick_vals, v_name){
var orientation;
if(axes == "x"){
orientation = "bottom";
Expand All @@ -2009,10 +2009,15 @@ var animint = function (to_select, json_file) {
.orient(orientation)
.tickValues(tick_vals);
// update existing axis
var xyaxis_sel = element.select("#"+viz_id+"_"+p_name).select("."+axes+"axis_"+panel_i);
var plot_id = Plots[p_name] && Plots[p_name].plot_id ? Plots[p_name].plot_id : ("plot_"+p_name);
var xyaxis_sel = element.select("#"+plot_id).select("."+axes+"axis_"+panel_i);
var milliseconds = 0;
if(v_name && Selectors.hasOwnProperty(v_name) && Selectors[v_name].hasOwnProperty("duration")){
milliseconds = Selectors[v_name].duration;
}
var xyaxis_g = xyaxis_sel
.transition()
.duration(1000)
.duration(milliseconds)
.call(xyaxis);
// Fix for issue #273: preserve axis text styling after update
apply_axis_text_styles(xyaxis_sel, axes, Plots[p_name]);
Expand All @@ -2021,7 +2026,8 @@ var animint = function (to_select, json_file) {
// Update major/minor grids once axes ticks have been updated
function update_grids(p_name, axes, panel_i, grid_vals, scales){
// Select panel to update
var bgr = element.select("#"+viz_id+"_"+p_name).select(".bgr"+panel_i);
var plot_id = Plots[p_name] && Plots[p_name].plot_id ? Plots[p_name].plot_id : ("plot_"+p_name);
var bgr = element.select("#"+plot_id).select(".bgr"+panel_i);
// Update major and minor grid lines
["minor", "major"].forEach(function(grid_class, j){
var lines = bgr.select(".grid_"+grid_class).select("."+axes);
Expand Down Expand Up @@ -2338,8 +2344,10 @@ var animint = function (to_select, json_file) {
if(!isArray(selectors)){
selectors = [selectors];
}
update_scales(p_name, xy, selectors[0],
response.selectors[selectors[0]].selected);
if(selectors.length > 0 && selectors[0] && response.selectors.hasOwnProperty(selectors[0])){
update_scales(p_name, xy, selectors[0],
response.selectors[selectors[0]].selected);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-compiler-ghpages.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_that("error for viz with no source", {
}, "plot.list does not contain option named source, which is required by animint2pages")
})

get_tsv <- function(L)Sys.glob(file.path(L$local_clone, "*tsv"))
get_tsv <- function(L)Sys.glob(file.path(L$local_clone, "*chunk[0-9]*.tsv")) # exclude common tsv
expect_Capture <- function(L){
expect_gt(file.size(file.path(L$local_clone,"Capture.PNG")), 0)
}
Expand Down
38 changes: 38 additions & 0 deletions tests/testthat/test-renderer3-update-axes-duration.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
acontext("update_axes respects selector duration - Issue #276")
# Test that update_axes uses the selector's duration option instead of hardcoded 1000ms
# This follows the same pattern as test-renderer3-update-axes.R
mtcars$cyl <- as.factor(mtcars$cyl)
viz_duration <- animint(
scatter = ggplot() +
geom_point(aes(mpg, disp, colour=cyl), data=mtcars) +
theme_animint(update_axes=c("x", "y")),
duration=list(cyl=2000),
selector.types=list(cyl="single")
)
info <- animint2HTML(viz_duration)

# Get initial tick positions using same pattern as test-renderer3-update-axes.R
rect_path <- "//svg[@id='plot_scatter']//g[contains(@class, '%saxis')]"
x_axis_node <- getNodeSet(info$html, sprintf(rect_path, "x"))[[1]]
y_axis_node <- getNodeSet(info$html, sprintf(rect_path, "y"))[[1]]
original_tick_diff_x <- getTickDiff(x_axis_node, axis="x")
original_tick_diff_y <- getTickDiff(y_axis_node, axis="y")

# Click to change selector
clickID("plot_scatter_cyl_variable_8")
Sys.sleep(0.5)
html_updated <- getHTML()

# Get updated tick positions
x_axis_node_updated <- getNodeSet(html_updated, sprintf(rect_path, "x"))[[1]]
y_axis_node_updated <- getNodeSet(html_updated, sprintf(rect_path, "y"))[[1]]
updated_tick_diff_x <- getTickDiff(x_axis_node_updated, axis="x")
updated_tick_diff_y <- getTickDiff(y_axis_node_updated, axis="y")

test_that("update_axes uses selector duration for transitions", {
# Verify ticks changed (confirms update_axes was called with correct duration)
# Tick spacing changes when filtering to different cyl values (4, 6, 8)
# because each subset has different mpg/disp ranges
expect_gt(abs(updated_tick_diff_x - original_tick_diff_x), 0)
expect_gt(abs(updated_tick_diff_y - original_tick_diff_y), 0)
})