From: Jacco van den Berg Date: Mon, 29 Apr 2024 00:37:29 +0000 (+0200) Subject: Create parsed object with correct keys (#11690) X-Git-Tag: v4.4.3~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8c004a1c422ed0aca67113bf82e64f6c3fcd3713;p=thirdparty%2FChart.js.git Create parsed object with correct keys (#11690) * Create parsed object with correct keys * Add test --- diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 4c7a66255..976a3a5f6 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -92,15 +92,18 @@ function applyStack(stack, value, dsIndex, options = {}) { return value; } -function convertObjectDataToArray(data) { +function convertObjectDataToArray(data, meta) { + const {iScale, vScale} = meta; + const iAxisKey = iScale.axis === 'x' ? 'x' : 'y'; + const vAxisKey = vScale.axis === 'x' ? 'x' : 'y'; const keys = Object.keys(data); const adata = new Array(keys.length); let i, ilen, key; for (i = 0, ilen = keys.length; i < ilen; ++i) { key = keys[i]; adata[i] = { - x: key, - y: data[key] + [iAxisKey]: key, + [vAxisKey]: data[key] }; } return adata; @@ -362,7 +365,8 @@ export default class DatasetController { // the internal metadata accordingly. if (isObject(data)) { - this._data = convertObjectDataToArray(data); + const meta = this._cachedMeta; + this._data = convertObjectDataToArray(data, meta); } else if (_data !== data) { if (_data) { // This case happens when the user replaced the data array instance. diff --git a/test/fixtures/controller.bar/data/object-index-axis-y.js b/test/fixtures/controller.bar/data/object-index-axis-y.js new file mode 100644 index 000000000..0023d0863 --- /dev/null +++ b/test/fixtures/controller.bar/data/object-index-axis-y.js @@ -0,0 +1,21 @@ +module.exports = { + config: { + type: 'bar', + data: { + datasets: [{ + label: '# of Votes', + data: {a: 1, b: 3, c: 2} + }] + }, + options: { + indexAxis: 'y' + } + }, + options: { + spriteText: true, + canvas: { + height: 256, + width: 512 + } + } +}; diff --git a/test/fixtures/controller.bar/data/object-index-axis-y.png b/test/fixtures/controller.bar/data/object-index-axis-y.png new file mode 100644 index 000000000..ace6956af Binary files /dev/null and b/test/fixtures/controller.bar/data/object-index-axis-y.png differ