From b6394f5a3d8a11ff7af3ee8cac5125a98cfea4bf Mon Sep 17 00:00:00 2001 From: Gauarv Chaudhary Date: Mon, 2 Mar 2026 17:29:15 +0530 Subject: [PATCH 1/6] animint.js: remove unnecessary Selectors.hasOwnProperty checks Fixes #278. Replaced Selectors.hasOwnProperty(selector_name) with a simple selector_name check in draw_geom and geom_label_aligned. Removed redundant guard in update_selector. Removed Selectors.hasOwnProperty check in update_axes. --- DESCRIPTION | 4 ++-- NEWS.md | 5 +++++ inst/htmljs/animint.js | 9 +++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 43ca2e728..5d787cd45 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: animint2 Title: Animated Interactive Grammar of Graphics -Version: 2026.2.28 +Version: 2026.3.2 URL: https://animint.github.io/animint2 BugReports: https://github.com/animint/animint2/issues Authors@R: c( @@ -64,7 +64,7 @@ Authors@R: c( comment="Animint2 GSoC 2025"), person("Gaurav", "Chaudhary", role="ctb", - comment="Remove unused css.file parameter; fix issue #233 selector values; fix issue #273 update_axes tick font-size; fix issue #276 update_axes transition duration")) + comment="Remove unused css.file parameter; fix issue #233 selector values; fix issue #273 update_axes tick font-size; fix issue #276 update_axes transition duration; #278 Removed unnecessary Selectors.hasOwnProperty checks in animint.js")) Description: Functions are provided for defining animated, interactive data visualizations in R code, and rendering on a web page. The 2018 Journal of Computational and diff --git a/NEWS.md b/NEWS.md index 6184d117b..68dfa2662 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# Changes in version 2026.3.2 (PR#285) + +- `animint.js`: Remove unnecessary `Selectors.hasOwnProperty` checks (issue #278). + Selector names are always valid when accessed, so membership checks are redundant. + # Changes in version 2025.12.4 (PR#277) - `update_axes`: Fix issue #276 where transition duration was hardcoded to 1000ms. Now it respects the selector's duration. diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index bfcc4b07f..4008ca3b6 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1567,7 +1567,7 @@ var animint = function (to_select, json_file) { eActions = function(groups) { // Handle transitions seperately due to unique structure of geom_label_aligned var transitionDuration = 0; - if (Selectors.hasOwnProperty(selector_name)) { + if (selector_name) { transitionDuration = +Selectors[selector_name].duration || 0; } groups.each(function(d) { @@ -1863,7 +1863,7 @@ var animint = function (to_select, json_file) { positionTooltip(tooltip, tooltip.html()); }); } - if(Selectors.hasOwnProperty(selector_name)){ + if(selector_name){ var milliseconds = Selectors[selector_name].duration; elements = elements.transition().duration(milliseconds); } @@ -2011,7 +2011,7 @@ var animint = function (to_select, json_file) { // update existing axis var xyaxis_sel = element.select("#"+viz_id+"_"+p_name).select("."+axes+"axis_"+panel_i); var milliseconds = 0; - if(v_name && Selectors.hasOwnProperty(v_name) && Selectors[v_name].hasOwnProperty("duration")){ + if(v_name && Selectors[v_name].hasOwnProperty("duration")){ milliseconds = Selectors[v_name].duration; } var xyaxis_g = xyaxis_sel @@ -2088,9 +2088,6 @@ var animint = function (to_select, json_file) { } var update_selector = function (v_name, value) { - if(!Selectors.hasOwnProperty(v_name)){ - return; - } value = value + ""; var s_info = Selectors[v_name]; if(s_info.type == "single"){ From 4ebbf28ca92002e66d650cfe2f21fe0f71c18981 Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Sun, 8 Mar 2026 20:21:28 +0530 Subject: [PATCH 2/6] animint.js: remove unnecessary Selectors.hasOwnProperty checks --- inst/htmljs/animint.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index 4008ca3b6..e8edea3ec 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1566,10 +1566,7 @@ var animint = function (to_select, json_file) { eAppend = "g"; eActions = function(groups) { // Handle transitions seperately due to unique structure of geom_label_aligned - var transitionDuration = 0; - if (selector_name) { - transitionDuration = +Selectors[selector_name].duration || 0; - } + var transitionDuration = +Selectors[selector_name].duration || 0; groups.each(function(d) { var group = d3.select(this); // Select existing elements (if any) @@ -1863,10 +1860,8 @@ var animint = function (to_select, json_file) { positionTooltip(tooltip, tooltip.html()); }); } - if(selector_name){ - var milliseconds = Selectors[selector_name].duration; - elements = elements.transition().duration(milliseconds); - } + var milliseconds = Selectors[selector_name].duration; + elements = elements.transition().duration(milliseconds); if(g_info.aes.hasOwnProperty("id")){ elements.attr("id", get_attr("id")); } @@ -2011,7 +2006,7 @@ var animint = function (to_select, json_file) { // update existing axis var xyaxis_sel = element.select("#"+viz_id+"_"+p_name).select("."+axes+"axis_"+panel_i); var milliseconds = 0; - if(v_name && Selectors[v_name].hasOwnProperty("duration")){ + if(Selectors[v_name].hasOwnProperty("duration")){ milliseconds = Selectors[v_name].duration; } var xyaxis_g = xyaxis_sel From e139205f4120693825082668af3f24ad994f7839 Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Mon, 9 Mar 2026 05:10:33 +0530 Subject: [PATCH 3/6] Restored if(selector_name) guards; selector_name can be null --- inst/htmljs/animint.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index e8edea3ec..b460f286c 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1566,7 +1566,10 @@ var animint = function (to_select, json_file) { eAppend = "g"; eActions = function(groups) { // Handle transitions seperately due to unique structure of geom_label_aligned - var transitionDuration = +Selectors[selector_name].duration || 0; + var transitionDuration = 0; + if (selector_name) { + transitionDuration = +Selectors[selector_name].duration || 0; + } groups.each(function(d) { var group = d3.select(this); // Select existing elements (if any) @@ -1860,8 +1863,10 @@ var animint = function (to_select, json_file) { positionTooltip(tooltip, tooltip.html()); }); } - var milliseconds = Selectors[selector_name].duration; - elements = elements.transition().duration(milliseconds); + if(selector_name){ + var milliseconds = Selectors[selector_name].duration; + elements = elements.transition().duration(milliseconds); + } if(g_info.aes.hasOwnProperty("id")){ elements.attr("id", get_attr("id")); } From b576d05964f81f38bdbb53fde758dfa0237ead06 Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Wed, 11 Mar 2026 09:45:37 +0530 Subject: [PATCH 4/6] animint.js: check .hasOwnProperty("duration") instead of selector_name only Replace bare if(selector_name) guards in geom_label_aligned and draw_geom with if(selector_name && Selectors[selector_name].hasOwnProperty("duration")) to match the same pattern already used in update_axes (Change 3). --- inst/htmljs/animint.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index b460f286c..dd5f970b0 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1567,7 +1567,7 @@ var animint = function (to_select, json_file) { eActions = function(groups) { // Handle transitions seperately due to unique structure of geom_label_aligned var transitionDuration = 0; - if (selector_name) { + if(selector_name && Selectors[selector_name].hasOwnProperty("duration")){ transitionDuration = +Selectors[selector_name].duration || 0; } groups.each(function(d) { @@ -1863,7 +1863,7 @@ var animint = function (to_select, json_file) { positionTooltip(tooltip, tooltip.html()); }); } - if(selector_name){ + if(selector_name && Selectors[selector_name].hasOwnProperty("duration")){ var milliseconds = Selectors[selector_name].duration; elements = elements.transition().duration(milliseconds); } From 36c892a98db42aac9f7acfaa36b4ec2a3329f7a9 Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Fri, 17 Apr 2026 13:30:11 +0530 Subject: [PATCH 5/6] fix(update_axes): restore Selectors.hasOwnProperty guard and correct NEWS PR number to PR#306 --- NEWS.md | 2 +- inst/htmljs/animint.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 68dfa2662..f56eb79fb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# Changes in version 2026.3.2 (PR#285) +# Changes in version 2026.3.2 (PR#306) - `animint.js`: Remove unnecessary `Selectors.hasOwnProperty` checks (issue #278). Selector names are always valid when accessed, so membership checks are redundant. diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index dd5f970b0..fd1d14d21 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -2011,7 +2011,7 @@ var animint = function (to_select, json_file) { // update existing axis var xyaxis_sel = element.select("#"+viz_id+"_"+p_name).select("."+axes+"axis_"+panel_i); var milliseconds = 0; - if(Selectors[v_name].hasOwnProperty("duration")){ + if(v_name && Selectors.hasOwnProperty(v_name) && Selectors[v_name].hasOwnProperty("duration")){ milliseconds = Selectors[v_name].duration; } var xyaxis_g = xyaxis_sel From 80f12083a9e5f302dcae34750866352d90b346b6 Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Sat, 18 Apr 2026 10:34:24 +0530 Subject: [PATCH 6/6] fix: Added Selectors.hasOwnProperty guard in eActions and draw_geom paths --- inst/htmljs/animint.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index fd1d14d21..1686596ff 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1567,7 +1567,7 @@ var animint = function (to_select, json_file) { eActions = function(groups) { // Handle transitions seperately due to unique structure of geom_label_aligned var transitionDuration = 0; - if(selector_name && Selectors[selector_name].hasOwnProperty("duration")){ + if(selector_name && Selectors.hasOwnProperty(selector_name) && Selectors[selector_name].hasOwnProperty("duration")){ transitionDuration = +Selectors[selector_name].duration || 0; } groups.each(function(d) { @@ -1863,7 +1863,7 @@ var animint = function (to_select, json_file) { positionTooltip(tooltip, tooltip.html()); }); } - if(selector_name && Selectors[selector_name].hasOwnProperty("duration")){ + if(selector_name && Selectors.hasOwnProperty(selector_name) && Selectors[selector_name].hasOwnProperty("duration")){ var milliseconds = Selectors[selector_name].duration; elements = elements.transition().duration(milliseconds); }