function getStackedData(children, attr) {
  const areSomeSeriesStacked = children.some(
    series => series && series.props.stack
  );
  // It stores the last segment position added to each bar, separated by cluster.
  const latestAttrPositions = {};

  return children.reduce((accumulator, series) => {
    // Skip the children that are not series (e.g. don't have any data).
    if (!series) {
      accumulator.push(null);
      return accumulator;
    }
    const seriesType = series.type.displayName;

    const {data, cluster = 'default', stack} = series.props;
    const preppedData = prepareData(data, attr);

    if (
      !attr ||
      !preppedData ||
      !preppedData.length ||
      (areSomeSeriesStacked && !stack)
    ) {
      accumulator.push(preppedData);
      return accumulator;
    }

    const attr0 = `${attr}0`;
    const baseAttr = attr === 'y' ? 'x' : 'y';

    accumulator.push(
      preppedData.map(d => {
        if (!latestAttrPositions[cluster]) {
          latestAttrPositions[cluster] = {};
        }
        if (!latestAttrPositions[cluster][seriesType]) {
          latestAttrPositions[cluster][seriesType] = {};
        }

        const prevD = latestAttrPositions[cluster][seriesType][d[baseAttr]];
        // It is the first segment of a bar.
        if (!prevD) {
          latestAttrPositions[cluster][seriesType][d[baseAttr]] = {
            [attr0]: d[attr0],
            [attr]: d[attr]
          };

          return {...d};
        }

        // Calculate the position of the next segment in a bar.
        const nextD = {
          ...d,
          [attr0]: prevD[attr],
          [attr]: prevD[attr] + d[attr] - (d[attr0] || 0)
        };

        latestAttrPositions[cluster][seriesType][d[baseAttr]] = {
          [attr0]: nextD[attr0],
          [attr]: nextD[attr]
        };

        return nextD;
      })
    );

    return accumulator;
  }, []);
}
Collect the stacked data for all children in use. If the children don't have
the data (e.g. the child is invalid series or something else), then the child
is skipped.
Each next value of attr is equal to the previous value plus the difference
between attr0 and attr.
@param {Array} children Array of children.
@param {string} attr Attribute to stack by.
@returns {Array} New array of children for the series.