# All files / utils resolveDomain.ts

22.22% Statements 2/9
0% Branches 0/4
0% Functions 0/1
22.22% Lines 2/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
    261x

    1x

     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
    }