# All files / utils resolveDomain.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    265x

    5x

    17x
    11x

    6x

    17x

    2x
    2x

    17x

     import {extent} from 'd3-array'

    import {NumericColumnData} from '../types'

    export const resolveDomain = (
      data: NumericColumnData,
      preferredDomain?: number[]
    ): [number, number] => {
      let domain: [number, number]

      if (preferredDomain) {
        domain = [preferredDomain[0], preferredDomain[1]]
      } else {
        domain = extent(data)
      }

      if (domain[0] === domain[1]) {
        // Widen domains of zero width by an arbitrary amount so that they can be
        // divided into bins
        domain[0] = domain[0] - 0.5
        domain[1] = domain[1] + 0.5
      }

      return domain
    }