From 8c004a1c422ed0aca67113bf82e64f6c3fcd3713 Mon Sep 17 00:00:00 2001 From: Jacco van den Berg Date: Mon, 29 Apr 2024 02:37:29 +0200 Subject: [PATCH] Create parsed object with correct keys (#11690) * Create parsed object with correct keys * Add test --- src/core/core.datasetController.js | 12 ++++++---- .../data/object-index-axis-y.js | 21 ++++++++++++++++++ .../data/object-index-axis-y.png | Bin 0 -> 10245 bytes 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/controller.bar/data/object-index-axis-y.js create mode 100644 test/fixtures/controller.bar/data/object-index-axis-y.png diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 4c7a66255ee..976a3a5f6f4 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 00000000000..0023d08632e --- /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 0000000000000000000000000000000000000000..ace6956afca4ca04f72b53f469d58a50fa848553 GIT binary patch literal 10245 zcmeHtdpwkD+x9g>Hc3cmW!GZGqYbSTm6%zT)GC{5DG?*eUXqdwGt-`gYGo6_N*>%3 zoBx(?LjaAhei^zmf6pqgL2~W}d5;u;NWOZxezi7SSZWm-I4>1FLTXjx4g?Y{Bbm5w z_uNC!(g17yswnFLrSZXE*6a#g739*-^R7e_C6brtYP zhg*)eT*tWn{rXa1DnU#f_#T7X!gwe&6?+}q9N2lQ&lrtD60SMgZbqPgUkyBP>t4-y zEdh809*0+!I+@Fe1IrkYJd+zfx4S>PjR2A(WuPT8>$RXyGAgZ95Ar02p}TW3(sh8x zGm$CgTSTTrDSj6Sko;sB*n~356~&e`F7fDG%bU-QJZIcuef?;fUVvL*suo|PU4lHZC%uu!7Gy4 z4;CQ_kA4M>JQylbI{Z1$(4evMDzxOPvO;D?rLAk4tR7BmQX6=*+uACEO-DthXeEeD zsgf3DZkG-?yDhPPdX~8Hw98+$+A%7kGPLMa1Z{8vQ)gQ_o+z)y17OVUP_G z&f}~rAo+d(@~<(6E^=!~^7U@ZD!?*I+KhbKZPbMDXOVjz#DQDr5j{~Ze_vIiyHSc=Jh!Y;S7ox2HLE`!C2hX`gK6ps(^SQN7c8qIk%>ls=g2lfY&?F%))F+H zfbr9eI6VjOy5FHD0)0pXDLyW9kn(4Qhd9*_L(kh05!PzkpPt)%?ceD3zX9E{tHJ58 z`#tS@`aTBs1S>08Dxr9rE{1FlF!&3oUu;~}%35}9_VIW#hdGzL z5PcVV);g`YH8_qZa>i@W>ANmF*9B94c{;Ru$<%=lY0Umu5k$jw1%YF}9_)5)vR&AO zV~|*LvDb-n9s&jMd8_1(%XSU>R(wuY5iGyiFGKq>H=^RmaG6I~+k1-{RsnlJD*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