Files
waveform-analysis/src/core/renderingOptions.ts
liqiyuan 082462cf67
Some checks failed
Package component / package (push) Failing after 4m19s
refactor(chart): enforce 400-line source limit
2026-07-27 15:05:13 +08:00

46 lines
1.6 KiB
TypeScript

import type { WaveformRenderingOptions } from '@/types'
export interface ResolvedWaveformRenderingOptions {
downsample: boolean
downsampleThreshold: number
maxPointsPerPixel: number
pointMinSpacing: number
errorBarMinSpacing: number
}
export const DEFAULT_WAVEFORM_RENDERING_OPTIONS: ResolvedWaveformRenderingOptions = {
downsample: true,
downsampleThreshold: 2_000,
maxPointsPerPixel: 4,
pointMinSpacing: 10,
errorBarMinSpacing: 12,
}
export function resolveWaveformRenderingOptions(
options?: WaveformRenderingOptions,
): ResolvedWaveformRenderingOptions {
const threshold = Number(options?.downsampleThreshold)
const pointsPerPixel = Number(options?.maxPointsPerPixel)
const pointMinSpacing = Number(options?.pointMinSpacing)
const errorBarMinSpacing = Number(options?.errorBarMinSpacing)
return {
downsample: options?.downsample ?? DEFAULT_WAVEFORM_RENDERING_OPTIONS.downsample,
downsampleThreshold:
Number.isFinite(threshold) && threshold >= 2
? Math.floor(threshold)
: DEFAULT_WAVEFORM_RENDERING_OPTIONS.downsampleThreshold,
maxPointsPerPixel:
Number.isFinite(pointsPerPixel) && pointsPerPixel > 0
? pointsPerPixel
: DEFAULT_WAVEFORM_RENDERING_OPTIONS.maxPointsPerPixel,
pointMinSpacing:
Number.isFinite(pointMinSpacing) && pointMinSpacing >= 0
? pointMinSpacing
: DEFAULT_WAVEFORM_RENDERING_OPTIONS.pointMinSpacing,
errorBarMinSpacing:
Number.isFinite(errorBarMinSpacing) && errorBarMinSpacing >= 0
? errorBarMinSpacing
: DEFAULT_WAVEFORM_RENDERING_OPTIONS.errorBarMinSpacing,
}
}