Skip to content

ref(dashboards): Extract shared heat map chart utilities#117873

Open
gggritso wants to merge 5 commits into
masterfrom
georgegritsouk/extract-shared-heat-map-utils
Open

ref(dashboards): Extract shared heat map chart utilities#117873
gggritso wants to merge 5 commits into
masterfrom
georgegritsouk/extract-shared-heat-map-utils

Conversation

@gggritso

@gggritso gggritso commented Jun 16, 2026

Copy link
Copy Markdown
Member

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

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>
@gggritso gggritso requested review from a team as code owners June 16, 2026 22:05
@linear-code

linear-code Bot commented Jun 16, 2026

Copy link
Copy Markdown

DAIN-1654

@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jun 16, 2026

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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.

Comment thread static/app/views/explore/metrics/metricPanel/index.tsx Outdated
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

📊 Type Coverage Diff

Metric Before After Delta
Coverage 93.70% 93.70% ±0%
Typed 132,914 132,915 🟢 +1
Untyped 8,943 8,943 ±0
🔍 1 new type safety issue introduced

Type assertions (as) (1 new)

File Line Detail
static/app/views/dashboards/widgets/heatMapWidget/utils/mergeMetricUnit.tsx 29 as DataUnitunit as DataUnit

This is informational only and does not block the PR.

gggritso added 2 commits June 16, 2026 18:44
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';

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant