Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/app/src/components/Search/DBSearchHeatmapChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions packages/app/src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — The dashboard heatmap editor still builds its own copy of the { output: 'duration', factor: 0.001 } literal

In applyHeatmapDefaults (packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx:164), replace the inline { output: 'duration', factor: 0.001 } with DURATION_HEATMAP_NUMBER_FORMAT. That function is the other duration heatmap, and it gets its value from getDurationMsExpression (lines 696 and 735), so after this PR the pairing lives in two places. While there: the Heatmap display-type switch at line 701 also passes fallbackValue, an arbitrary non-ms expression, into applyHeatmapDefaults. That path still gets the 0.001 factor, which the new doc comment says is wrong. Apply the format only when the value came from getDurationMsExpression, as DBSearchHeatmapChart does.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving both here. EditTimeChartForm.tsx is outside this PR's files and routing it through the constant is the kind of extra call site this change should not reach for; the fallbackValue path applying the ms factor to a non-ms expression is a real bug but it predates this PR, which only moves an existing literal. Worth its own change.

output: 'duration',
factor: 0.001,
} satisfies NumberFormat;

export function getDurationSecondsExpression(source: TTraceSource) {
return `(${source.durationExpression})/1e${source.durationPrecision ?? 9}`;
}
Expand Down
Loading