Skip to content

ref(dashboards): Simplify shared heat map bucket helpers#117957

Merged
gggritso merged 8 commits into
masterfrom
georgegritsouk/simplify-heat-map-bucket-helpers
Jun 19, 2026
Merged

ref(dashboards): Simplify shared heat map bucket helpers#117957
gggritso merged 8 commits into
masterfrom
georgegritsouk/simplify-heat-map-bucket-helpers

Conversation

@gggritso

@gggritso gggritso commented Jun 17, 2026

Copy link
Copy Markdown
Member

Re-splits the helpers used in Explore for Heat Map calculations, in preparation for Dashboards usage. The biggest change is that I combined the utility that calculates the X and Y buckets into one, since they're always used together. I feel this is less confusing, and it prevents having to re-calculate some intermediate values. I also messed around a bit with the logic of some of the functions, namely:

  • interval selection for a duration is a bit more robust, and it always return an interval, even if the input if out of range. It only fails if not enough intervals are provided
  • the Y-axis bucket calculation is not precise to the pixel, and tries very hard to make perfectly square heat map cells

Refs DAIN-1654

Reshape the shared heat map bucket helpers from the original Explore-shaped
signatures to a simpler form: the X-axis interval is derived from the page
filter + container width, and the Y-axis bucket count from the container
height via PIXELS_PER_BUCKET (renamed from PIXELS_PER_X_BUCKET). Explore's
metric panel is updated to the new signatures.

This changes Explore's heat map bucket sizing (the X axis no longer snaps
against useChartInterval's option list, and the Y axis is height-based rather
than width/aspect-ratio based). Split out of the heat map dashboard widget
work, which needs these simpler signatures.

Refs DAIN-1654
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gggritso gggritso requested review from a team as code owners June 17, 2026 21:59
@linear-code

linear-code Bot commented Jun 17, 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 17, 2026
Comment thread static/app/views/explore/metrics/metricPanel/index.tsx
With the simplified Y bucket count derived from a constant height, yBuckets is
always positive, so the heat map query no longer waited for layout — it fired at
width 0 with a coarse fallback interval, then refetched once measured. Gate the
query on a measured container width.

Refs DAIN-1654
@gggritso gggritso requested a review from a team as a code owner June 18, 2026 22:39
Comment thread static/app/views/explore/metrics/metricPanel/index.tsx Outdated
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

📊 Type Coverage Diff

Metric Before After Delta
Coverage 93.70% 93.70% ±0%
Typed 133,113 133,112 🔴 -1
Untyped 8,952 8,956 🔴 +4
🔍 4 new type safety issues introduced

Non-null assertions (!) (4 new)

File Line Detail
static/app/utils/duration/closestIntervalToDuration.tsx 22 sortedIntervals.at(0)!
static/app/utils/duration/closestIntervalToDuration.tsx 29 sortedIntervals.at(-1)!
static/app/utils/duration/closestIntervalToDuration.tsx 34 sortedIntervals.at(-1)!
static/app/utils/duration/closestIntervalToDuration.tsx 86 intervalRangeMap.get(duration)!

This is informational only and does not block the PR.

@gggritso

Copy link
Copy Markdown
Member Author

@cursor review

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 225b034. Configure here.

@nsdeschenes nsdeschenes 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.

Looks all good, just some small non-implementation related questions 😄

Comment on lines +6 to +7
* assertions. Unfortunately heavily limited to only work with `[0]` and not
* `.at(0)` or any other index.

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.

😭

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.

Would it be worth looking into introducing this package, and utilizing this function: https://remedajs.com/docs/#hasAtLeast ?

I know @TkDodo is a maintainer of it :o

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤷🏻‍♂️ I don't have a strong opinion! It seems like overkill for this case, but maybe it's worth it?

'/organizations/$organizationIdOrSlug/events-heatmap/',
{
path: enabled ? {organizationIdOrSlug: organization.slug} : skipToken,
path: !enabled || !valid ? skipToken : {organizationIdOrSlug: organization.slug},

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.

Is this how we "skipToken" apiOptions? :o

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, skipToken goes in the path position with our stuff

@gggritso gggritso merged commit 34530ed into master Jun 19, 2026
71 checks passed
@gggritso gggritso deleted the georgegritsouk/simplify-heat-map-bucket-helpers branch June 19, 2026 16:52
gggritso added a commit that referenced this pull request Jun 19, 2026
…-dashboards-widget

Reconcile with the merged (and reworked) heat map bucket helpers PR (#117957):
the two getHeatmapXAxisBucketInterval/getHeatmapYAxisBucketCount helpers were
consolidated on master into calculateHeatMapBucketDimensions(selection,
{width, height}, availableIntervals) -> {interval, yBuckets} | null. Point the
dashboards HeatmapMeasuredArea at the new helper (supplying availableIntervals
via getIntervalOptionsForPageFilter), and take master's Explore metricPanel.
Keep the dashboards-only HEATMAP_RESIZE_DEBOUNCE_MS setting.
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.

2 participants