Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #268 from FormidableLabs/bug/stacked-domain
Browse files Browse the repository at this point in the history
correct stacked domain logic:
  • Loading branch information
boygirl authored Jul 17, 2017
2 parents 8697ca0 + 91466af commit c810b23
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/victory-util/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ export default {
return this.getDomainFromCategories(props, axis);
}
const globalDomain = this.getDomainFromData(props, axis, datasets);

// find the cumulative max for stacked chart types
const cumulativeData = !dependent ?
this.getCumulativeData(props, axis, datasets) : [];

const cumulativeMaxArray = cumulativeData.map((dataset) => {
return dataset.reduce((memo, val) => {
return val > 0 ? +val + +memo : memo;
Expand Down Expand Up @@ -237,22 +235,23 @@ export default {
*/
getCumulativeData(props, axis, datasets) {
const currentAxis = Helpers.getCurrentAxis(axis, props.horizontal);
const otherAxis = currentAxis === "x" ? "y" : "x";
const categories = [];
const axisValues = [];
datasets.forEach((dataset) => {
dataset.forEach((data) => {
if (data.category !== undefined && !includes(categories, data.category)) {
categories.push(data.category);
} else if (!includes(axisValues, data[currentAxis])) {
axisValues.push(data[currentAxis]);
} else if (!includes(axisValues, data[`_${otherAxis}`])) {
axisValues.push(data[`_${otherAxis}`]);
}
});
});

const _dataByCategory = () => {
return categories.map((value) => {
return datasets.reduce((prev, data) => {
return data.category === value ? prev.concat(data[axis]) : prev;
return data.category === value ? prev.concat(data[`_${axis}`]) : prev;
}, []);
});
};
Expand All @@ -262,7 +261,6 @@ export default {
return datasets.map((data) => data[index] && data[index][`_${currentAxis}`]);
});
};

return categories.length === 0 ? _dataByIndex() : _dataByCategory();
},

Expand Down

0 comments on commit c810b23

Please sign in to comment.