From 887421b9cfb67640b6f02784f56c89fa3cd08bea Mon Sep 17 00:00:00 2001 From: Alex Fedotyev <61838744+alex-fedotyev@users.noreply.github.com> Date: Tue, 22 Sep 2026 15:05:49 +0000 Subject: [PATCH] refactor(app): name the duration-heatmap number format The significant-fields heatmap built { output: 'duration', factor: 0.001 } inline. The factor is only correct next to getDurationMsExpression, which applies the source's durationPrecision and leaves the value in ms, so give it a name in source.ts and document that pairing. No behavior change. --- .../src/components/Search/DBSearchHeatmapChart.tsx | 11 +++++------ packages/app/src/source.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/app/src/components/Search/DBSearchHeatmapChart.tsx b/packages/app/src/components/Search/DBSearchHeatmapChart.tsx index 435212c18f..025f82b0c2 100644 --- a/packages/app/src/components/Search/DBSearchHeatmapChart.tsx +++ b/packages/app/src/components/Search/DBSearchHeatmapChart.tsx @@ -26,8 +26,10 @@ import DBHeatmapChart, { toHeatmapChartConfig, } from '@/components/DBHeatmapChart'; import HeatmapSettingsDrawer from '@/components/HeatmapSettingsDrawer'; -import { getDurationMsExpression } from '@/source'; -import type { NumberFormat } from '@/types'; +import { + DURATION_HEATMAP_NUMBER_FORMAT, + getDurationMsExpression, +} from '@/source'; export function DBSearchHeatmapChart({ chartConfig, @@ -151,10 +153,7 @@ export function DBSearchHeatmapChart({ ], numberFormat: fields.value === getDurationMsExpression(source) - ? ({ - output: 'duration', - factor: 0.001, - } satisfies NumberFormat) + ? DURATION_HEATMAP_NUMBER_FORMAT : undefined, }).heatmapConfig } diff --git a/packages/app/src/source.ts b/packages/app/src/source.ts index e16093f067..318693bb4b 100644 --- a/packages/app/src/source.ts +++ b/packages/app/src/source.ts @@ -484,6 +484,18 @@ export function getDurationMsExpression(source: TTraceSource) { return `(${source.durationExpression})/1e${(source.durationPrecision ?? 9) - 3}`; } +/** + * Number format for a duration heatmap whose value expression is already in + * milliseconds, which is what `getDurationMsExpression` returns: it applies + * the source's `durationPrecision`, so the only conversion left for display + * is milliseconds to seconds. Pair the two; this factor is wrong against a + * raw duration column. + */ +export const DURATION_HEATMAP_NUMBER_FORMAT = { + output: 'duration', + factor: 0.001, +} satisfies NumberFormat; + export function getDurationSecondsExpression(source: TTraceSource) { return `(${source.durationExpression})/1e${source.durationPrecision ?? 9}`; }