Skip to content

Commit

Permalink
Fixed misplaced data points on category scale
Browse files Browse the repository at this point in the history
* Fixed issue, that category scale shows data points misplaced. See chartjs#4060
* Cleaned code
* Fixed Irregular whitespace
* Fixed error in case value is undefined
* Verified that no error is thrown in case value === null
  • Loading branch information
martinzuern authored and ericnkatz committed May 24, 2017
1 parent e72d43c commit bb3139e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/scales/scale.category.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ module.exports = function(Chart) {
// 1 is added because we need the length but we have the indexes
var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);

if (value !== undefined && isNaN(index)) {
// If value is a data object, then index is the index in the data array,
// not the index of the scale. We need to change that.
var valueCategory;
if (value !== undefined && value !== null) {
valueCategory = me.isHorizontal() ? value.x : value.y;
}
if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
var labels = me.getLabels();
value = valueCategory || value;
var idx = labels.indexOf(value);
index = idx !== -1 ? idx : index;
}
Expand Down

0 comments on commit bb3139e

Please sign in to comment.