From 0ac803713b2af004e106a5226c4c97db7968369f Mon Sep 17 00:00:00 2001 From: Gauarv Chaudhary Date: Mon, 2 Mar 2026 17:29:15 +0530 Subject: [PATCH 1/8] 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 | 2 +- NEWS.md | 5 +++++ inst/htmljs/animint.js | 9 +++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7d97b752f..4fb8c12eb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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"), person("Nandani", "Aggarwal", role="ctb", comment="Removed geom_dotplot and replaced with error")) diff --git a/NEWS.md b/NEWS.md index 7c10aef35..f5dc8cbde 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,11 @@ - `geom_dotplot()` has been removed. Use `geom_point()` instead for interactive visualizations. (Fixed #289) +# 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. + # 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 3bc738f87..5232c52c1 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1642,7 +1642,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) { @@ -1938,7 +1938,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); } @@ -2086,7 +2086,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 @@ -2163,9 +2163,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 ba48e08b71b01d8022913e214d53b8d93ad20d58 Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Sun, 8 Mar 2026 20:21:28 +0530 Subject: [PATCH 2/8] 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 5232c52c1..bf2b52ae1 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1641,10 +1641,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) @@ -1938,10 +1935,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")); } @@ -2086,7 +2081,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 e5ce707eec4e82e52e8d956cec704524a911a5eb Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Mon, 9 Mar 2026 05:10:33 +0530 Subject: [PATCH 3/8] 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 bf2b52ae1..fcb8a1db8 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1641,7 +1641,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) @@ -1935,8 +1938,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 5d2550e88a8ea19b1d4ffce2649a26def6eaa036 Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Wed, 11 Mar 2026 09:45:37 +0530 Subject: [PATCH 4/8] 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 fcb8a1db8..31f204365 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1642,7 +1642,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) { @@ -1938,7 +1938,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 dd210bd26ca55fa5290d16f4bf012e0fa285545c Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Fri, 17 Apr 2026 13:30:11 +0530 Subject: [PATCH 5/8] fix(update_axes): restore Selectors.hasOwnProperty guard and correct NEWS PR number to PR#306 --- inst/htmljs/animint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index 31f204365..4783954b3 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -2086,7 +2086,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 008ab95ae7e62576415be9440fc72a5ed632fb58 Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Sat, 18 Apr 2026 10:34:24 +0530 Subject: [PATCH 6/8] 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 4783954b3..46e0e28d9 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -1642,7 +1642,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) { @@ -1938,7 +1938,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); } From f040ff7f9c745e55c8564943f79ee8781f37884c Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Fri, 29 May 2026 09:15:54 +0530 Subject: [PATCH 7/8] refactor(animint.js): centralize selector duration guard for #278 Use selector_has_duration() for geom_label_aligned, draw_geom, and update_axes so null selector_name on initial update_geom(g, null) stays safe and we only transition when duration is defined. Remove redundant hasOwnProperty guard in update_selector. --- inst/htmljs/animint.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index 46e0e28d9..f0d5dc995 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -101,6 +101,12 @@ var animint = function (to_select, json_file) { return safe_name(selector_name) + "_variable"; } + function selector_has_duration(name) { + return !!(name && + Selectors.hasOwnProperty(name) && + Selectors[name].hasOwnProperty("duration")); + } + function is_interactive_aes(v_name){ if(v_name.indexOf("clickSelects") > -1){ return true; @@ -1642,7 +1648,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.hasOwnProperty(selector_name) && Selectors[selector_name].hasOwnProperty("duration")){ + if(selector_has_duration(selector_name)){ transitionDuration = +Selectors[selector_name].duration || 0; } groups.each(function(d) { @@ -1938,7 +1944,7 @@ var animint = function (to_select, json_file) { positionTooltip(tooltip, tooltip.html()); }); } - if(selector_name && Selectors.hasOwnProperty(selector_name) && Selectors[selector_name].hasOwnProperty("duration")){ + if(selector_has_duration(selector_name)){ var milliseconds = Selectors[selector_name].duration; elements = elements.transition().duration(milliseconds); } @@ -2086,7 +2092,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(selector_has_duration(v_name)){ milliseconds = Selectors[v_name].duration; } var xyaxis_g = xyaxis_sel From 3e7b176d8e7c206f813e43c12e8e794fbc7990ad Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Fri, 29 May 2026 21:39:23 +0530 Subject: [PATCH 8/8] address review: simplify selector_has_duration, move attribution to NEWS - DESCRIPTION: Gaurav comment -> GSOC 2026 - animint.js: drop git status and Selectors.hasOwnProperty; keep name guard for null selector_name on initial render - NEWS.md: PR#306 attribution and accurate changelog wording --- DESCRIPTION | 2 +- NEWS.md | 3 +-- inst/htmljs/animint.js | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4fb8c12eb..73aad0d6f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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; #278 Removed unnecessary Selectors.hasOwnProperty checks in animint.js"), + comment="GSOC 2026"), person("Nandani", "Aggarwal", role="ctb", comment="Removed geom_dotplot and replaced with error")) diff --git a/NEWS.md b/NEWS.md index f5dc8cbde..7d3d8c548 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,8 +8,7 @@ # 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. +- `animint.js`: Remove redundant `Selectors.hasOwnProperty` checks and use a shared `selector_has_duration()` helper (issue #278, PR#306). # Changes in version 2025.12.4 (PR#277) diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index f0d5dc995..382df8962 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -101,10 +101,10 @@ var animint = function (to_select, json_file) { return safe_name(selector_name) + "_variable"; } + // selector_name can be null for geoms without a selector (initial render via update_geom(g, null)). function selector_has_duration(name) { - return !!(name && - Selectors.hasOwnProperty(name) && - Selectors[name].hasOwnProperty("duration")); + return name && + Selectors[name].hasOwnProperty("duration"); } function is_interactive_aes(v_name){