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

correct stacked domain logic: #268

Merged
merged 1 commit into from
Jul 17, 2017
Merged
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
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