# All files scaleFinder.js

100% Statements 16/16
100% Branches 0/0
100% Functions 7/7
100% Lines 14/14

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41

    5x

    470x
    470x
    3x

    3x

    1x
    1x

    1x

    1x
    1x

    1x

    1x
    1x

    1x

     import { max, min }    from "d3-array";
    import { scaleLinear } from "d3-scale";
    import { scaleTime }   from "d3-scale";
    import { scaleBand }   from "d3-scale";

    class ScaleFinder {
        constructor(data){
            this.data = data;
        }

        getInterval(){
            const MAX      = max(this.data, d => d);
            const MIN      = min(this.data, d => d);
            const interval = [MIN, MAX];

            return interval;
        }

        getLinearScale(){
            const interval = this.getInterval();
            const scale    =  scaleLinear().domain(interval);

            return scale;
        }

        getTimeScale(){
            const interval = this.getInterval();
            const scale    = scaleTime().domain(interval);

            return scale;
        }

        getOrdinalScale(binWidth){
            const scale = scaleBand().domain(this.data);
            scale.padding([binWidth]);

            return scale;
        }
    }

    export default ScaleFinder;