From: Jukka Kurkela Date: Tue, 9 Mar 2021 13:08:36 +0000 (+0200) Subject: scale.category: options.min/max can be index (#8594) X-Git-Tag: v3.0.0-beta.14~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b00514347036d14bd44807d57c503eadde3212e7;p=thirdparty%2FChart.js.git scale.category: options.min/max can be index (#8594) --- diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index 868b24b5c..c6efd61b8 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 8142c8db6..8f5aafe70 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 acaf00c9b..8640be64a 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 d2270e26f..eb0ccb1ec 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 45b7fd850..e97bfcecb 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