本文整理汇总了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}
)
}
示例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
}
示例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
}