]> git.ipfire.org Git - thirdparty/Chart.js.git/commit
Fix out of bounds index access in getLabelMoment 3039/head
authorIan Ker-Seymer <i.kerseymer@gmail.com>
Tue, 26 Jul 2016 18:45:05 +0000 (14:45 -0400)
committerIan Ker-Seymer <i.kerseymer@gmail.com>
Tue, 26 Jul 2016 18:45:05 +0000 (14:45 -0400)
commite4dd158b241268600bb1c9005969af7b2efcb130
treea5640844456a143b10fe677ba3f7f28992d3a779
parenta0d8554117cb506a0d96e922ef52360dab538b3f
Fix out of bounds index access in getLabelMoment

Previously, calling getLabelMoment with an out of bound index would cause an
error such as this:

```
Uncaught TypeError: Cannot read property 'null' of undefined
```

This happens because there is not always guaranteed to be a labelMoment on
at the current datasetIndex.

One example of this is practice comes from a this function call:

```js
// since the are not always guaranteed to be at least two labelMoments
//                                \ / this index can be out of bounds
//                                 |
var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
```

This patch simply ensures that the `labelMoments` for the `datasetIndex` are
defined before accessing properties on it.
src/scales/scale.time.js
test/scale.time.tests.js