# All files / utils/legend sort.ts

94.44% Statements 17/18
75% Branches 9/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
    314x

    4x

    7x

    7x

    7x
    7x

    428x

    7x
    7x
    428x
    428x

    428x
    428x

    1311x
    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 => {
        Eif (!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())
    }