# All files / transforms scatter.ts

25% Statements 4/16
0% Branches 0/4
0% Functions 0/1
33.33% Lines 4/12

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
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    481x

    1x
    1x

    1x

     import {extent} from 'd3-array'

    import {Table, ScatterLayerSpec} from '../types'
    import {FILL, SYMBOL} from '../constants/columnKeys'
    import {createGroupIDColumn, getNominalColorScale, getSymbolScale} from './'

    export const scatterTransform = (
      inputTable: Table,
      xColumnKey: string,
      yColumnKey: string,
      fillColKeys: string[],
      symbolColKeys: string[],
      colors: string[]
    ): ScatterLayerSpec => {
      const [fillColumn, fillColumnMap] = createGroupIDColumn(
        inputTable,
        fillColKeys
      )

      const [symbolColumn, symbolColumnMap] = createGroupIDColumn(
        inputTable,
        symbolColKeys
      )

      const table = inputTable
        .addColumn(FILL, 'system', 'number', fillColumn)
        .addColumn(SYMBOL, 'system', 'number', symbolColumn)

      const xCol = table.getColumn(xColumnKey, 'number') || []
      const yCol = table.getColumn(yColumnKey, 'number') || []
      const fillScale = getNominalColorScale(fillColumnMap, colors)
      const symbolScale = getSymbolScale(symbolColumnMap)

      return {
        type: 'scatter',
        inputTable,
        table,
        xDomain: extent(xCol),
        yDomain: extent(yCol),
        xColumnKey,
        yColumnKey,
        xColumnType: inputTable.getColumnType(xColumnKey),
        yColumnType: inputTable.getColumnType(yColumnKey),
        scales: {fill: fillScale, symbol: symbolScale},
        columnGroupMaps: {fill: fillColumnMap, symbol: symbolColumnMap},
      }
    }