优化采样溢出处理,调整时间轴计算逻辑,确保在采样溢出时使用固定时间;更新显示信息以提示用户采样溢出情况

This commit is contained in:
2025-11-18 21:00:07 +08:00
parent 2acda5959a
commit 491c42b321
2 changed files with 23 additions and 3 deletions
+21 -3
View File
@@ -117,8 +117,10 @@ export default function Page({ params }: { params: Promise<{ id: string }> }) {
const timeAxis = useMemo(() => {
if (!rec) return [] as number[]
// 使用秒为单位,保留3位小数
const step = rec.sampleCount > 0 ? rec.duration / rec.sampleCount : 0
// 使用秒为单位,保留3位小数;若采样溢出,固定为 16.384s
const overflow = rec.sampleCount >= 16384
const effectiveDuration = overflow ? 16.384 : rec.duration
const step = rec.sampleCount > 0 ? effectiveDuration / rec.sampleCount : 0
return Array.from({ length: rec.sampleCount }, (_, i) => +(i * step).toFixed(3))
}, [rec])
@@ -198,7 +200,23 @@ export default function Page({ params }: { params: Promise<{ id: string }> }) {
</div>
<div className="rounded-lg border p-3 sm:p-4 dark:border-zinc-800">
<div className="text-sm text-zinc-500">采样</div>
<div className="mt-1 text-lg">{rec.sampleCount} 点 · {rec.duration.toFixed(3)} s · {(rec.sampleCount / rec.duration).toFixed(2)} Hz</div>
{(() => {
const overflow = rec.sampleCount >= 16384
const effectiveDuration = overflow ? 16.384 : rec.duration
const hz = effectiveDuration > 0 ? (rec.sampleCount / effectiveDuration) : 0
return (
<div className="mt-1 text-lg">
{rec.sampleCount} 点 ·{' '}
<span
className={overflow ? 'text-red-600 dark:text-red-400' : ''}
title={overflow ? '采样溢出,时间将不准确' : undefined}
>
{effectiveDuration.toFixed(3)} s
</span>
{' '}· {hz.toFixed(2)} Hz
</div>
)
})()}
</div>
<div className="rounded-lg border p-3 sm:p-4 dark:border-zinc-800">
<div className="text-sm text-zinc-500">拟合</div>