Skip to content

Commit

Permalink
scale.category: options.min/max can be index (#8594)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle authored Mar 9, 2021
1 parent 7ec99c3 commit b005143
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/scales/scale.category.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Scale from '../core/core.scale';
import {valueOrDefault} from '../helpers';

function findOrAddLabel(labels, raw, index) {
const first = labels.indexOf(raw);
Expand All @@ -22,7 +23,7 @@ export default class CategoryScale extends Scale {
parse(raw, index) {
const labels = this.getLabels();
return isFinite(index) && labels[index] === raw
? index : findOrAddLabel(labels, raw, index);
? index : findOrAddLabel(labels, raw, valueOrDefault(index, raw));
}

determineDataLimits() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"indexAxis": "y",
"scales": {
"x": {
"display": false,
"min": -8,
"max": 12
"display": false
},
"y": {
"display": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
},
"y": {
"display": false,
"stacked": true,
"min": -8,
"max": 12
"stacked": true
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/controller.bar/floatBar/float-bar-stacked.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"scales": {
"x": {
"display": false,
"stacked": true,
"min": -8,
"max": 12
"stacked": true
},
"y": {
"display": false,
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/controller.bar/floatBar/float-bar.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
"options": {
"scales": {
"x": {
"display": false,
"min": -8,
"max": 12
"display": false
},
"y": {
"display": false
Expand Down

0 comments on commit b005143

Please sign in to comment.