当前位置: 首页>>代码示例>>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;未经允许,请勿转载。