當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fast.fastReduce函數代碼示例

本文整理匯總了TypeScript中src/utils/fast.fastReduce函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fastReduce函數的具體用法?TypeScript fastReduce怎麽用?TypeScript fastReduce使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了fastReduce函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: calculateTimeColumnWidth

export const calculateColumnWidths = (
  data: string[][],
  fieldOptions: FieldOption[],
  timeFormat: string,
  verticalTimeAxis: boolean,
  decimalPlaces: DecimalPlaces
): ColumnWidths => {
  const timeFormatWidth = calculateTimeColumnWidth(
    timeFormat === '' ? DEFAULT_TIME_FORMAT : timeFormat
  )

  return fastReduce<string[], ColumnWidths>(
    data,
    (acc: ColumnWidths, row: string[], r: number) => {
      return updateMaxWidths(
        row,
        acc,
        data[0],
        r === 0,
        fieldOptions,
        timeFormatWidth,
        verticalTimeAxis,
        decimalPlaces
      )
    },
    {widths: {}, totalWidths: 0}
  )
}
開發者ID:viccom,項目名稱:influxdb,代碼行數:28,代碼來源:tableGraph.ts

示例2: if

const updateMaxWidths = (
  row: string[],
  maxColumnWidths: ColumnWidths,
  topRow: string[],
  isTopRow: boolean,
  fieldOptions: FieldOption[],
  timeFormatWidth: number,
  verticalTimeAxis: boolean,
  decimalPlaces: DecimalPlaces
): ColumnWidths => {
  const maxWidths = fastReduce<string>(
    row,
    (acc: ColumnWidths, col: string, c: number) => {
      const isLabel =
        (verticalTimeAxis && isTopRow) || (!verticalTimeAxis && c === 0)

      const foundField =
        isLabel && _.isString(col)
          ? fieldOptions.find(field => field.internalName === col)
          : null

      let colValue = `${col}`
      if (foundField && foundField.displayName) {
        colValue = foundField.displayName
      } else if (_.isNumber(col) && decimalPlaces.isEnforced) {
        colValue = col.toFixed(decimalPlaces.digits)
      }

      const columnLabel = topRow[c]
      const isTimeColumn = columnLabel === DEFAULT_TIME_FIELD.internalName

      const isTimeRow = topRow[0] === DEFAULT_TIME_FIELD.internalName

      const useTimeWidth =
        (isTimeColumn && verticalTimeAxis && !isTopRow) ||
        (!verticalTimeAxis && isTopRow && isTimeRow && c !== 0)

      const currentWidth = useTimeWidth
        ? timeFormatWidth
        : calculateSize(colValue.toString().trim()) + CELL_HORIZONTAL_PADDING

      const {widths: Widths} = maxColumnWidths
      const maxWidth = _.get(Widths, `${columnLabel}`, 0)

      if (isTopRow || currentWidth > maxWidth) {
        acc.widths[columnLabel] = currentWidth
        acc.totalWidths += currentWidth - maxWidth
      }

      return acc
    },
    {...maxColumnWidths}
  )

  return maxWidths
}
開發者ID:viccom,項目名稱:influxdb,代碼行數:56,代碼來源:tableGraph.ts

示例3: getUnixISODiff

export const findHoverTimeIndex = (
  sortedTimeVals: string[],
  hoverTime: number
) => {
  if (sortedTimeVals.length < 2) {
    // first value is "_time" header
    return -1
  }

  const firstDiff = getUnixISODiff(hoverTime, sortedTimeVals[1]) // sortedTimeVals[0] is "_time"
  const hoverTimeFound = fastReduce<string, {index: number; diff: number}>(
    sortedTimeVals,
    (acc, currentTime, index) => {
      const thisDiff = getUnixISODiff(hoverTime, currentTime)
      if (thisDiff < acc.diff) {
        return {index, diff: thisDiff}
      }
      return acc
    },
    {index: 1, diff: firstDiff}
  )

  return hoverTimeFound.index
}
開發者ID:viccom,項目名稱:influxdb,代碼行數:24,代碼來源:tableGraph.ts


注:本文中的src/utils/fast.fastReduce函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。