static getMargin()

in src/YAxisLabels.js [212:241]


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

    if (
      (position === 'left' && placement === 'after') ||
      (position === 'right' && placement === 'before')
    )
      return zeroMargin;

    const marginX = max(labels.map(label => Math.ceil(distance + label.width)));
    const [marginTop, marginBottom] = getLabelsYOverhang(
      yScale,
      labels,
      'middle',
    );

    return defaults(
      { [`margin${capitalize(position)}`]: marginX, marginTop, marginBottom },
      zeroMargin,
    );
  }