null category values sometimes not replaced with "Blank"
The chartUpdateData.js file includes several functions that look for empty strings or null
chart category values and replaces them with the word Blank
. However, the existing code sometimes fails to work.
Current code:
var index = nameList.indexOf(null || ""); if (index !== -1) {nameList[index] = "Blank";}
For the above code if nameList
contains null
values, but no empty values then the null
values are not replaced with Blank
. This seems to be because the || ""
part of the indexOf
is run after the check for null
, and returns -1
as no empty strings were found.
In addition, the above code will only ever find the first instance of the problematic category name. We need to find and replace them all.
I think that the solution is to have an array of things to check for, and loop through each. Something like this should solve both issues above:
var blank_indicators = ["", null]; var i, j; for (i = 0; i < blank_indicators.length; i++) { for (j = 0; j < nameList.length; j++) { if (nameList[j] === blank_indicators[i]) { nameList[j] = "Blank"; } } }
Comments (4)
-
reporter -
reporter The updated JavaScript fixes this issue so I have updated the changes files [skip ci]. References issue
#639→ <<cset f0880b75e3d1>>
-
reporter Moved blank checking to a function to reduce duplication. Changed a variable name to camel case. Hopefully these changes will brighten up Codacy's day [skip ci]. References issue
#639→ <<cset fb9d860de680>>
-
- changed status to resolved
- Log in to comment
Improved code to replace null and empty chart categories with the text . JavaScript changes only [skip ci]. References issue
#639→ <<cset 925c79762c6b>>