refactor(metrics): Prevent chart crashes with empty data#4578
Merged
Conversation
This commit introduces checks to prevent crashes in the metrics charts when there is no data to display. The charts will now only render if there is valid data available for at least one series.
This is achieved by pre-filtering the telemetry data and only creating chart layers and axes if the corresponding data is not empty. This improves the robustness of the metrics feature by gracefully handling cases where certain telemetry data might be missing.
Specific changes:
- In `PowerMetrics`, `DeviceMetrics`, `EnvironmentCharts`, and `SignalMetrics`, data for each series is filtered and stored in `remember` blocks.
- Chart layers (`LineCartesianLayer`) and axes (`VerticalAxis`) are conditionally created only if their corresponding data is not empty.
- The `GenericMetricChart` composable is only called if there is at least one layer to render.
- Added `@Suppress("CyclomaticComplexMethod")` to `DeviceMetricsChart` and `SignalMetricsChart` due to increased conditional complexity.
- In `PaxMetrics`, chart data series are now memoized using `remember`.
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4578 +/- ##
==========================================
- Coverage 14.79% 14.79% -0.01%
==========================================
Files 428 429 +1
Lines 14845 14846 +1
Branches 2456 2457 +1
==========================================
Hits 2197 2197
- Misses 12330 12331 +1
Partials 318 318 ☔ View full report in Codecov by Sentry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit introduces checks to prevent crashes in the metrics charts when there is no data to display. The charts will now only render if there is valid data available for at least one series.
This is achieved by pre-filtering the telemetry data and only creating chart layers and axes if the corresponding data is not empty. This improves the robustness of the metrics feature by gracefully handling cases where certain telemetry data might be missing.
Specific changes:
PowerMetrics,DeviceMetrics,EnvironmentCharts, andSignalMetrics, data for each series is filtered and stored inrememberblocks.LineCartesianLayer) and axes (VerticalAxis) are conditionally created only if their corresponding data is not empty.GenericMetricChartcomposable is only called if there is at least one layer to render.@Suppress("CyclomaticComplexMethod")toDeviceMetricsChartandSignalMetricsChartdue to increased conditional complexity.PaxMetrics, chart data series are now memoized usingremember.