private def sort()

in atlas-eval/src/main/scala/com/netflix/atlas/eval/graph/Grapher.scala [442:477]


  private def sort(
    warnings: scala.collection.mutable.Builder[String, List[String]],
    sortBy: Option[String],
    useDescending: Boolean,
    lines: List[LineDef]
  ): List[LineDef] = {

    // The default is sort by legend in ascending order. If the defaults have been explicitly
    // changed, then the explicit values should be used. Since the sort by param is used to
    // short circuit if there is nothing to do, it will get set to legend explicitly here if
    // the order has been changed to descending.
    val by = if (useDescending) Some(sortBy.getOrElse("legend")) else sortBy

    by.fold(lines) { mode =>
      val cmp: Function2[LineDef, LineDef, Boolean] = mode match {
        case "legend" =>
          (a, b) => compare(useDescending, a.data.label, b.data.label)
        case "min" =>
          (a, b) => compare(useDescending, a.legendStats.min, b.legendStats.min)
        case "max" =>
          (a, b) => compare(useDescending, a.legendStats.max, b.legendStats.max)
        case "avg" =>
          (a, b) => compare(useDescending, a.legendStats.avg, b.legendStats.avg)
        case "count" =>
          (a, b) => compare(useDescending, a.legendStats.count, b.legendStats.count)
        case "total" =>
          (a, b) => compare(useDescending, a.legendStats.total, b.legendStats.total)
        case "last" =>
          (a, b) => compare(useDescending, a.legendStats.last, b.legendStats.last)
        case order =>
          warnings += s"Invalid sort mode '$order'. Using default of 'legend'."
          (a, b) => compare(useDescending, a.data.label, b.data.label)
      }
      lines.sortWith(cmp)
    }
  }