Skip to content

Commit 8c004a1

Browse files
authored
Create parsed object with correct keys (#11690)
* Create parsed object with correct keys * Add test
1 parent 1777f95 commit 8c004a1

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/core/core.datasetController.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,18 @@ function applyStack(stack, value, dsIndex, options = {}) {
9292
return value;
9393
}
9494

95-
function convertObjectDataToArray(data) {
95+
function convertObjectDataToArray(data, meta) {
96+
const {iScale, vScale} = meta;
97+
const iAxisKey = iScale.axis === 'x' ? 'x' : 'y';
98+
const vAxisKey = vScale.axis === 'x' ? 'x' : 'y';
9699
const keys = Object.keys(data);
97100
const adata = new Array(keys.length);
98101
let i, ilen, key;
99102
for (i = 0, ilen = keys.length; i < ilen; ++i) {
100103
key = keys[i];
101104
adata[i] = {
102-
x: key,
103-
y: data[key]
105+
[iAxisKey]: key,
106+
[vAxisKey]: data[key]
104107
};
105108
}
106109
return adata;
@@ -362,7 +365,8 @@ export default class DatasetController {
362365
// the internal metadata accordingly.
363366

364367
if (isObject(data)) {
365-
this._data = convertObjectDataToArray(data);
368+
const meta = this._cachedMeta;
369+
this._data = convertObjectDataToArray(data, meta);
366370
} else if (_data !== data) {
367371
if (_data) {
368372
// This case happens when the user replaced the data array instance.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
config: {
3+
type: 'bar',
4+
data: {
5+
datasets: [{
6+
label: '# of Votes',
7+
data: {a: 1, b: 3, c: 2}
8+
}]
9+
},
10+
options: {
11+
indexAxis: 'y'
12+
}
13+
},
14+
options: {
15+
spriteText: true,
16+
canvas: {
17+
height: 256,
18+
width: 512
19+
}
20+
}
21+
};
Loading

0 commit comments

Comments
 (0)