Skip to content

Commit

Permalink
Create parsed object with correct keys
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeLenaleee committed Feb 28, 2024
1 parent 7736ea3 commit c63adcd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/core.datasetController.js
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

0 comments on commit c63adcd

Please sign in to comment.