ixfx
    Preparing search index...

    Function scale

    • Scales v from an input range to an output range (aka map)

      For example, if a sensor's useful range is 100-500, scale it to a percentage:

      import { scale } from 'https://unpkg.com/ixfx/dist/data.js';

      scale(sensorReading, 100, 500, 0, 1);

      scale defaults to a percentage-range output, so you can get away with:

      scale(sensorReading, 100, 500);
      

      If v is outside of the input range, it will likewise be outside of the output range. Use scaleClamped to clip value to range.

      If inMin and inMax are equal, outMax will be returned.

      An easing function can be provided for non-linear scaling. In this case the input value is 'pre scaled' using the function before it is applied to the output range.

      scale(sensorReading, 100, 500, 0, 1, Easings.gaussian());
      

      Parameters

      • v: number

        Value to scale

      • inMin: number

        Input minimum

      • inMax: number

        Input maximum

      • OptionaloutMin: number

        Output minimum. If not specified, 0

      • OptionaloutMax: number

        Output maximum. If not specified, 1

      • Optionaleasing: (v: number) => number

        Easing function

      Returns number

      Scaled value