Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metric): chart not rendered when the trend is empty #2447

Merged
merged 8 commits into from
Jun 3, 2024

Conversation

alexwizp
Copy link
Contributor

Closes: #2445

Summary

This change ensures that the chart component can handle empty trend data appropriately, preventing rendering failures and console errors.

Screen

Screen:

Trend was set to []

image

No console issues

@alexwizp alexwizp changed the title fix (Metric): chart not rendered when the trend is empty fix(Metric): chart not rendered when the trend is empty May 30, 2024
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

This doesn't solve the issue completely.

The root cause is a couple of lines below that changed line where:

  const [xMin, xMax] = [sortedTrendData.at(0)!.x, sortedTrendData.at(-1)!.x];

We need to avoid these type of assertions because they can cause all sort of issues around them (cc @dej611)

Even if with a single element the chart renders, the SVG is malformed (will contain NaN numbers that throws in the console).

The correct fix should check if the trend contains at least 2 elements. If not you should assure a correct background/foreground color selection (changing it to if(trend.length < 2) return null doesn't solves it quickly unfortunately)

@nickofthyme nickofthyme requested a review from markov00 May 31, 2024 03:52
@nickofthyme
Copy link
Collaborator

buildkite update screenshots

@alexwizp alexwizp requested review from markov00 and nickofthyme May 31, 2024 10:10
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

New changes LGTM, let's see what @markov00 thinks.

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for taking care of it

@markov00 markov00 changed the title fix(Metric): chart not rendered when the trend is empty fix(metric): chart not rendered when the trend is empty Jun 3, 2024
@markov00 markov00 merged commit 6042cc8 into elastic:main Jun 3, 2024
14 checks passed
nickofthyme pushed a commit that referenced this pull request Jun 4, 2024
# [65.2.0](v65.1.0...v65.2.0) (2024-06-04)

### Bug Fixes

* **deps:** update dependency @elastic/eui to ^94.5.2 ([#2450](#2450)) ([26b425c](26b425c))
* **deps:** update dependency @elastic/eui to ^94.6.0 ([#2454](#2454)) ([6759469](6759469))
* **deps:** update dependency @playwright/test to ^1.44.1 ([#2451](#2451)) ([158b4c2](158b4c2))
* **deps:** update dependency json-schema-to-typescript to v14.0.5 ([#2452](#2452)) ([7947e17](7947e17))
* **metric:** chart not rendered when the trend is empty ([#2447](#2447)) ([6042cc8](6042cc8))
* **sunburst:** rendering for full sections ([#2457](#2457)) ([58c2721](58c2721))

### Features

* **legend:** improve tooltip wording ([#2439](#2439)) ([27c04f4](27c04f4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Metric] SparkLine - chart not rendered when the trend is empty
3 participants