feat(charts): More charts ui/ux tweaks#4520
Merged
Merged
Conversation
…values Adds a 10% padding to the top and bottom of the Y-axis on the device, power, signal, and pax counter charts to prevent the graph line from touching the edges. Additionally, filters out invalid `Int.MIN_VALUE` readings for `soil_moisture` and `iaq` from environment metrics to prevent crashes. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit introduces a time frame filter to all the node metrics screens (Device, Environment, Power, Signal, and Pax). A `TimeFrame` enum has been created to define the available filter options: 1 hour, 24 hours, and 7 days. A `SlidingSelector` component is used in the UI to allow users to switch between these time frames. The view model now holds the selected time frame state, and the data displayed in both the charts and lists on each metrics screen is filtered accordingly. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Replaces the custom `SlidingSelector` with a new `TimeFrameSelector` composable based on Material 3's `SingleChoiceSegmentedButtonRow`. This refactor is applied across all metrics screens (Device, Environment, Pax, Power, and Signal). Additionally, an "All" time frame option has been added to display all historical metrics data. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit refactors the time frame selector in the metrics screens to only display time frames that are relevant to the available data. Key changes include: - A new `oldestTimestampSeconds` function in `MetricsState` to find the earliest data point across all metric types. - The `TimeFrame` enum now includes `TWO_WEEKS` and `ONE_MONTH` options and has a new `isAvailable` method to check if a time frame is relevant based on the oldest data. - `MetricsViewModel` now exposes an `availableTimeFrames` state flow, which filters the time frames based on the available data history. - The `TimeFrameSelector` composable is updated to accept and display only the `availableTimeFrames`. If only one option is available, the selector is hidden. - All metric screens (`Device`, `Environment`, `Power`, `Signal`, `Pax`) are updated to use the new `availableTimeFrames` state. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
- Refactors the x-axis date/time formatting for charts to use a newline for date and time when the visible span is between 2 and 14 days. This improves label readability in the graphs. - Updates the logic for determining available time frames (`availableTimeFrames`) to consider both node and environmental metrics, ensuring the full range of data is accounted for. - Modifies the `hasValidSignal` check to use a logical OR (`||`) for `rx_snr` and `rx_rssi`, allowing packets with at least one of these values to be considered valid. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Removes the unused `Y_AXIS_WEIGHT` constant from several metrics chart files. Also, adds `@Suppress` annotations for `MagicNumber` and `CyclomaticComplexMethod` to clean up warnings and improve code formatting in various places. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit refactors the Power, Environment, and PAX metrics screens to use a new `BaseMetricScreen` composable. This change abstracts away common boilerplate code for the screen layout, state management, and user interactions, resulting in cleaner and more maintainable UI components. Key changes: - Introduced `BaseMetricScreen` to handle the generic layout including the app bar, time frame selector, and adaptive chart/list view. - Migrated shared UI logic for chart point selection, list scrolling, and data fetching requests into the base implementation. - Refactored `PowerMetricsScreen`, `EnvironmentMetricsScreen`, and `PaxMetricsScreen` to use `BaseMetricScreen`, significantly reducing their code size. - Centralized PAX log decoding logic into `MetricsViewModel`. - Optimized telemetry data filtering and processing by moving it into `MetricsViewModel` and exposing it through `StateFlows`. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit introduces several changes to improve code quality and remove obsolete functionality. - In `PowerMetrics.kt`, the `copy` function call now uses a named argument (`alpha = 1f`) for better readability. - The `MetricsViewModel` has been refactored to remove unused functions (`tracerouteMapAvailability`, `requestUserInfo`), properties (`environmentState`), and imports. - Null-safe calls (`?: 0`) have been removed where the type is non-nullable, simplifying the code. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
The `BaseMetricScreen` composable has been refactored to remove its direct dependency on `MetricsViewModel`. State and event handlers are now passed in as parameters, making the component more reusable and easier to test. This change involved: - Removing the `viewModel` parameter from `BaseMetricScreen`. - Passing `nodeName`, `snackbarHostState`, and an `onRequestTelemetry` lambda as new parameters. - Moving the `LaunchedEffect` for handling snackbar feedback from `BaseMetricScreen` into each of the individual metric screen composables (`DeviceMetrics`, `SignalMetrics`, `PowerMetrics`, etc.). - Updating the call sites in each metric screen to provide the required state and callbacks to the refactored `BaseMetricScreen`. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Adds unit tests for the `BaseMetricScreen` composable to verify its behavior. - Tests that the title, node name, and placeholder content are displayed correctly. - Adds a test to confirm that the refresh button's callback is triggered on click. - A `testTag` has been added to the refresh button to facilitate testing. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
…cs/MetricsViewModel.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4520 +/- ##
==========================================
+ Coverage 11.23% 14.44% +3.20%
==========================================
Files 424 424
Lines 14432 14521 +89
Branches 2397 2410 +13
==========================================
+ Hits 1621 2097 +476
+ Misses 12515 12121 -394
- Partials 296 303 +7 ☔ View full report in Codecov by Sentry. |
Pass LazyListState to the metrics list composables. This enables scrolling the list to the corresponding item when a point is selected on the chart. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
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 pull request introduces a significant refactor and feature enhancement to the metrics screens, particularly focusing on time frame selection and filtering, code simplification, and improved data handling for environment metrics. The changes standardize the way metrics are filtered by time, add user controls for selecting time frames, and clean up the codebase by removing unnecessary logic and improving data validity checks.
Key improvements include:
Time Frame Selection & Filtering
strings.xmlto support user-friendly time frame selection in the UI. [1] [2]TimeFrameSelectorcomposable and integrated it into bothDeviceMetricsScreenandEnvironmentMetricsScreen, allowing users to filter metrics by selectable time frames. [1] [2]DeviceMetricsScreenandEnvironmentMetricsScreento only display metrics within the selected time frame, using the newtimeFrameandavailableTimeFramesstate. [1] [2]Codebase Simplification & Cleanup
EnvironmentMetricsScreento use the sharedBaseMetricScreenand removed a significant amount of redundant or boilerplate Compose code, streamlining the UI logic.EnvironmentMetrics.ktfor better maintainability.Data Handling & Validity
Int.MIN_VALUE(previously only filtered zero), ensuring charts and stats do not display nonsensical data. [1] [2] [3]Telemetrymodel to ensure only valid data is considered for display and analysis.Chart Formatting Enhancements
Minor Fixes
VoltageCurrentDisplayfor clarity.These changes collectively enhance the user experience by making metric data more navigable and relevant, while also improving code maintainability and correctness.
addresses #4496 , addresses #4439