Skip to content

Commit 05b8283

Browse files
authored
Merge branch 'master' into fix/invalid-selector-character
2 parents 30942de + a444f7b commit 05b8283

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: animint2
22
Title: Animated Interactive Grammar of Graphics
3-
Version: 2025.10.31
3+
Version: 2025.11.17
44
URL: https://animint.github.io/animint2
55
BugReports: https://github.com/animint/animint2/issues
66
Authors@R: c(
@@ -64,7 +64,7 @@ Authors@R: c(
6464
comment="Animint2 GSoC 2025"),
6565
person("Gaurav", "Chaudhary",
6666
role="ctb",
67-
comment="Remove unused css.file parameter; fix issue #233 selector values"))
67+
comment="Remove unused css.file parameter; fix issue #233 selector values; fix issue #273 update_axes tick font-size"))
6868
Description: Functions are provided for defining animated,
6969
interactive data visualizations in R code, and rendering
7070
on a web page. The 2018 Journal of Computational and

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Changes in version 2025.11.17 (PR#274)
2+
3+
- `update_axes`: Fixed issue #273 where axis tick text font-size was inconsistent between plots with and without `update_axes`. Previously, plots using `theme_animint(update_axes="x")` would lose `theme(axis.text = element_text(size=...))` styling after axis updates.
4+
15
# Changes in version 2025.10.31 (PR#271)
26

37
- `geom_point()` now warns when shape parameter is set to a value other than 21, since animint2 web rendering only supports shape=21 for proper display of both color and fill aesthetics.

inst/htmljs/animint.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,7 @@ var animint = function (to_select, json_file) {
647647
var axis_path = xaxis_g.select("path.domain");
648648
axis_path.remove();
649649
}
650-
xaxis_g.selectAll("text")
651-
.style("text-anchor", p_info.xanchor)
652-
.style("font-size", p_info.xsize)
653-
.attr("transform", "rotate(" + p_info.xangle + " 0 9)");
650+
apply_axis_text_styles(xaxis_g, "x", p_info);
654651
}
655652
if(draw_y){
656653
var yaxis = d3.svg.axis()
@@ -669,8 +666,7 @@ var animint = function (to_select, json_file) {
669666
var axis_path = yaxis_g.select("path.domain");
670667
axis_path.remove();
671668
}
672-
yaxis_g.selectAll(".tick text")
673-
.style("font-size", p_info.ysize);
669+
apply_axis_text_styles(yaxis_g, "y", p_info);
674670
}
675671

676672
if(!axis.xline) {
@@ -1930,6 +1926,20 @@ var animint = function (to_select, json_file) {
19301926
}
19311927
}
19321928

1929+
// Helper function to apply axis text styling
1930+
// Used by both axis initialization and update_axes to ensure consistency
1931+
function apply_axis_text_styles(axis_g, axes, p_info){
1932+
if(axes == "x"){
1933+
axis_g.selectAll("text")
1934+
.style("text-anchor", p_info.xanchor)
1935+
.style("font-size", p_info.xsize)
1936+
.attr("transform", "rotate(" + p_info.xangle + " 0 9)");
1937+
}else{
1938+
axis_g.selectAll(".tick text")
1939+
.style("font-size", p_info.ysize);
1940+
}
1941+
}
1942+
19331943
// update scales for the plots that have update_axes option in
19341944
// theme_animint
19351945
function update_scales(p_name, axes, v_name, value){
@@ -1999,10 +2009,13 @@ var animint = function (to_select, json_file) {
19992009
.orient(orientation)
20002010
.tickValues(tick_vals);
20012011
// update existing axis
2002-
var xyaxis_g = element.select("#plot_"+p_name).select("."+axes+"axis_"+panel_i)
2012+
var xyaxis_sel = element.select("#plot_"+p_name).select("."+axes+"axis_"+panel_i);
2013+
var xyaxis_g = xyaxis_sel
20032014
.transition()
20042015
.duration(1000)
20052016
.call(xyaxis);
2017+
// Fix for issue #273: preserve axis text styling after update
2018+
apply_axis_text_styles(xyaxis_sel, axes, Plots[p_name]);
20062019
}
20072020

20082021
// Update major/minor grids once axes ticks have been updated
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
acontext("update_axes tick font-size consistency - Issue #273")
2+
mtcars_test <- mtcars
3+
mtcars_test$cyl <- as.factor(mtcars_test$cyl)
4+
viz_tick_size <- list(
5+
noUpdate = ggplot() +
6+
geom_point(aes(mpg, disp, colour=cyl), data=mtcars_test) +
7+
ggtitle("No update_axes") +
8+
theme(axis.text = element_text(size=12)),
9+
withUpdateX = ggplot() +
10+
geom_point(aes(mpg, disp, colour=cyl), showSelected="cyl", data=mtcars_test) +
11+
theme_animint(update_axes=c("x")) +
12+
ggtitle("With update_axes x") +
13+
theme(axis.text = element_text(size=12)),
14+
selector.types = list(cyl="single")
15+
)
16+
info <- animint2HTML(viz_tick_size)
17+
test_that("x-axis tick text font-size is consistent with and without update_axes", {
18+
no_update_xpath <- '//svg[@id="plot_noUpdate"]//g[@class="xaxis axis xaxis_1"]//g[@class="tick major"]//text'
19+
with_update_xpath <- '//svg[@id="plot_withUpdateX"]//g[@class="xaxis axis xaxis_1"]//g[@class="tick major"]//text'
20+
no_update_font_size <- getStyleValue(info$html, no_update_xpath, "font-size")
21+
with_update_font_size <- getStyleValue(info$html, with_update_xpath, "font-size")
22+
expect_gt(length(no_update_font_size), 0)
23+
expect_gt(length(with_update_font_size), 0)
24+
no_update_size_unique <- unique(no_update_font_size)
25+
with_update_size_unique <- unique(with_update_font_size)
26+
expect_equal(length(no_update_size_unique), 1)
27+
expect_equal(length(with_update_size_unique), 1)
28+
expect_equal(with_update_size_unique, no_update_size_unique, info=sprintf("Axis tick text font-size should be consistent regardless of update_axes. Expected %s but got %s", no_update_size_unique, with_update_size_unique))
29+
})

0 commit comments

Comments
 (0)