1 point

Safer margins for a graph


dashboard

Tue Dec 17 2019 06:09:11 GMT+0000 (UTC)

Posted 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_copy

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



>> Browse more code snippets

more_vert