refactor(chart): enforce 400-line source limit
Some checks failed
Package component / package (push) Failing after 4m19s
Some checks failed
Package component / package (push) Failing after 4m19s
This commit is contained in:
@@ -1,23 +1,14 @@
|
||||
import { bisector } from 'd3'
|
||||
|
||||
import type { WaveformPoint, WaveformRenderingOptions } from '@/types'
|
||||
import type { WaveformPoint } from '@/types'
|
||||
import { resolveWaveformPointErrors } from './data'
|
||||
import type { ResolvedWaveformRenderingOptions } from './renderingOptions'
|
||||
|
||||
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 {
|
||||
DEFAULT_WAVEFORM_RENDERING_OPTIONS,
|
||||
resolveWaveformRenderingOptions,
|
||||
type ResolvedWaveformRenderingOptions,
|
||||
} from './renderingOptions'
|
||||
|
||||
const pointBisector = bisector((point: WaveformPoint) => point.x)
|
||||
const acceptAllPoints = () => true
|
||||
@@ -74,34 +65,6 @@ export function hasMinimumVisibleXValues(
|
||||
return false
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
function pushUniquePoint(target: WaveformPoint[], point: WaveformPoint | undefined) {
|
||||
if (point && target[target.length - 1] !== point) target.push(point)
|
||||
}
|
||||
|
||||
45
src/core/renderingOptions.ts
Normal file
45
src/core/renderingOptions.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user