Safer margins for a graph

PHOTO EMBED

Tue Dec 17 2019 06:09:11 GMT+0000 (Coordinated Universal Time)

Saved by @salitha.pathi #javascript

    let findMargins = (maximum: number) => {
      const _sign = maximum < 0 ? -1 : 1;
      const _maximum = Math.abs(maximum);
      const _multiplier = Math.pow(10, Math.floor(_maximum).toString().length - 1);
      return Math.ceil(_maximum / _multiplier) * _multiplier * _sign;
    }
content_copyCOPY

This decides the best margin for a graph when maximum of the each axis provided. If negative given, returns negative margin