Skip to content

Commit 2915be8

Browse files
committed
auspice: Update serum id creation
Replace any characters in the serum name that are not alphanumeric, dashes or underscores with an underscore to create a serum id that can used as a query selector. I know that replacing with just an underscore is not the most robust way to create unique IDs, but this is just a quick fix to get the private flu site working again. Also refactored the three separate serum id creations into a single function so that I don't have to change the code in three places.
1 parent 2682944 commit 2915be8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

auspice/js/auspice/colors.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ function resetFocusNode() {
425425
}
426426
}
427427

428+
function createSerumId(serum) {
429+
// Regex for replacing characters in the serum name that are not alphanumeric or underscores
430+
const REPLACE_SERUM_ID_REGEX = new RegExp(/[^a-zA-Z0-9-\_]/g);
431+
return "s" + serum.split("/").join("").replace(REPLACE_SERUM_ID_REGEX, "_");
432+
}
433+
428434
function newFocus(){
429435
if (typeof(focusNode)=="undefined"){
430436
resetFocusNode();
@@ -448,18 +454,18 @@ function newFocus(){
448454

449455
for (var i=0; i<allSera.length; i++){
450456
var serum = allSera[i];
451-
var serumID = "s" + serum.split("/").join("").replace(/[;,\s\'\+\*\.\(\)]/g, "_");
457+
var serumID = createSerumId(serum);
452458
htmlStr+='<input type="checkbox" id="' + serumID + '" name="' + serum + '" checked="checked"> ' + serum +"<br>";
453459
activeSera[serum]=true;
454460
}
455461
seraDiv.innerHTML = htmlStr;
456462
for (var serum in titer_subs_model["potency"][focusNode.strain]){
457-
var serumID = "s" + serum.split("/").join("").replace(/[;,\s\'\+\*\.\(\)]/g, "_");
463+
var serumID = createSerumId(serum);
458464
d3.select("#"+serumID)
459465
.on("change", function(elem){
460466
for (var j=0; j<allSera.length; j++){
461467
var tmpserum = allSera[j];
462-
var tmpserumID = "s" + tmpserum.split("/").join("").replace(/[;,\s\'\+\*\.\(\)]/g, "_");
468+
var tmpserumID = createSerumId(tmpserum);
463469
activeSera[tmpserum]=document.getElementById(tmpserumID).checked;
464470
}
465471
colorByHIDistance()});

0 commit comments

Comments
 (0)