From df2460664a9521c167f901b4823169a071b1487f Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Tue, 9 Mar 2021 11:23:42 +0200 Subject: [PATCH] scale.category: options.min/max can be index --- src/scales/scale.category.js | 3 ++- .../controller.bar/floatBar/float-bar-horizontal.json | 4 +--- .../controller.bar/floatBar/float-bar-stacked-horizontal.json | 4 +--- test/fixtures/controller.bar/floatBar/float-bar-stacked.json | 4 +--- test/fixtures/controller.bar/floatBar/float-bar.json | 4 +--- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index 868b24b5c81..c6efd61b8f4 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -1,4 +1,5 @@ import Scale from '../core/core.scale'; +import {valueOrDefault} from '../helpers'; function findOrAddLabel(labels, raw, index) { const first = labels.indexOf(raw); @@ -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() { diff --git a/test/fixtures/controller.bar/floatBar/float-bar-horizontal.json b/test/fixtures/controller.bar/floatBar/float-bar-horizontal.json index 8142c8db608..8f5aafe70f0 100644 --- a/test/fixtures/controller.bar/floatBar/float-bar-horizontal.json +++ b/test/fixtures/controller.bar/floatBar/float-bar-horizontal.json @@ -18,9 +18,7 @@ "indexAxis": "y", "scales": { "x": { - "display": false, - "min": -8, - "max": 12 + "display": false }, "y": { "display": false diff --git a/test/fixtures/controller.bar/floatBar/float-bar-stacked-horizontal.json b/test/fixtures/controller.bar/floatBar/float-bar-stacked-horizontal.json index acaf00c9bb6..8640be64a7c 100644 --- a/test/fixtures/controller.bar/floatBar/float-bar-stacked-horizontal.json +++ b/test/fixtures/controller.bar/floatBar/float-bar-stacked-horizontal.json @@ -23,9 +23,7 @@ }, "y": { "display": false, - "stacked": true, - "min": -8, - "max": 12 + "stacked": true } } } diff --git a/test/fixtures/controller.bar/floatBar/float-bar-stacked.json b/test/fixtures/controller.bar/floatBar/float-bar-stacked.json index d2270e26f65..eb0ccb1ec91 100644 --- a/test/fixtures/controller.bar/floatBar/float-bar-stacked.json +++ b/test/fixtures/controller.bar/floatBar/float-bar-stacked.json @@ -18,9 +18,7 @@ "scales": { "x": { "display": false, - "stacked": true, - "min": -8, - "max": 12 + "stacked": true }, "y": { "display": false, diff --git a/test/fixtures/controller.bar/floatBar/float-bar.json b/test/fixtures/controller.bar/floatBar/float-bar.json index 45b7fd8503d..e97bfcecbf8 100644 --- a/test/fixtures/controller.bar/floatBar/float-bar.json +++ b/test/fixtures/controller.bar/floatBar/float-bar.json @@ -17,9 +17,7 @@ "options": { "scales": { "x": { - "display": false, - "min": -8, - "max": 12 + "display": false }, "y": { "display": false