# All files / utils/legend sort.ts

94.44% Statements 17/18
83.33% Branches 10/12
100% Functions 5/5
93.75% Lines 15/16

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

    3x

    7x

    7x

    7x
    7x

    428x

    7x
    7x
    428x
    427x

    428x
    428x

    1329x
    428x

     import {DomainLabel, LineData} from '../../types'

    export const getDataSortOrder = (
      lineData: LineData,
      rowIndices: number[],
      domainLabel?: DomainLabel
    ): number[] => {
      Iif (!lineData || !rowIndices?.length) {
        return []
      }

      const domainLabelName = domainLabel || DomainLabel.Y

      const numberMap = {}
      const numericalValues = Object.keys(lineData).reduce(
        (combinedNumericalValues, id) =>
          combinedNumericalValues.concat(lineData[id][domainLabelName]),
        []
      )
      const sortable = []
      rowIndices.forEach(rowIndex => {
        if (!numberMap[numericalValues[rowIndex]]) {
          numberMap[numericalValues[rowIndex]] = []
        }
        numberMap[numericalValues[rowIndex]].push(rowIndex)
        sortable.push(numericalValues[rowIndex])
      })
      sortable.sort((first, second) => second - first)
      return sortable.map(numericalValue => numberMap[numericalValue].shift())
    }