ref(dashboards): Extract shared heat map chart utilities#117873
ref(dashboards): Extract shared heat map chart utilities#117873gggritso wants to merge 5 commits into
Conversation
Move Explore's heat map helpers into a shared heatMapWidget location so the upcoming dashboards heat map widget can reuse them: the X/Y bucket-sizing helpers (getHeatmapXAxisBucketInterval, getHeatmapYAxisBucketCount), the metric-unit patch (mergeMetricUnit), and heat map settings (PIXELS_PER_BUCKET, HEATMAP_Z_AXIS_SCALE). The Explore metric panel and heat map now import them. Behavior-preserving refactor split from the larger heat map dashboard widget work. Refs DAIN-1654 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5b180cc. Configure here.
📊 Type Coverage Diff
🔍 1 new type safety issue introducedType assertions (
This is informational only and does not block the PR. |
Move Explore's existing heat map helpers verbatim instead of rewriting them. The previous version of this branch simplified the helpers while relocating them, which silently changed Explore's behavior (it dropped the 1d interval option for long ranges and replaced the width-gated Y-bucket math). Restore the original getHeatmapXBucketInterval / getHeatmapYBuckets bodies and signatures (and PIXELS_PER_X_BUCKET = 15) under the renamed shared files so this is a true no-op refactor for Explore. Refs DAIN-1654
…at-map-utils' into georgegritsouk/extract-shared-heat-map-utils ; Conflicts: ; static/app/views/dashboards/widgets/heatMapWidget/settings.ts
| import {getDiffInMinutes} from 'sentry/components/charts/utils'; | ||
| import type {PageFilters} from 'sentry/types/core'; | ||
| import {intervalToMilliseconds} from 'sentry/utils/duration/intervalToMilliseconds'; | ||
| import {STACKED_GRAPH_HEIGHT} from 'sentry/views/explore/metrics/settings'; |
There was a problem hiding this comment.
Bug: The getHeatmapYAxisBucketCount function uses a hardcoded height (STACKED_GRAPH_HEIGHT) which will be incorrect for variably-sized dashboard widgets, leading to distorted heatmaps.
Severity: MEDIUM
Suggested Fix
Modify the getHeatmapYAxisBucketCount function to accept chartContainerHeight as a parameter. Use this new parameter in the aspect ratio calculation instead of the hardcoded STACKED_GRAPH_HEIGHT to ensure the calculation is correct for containers of any height.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
static/app/views/dashboards/widgets/heatMapWidget/utils/getHeatmapYAxisBucketCount.tsx#L4
Potential issue: The function `getHeatmapYAxisBucketCount` is being extracted for reuse
in dashboard widgets, but it hardcodes a dependency on `STACKED_GRAPH_HEIGHT`, a fixed
height value of 362px from the Explore view. Dashboard widgets have variable heights,
and the function does not accept height as a parameter. When this utility is used by a
dashboard widget with a height other than 362px, it will use the wrong height for its
aspect ratio calculation. This will result in an incorrect Y-axis bucket count, causing
the heatmap cells to be distorted rather than roughly square as intended.
Also affects:
static/app/views/dashboards/widgets/heatMapWidget/utils/getHeatmapYAxisBucketCount.tsx:27~27
Did we get this right? 👍 / 👎 to inform future reviews.

In an attempt to make a future PR less insane, this PR takes some of the current Heat Map behaviour and splits out the helpers into their own files and so on.
Refs DAIN-1654