Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Heatmap data values test does not detect wrong values if they are string #234

Closed
tchaffee opened this issue Oct 9, 2017 · 0 comments · Fixed by #240
Closed

Heatmap data values test does not detect wrong values if they are string #234

tchaffee opened this issue Oct 9, 2017 · 0 comments · Fixed by #240

Comments

@tchaffee
Copy link
Contributor

tchaffee commented Oct 9, 2017

Issue Description

Test 8 for the D3 Heat Map is supposed to ensure that the data-month attribute has values between 0 and 11 and it does not always do this. If the data-month attribute has a string value ('January' for example), the test will still pass. The test should be fixed to determine if the data values are numeric, and to fail if they are not.

The code can be fixed by adding a isNaN check to the valuesAreBetween function (near line 182), after converting the data item to a number:

function valuesAreBetween(min, max, data) {
  for (var i = 0; i < data.length; i++) {
    // Note the use of the unary add (plus sign) before the data element
    // to attempt to convert to a number.
    var item = +data[i];

    if (isNaN(item)) {
      return false;
    }

    if (item < min || item > max) {
      return false;
    }
  }
  return true;
}

Browser Information

N/A

Your Code / Link to Your Pen

https://codepen.io/tom-p-uk/pen/ZeQEaE

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant