Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create parsed object with correct keys #11690

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/core/core.datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/controller.bar/data/object-index-axis-y.js
Original file line number Diff line number Diff line change
@@ -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
}
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading