-
Notifications
You must be signed in to change notification settings - Fork 122
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
Conversation
There was a problem hiding this 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)
packages/charts/src/chart_types/metric/renderer/dom/sparkline.tsx
Outdated
Show resolved
Hide resolved
buildkite update screenshots |
There was a problem hiding this 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.
There was a problem hiding this 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
# [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))
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 []
No
console
issues