static getMargin()

in src/XAxisLabels.js [238:273]


  static getMargin(props) {
    const propsWithDefaults = defaults({}, props, XAxisLabels.defaultProps);
    const { xScale, position, placement, distance } = propsWithDefaults;
    const labels =
      propsWithDefaults.labels || XAxisLabels.getLabels(propsWithDefaults);
    const zeroMargin = {
      marginTop: 0,
      marginBottom: 0,
      marginLeft: 0,
      marginRight: 0,
    };

    if (
      (position === 'bottom' && placement === 'above') ||
      (position === 'top' && placement === 'below')
    )
      return zeroMargin;

    const marginY = max(
      labels.map(label => Math.ceil(distance + label.height)),
    );
    let textAnchor = 'middle';
    if (propsWithDefaults.noLabelOverhang) {
      textAnchor = 'start';
    }
    const [marginLeft, marginRight] = getLabelsXOverhang(
      xScale,
      labels,
      textAnchor,
    );

    return defaults(
      { [`margin${capitalize(position)}`]: marginY, marginLeft, marginRight },
      zeroMargin,
    );
  }