Skip to content

Conversation

@ben-fornefeld
Copy link
Member

@ben-fornefeld ben-fornefeld commented Oct 24, 2025

Note

Refactors the Usage page to an interactive, brush-selectable ECharts experience with time range presets and sampling, backed by hourly usage data and new utilities.

  • Usage Page (UI/UX):
    • Replace Cost/RAM/vCPU/Sandboxes cards and Recharts with four interactive ECharts (UsageMetricChart) inside UsageChartsProvider.
    • Add brush selection, hover syncing, and animated metric display; per-chart time range controls with presets and copyable ISO intervals.
  • Data & Sampling:
    • Fetch raw hourly usage via getUsage (UsageResponse.hour_usages), convert timestamps to ms; remove monthly aggregation/cache.
    • Add sampling (hourly/daily/weekly), zero-fill time series, totals/hover formatting, and timeframe URL syncing (nuqs).
  • New Components/Utils:
    • compute-usage-chart, usage-charts-context, usage-time-range-controls, time-range-picker, time-range-presets.
    • Utilities: calculateAxisMax, time-series helpers, time range/preset finder, formatting (formatDay/Hour/DateRange).
  • Monitoring Charts:
    • Switch from DataZoom/toolbox to Brush; compute Y max via shared calculateAxisMax; remove STATIC_ECHARTS_CONFIG and old calculateYAxisMax.
    • Update unit tests to use calculateAxisMax.
  • Layout & Misc:
    • Mark /dashboard/*/usage as custom layout with optional header bottom styles; wrapper/header tweaks; small UI polish (AnimatedNumber, TimeInput).
    • Update billing credits to use new getUsage; adjust chart placeholder config.

Written by Cursor Bugbot for commit 8bb233e. This will update automatically on new commits. Configure here.

- Replaced individual usage cards with new chart components in a responsive grid layout
- Added UsageChartsProvider context to manage shared chart state and interactions
- Implemented interactive tooltips and hover states across all usage charts
- Updated layout configuration to use custom header styling for usage page
- Improved mobile responsiveness with better overflow handling and chart sizing
- Consolidated data fetching to single request
- Simplified data model by converting to TimeSeriesPoint interface for all metrics
- Added fillTimeSeriesWithEmptyPoints utility to ensure consistent data points
- Centralized display value calculations and formatting in context
- Removed direct dependency on UsageData type in chart components
- Updated compute usage chart to handle standardized time series format
- Renamed getUsageThroughReactCache to getUsage for clarity

The changes consoli
- Modified default date range to show 3 days before first data point instead of exact first date
- Updated display value labels from "total" to "over range" for better clarity
- Simplified timeframe filtering logic by removing redundant comments
- Reorganized date range calculation to handle edge cases more consistently
- Added consistent timestamp handling with 12-hour window for hover matching
- Removed endEnabled toggle and simplified TimeRangePicker interface by making time inputs optional
- Added hideTime prop to allow date-only selection mode
- Updated time handling to use default values (00:00:00 for start, 23:59:59 for end) when time is not specified
- Renamed getUsageThroughReactCache to getUsage for clarity
- Fixed time input validation to properly handle null/empty time values
- Streamlined TimeRangeValues interface by
@ben-fornefeld ben-fornefeld added improvement Improvements in-code refactor design For changes related to UI/UX labels Oct 24, 2025
@linear
Copy link

linear bot commented Oct 24, 2025

@vercel
Copy link

vercel bot commented Oct 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
web Ready Ready Preview Comment Nov 3, 2025 4:22pm
web-juliett Ready Ready Preview Comment Nov 3, 2025 4:22pm

@ben-fornefeld
Copy link
Member Author

bugbot run

cursor[bot]

This comment was marked as outdated.

- Added brush selection component to ECharts configuration allowing users to select time ranges directly on charts
- Implemented brush event handling to update timeframe when user selects a range
- Added date normalization functions to snap selections to full day boundaries
- Removed static ECharts config and integrated brush-specific options directly into chart options
- Added onBrushEnd callback prop to ComputeUsageChart component
tomassrnka
tomassrnka previously approved these changes Oct 24, 2025
Copy link
Member

@tomassrnka tomassrnka left a comment

Choose a reason for hiding this comment

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

Ok from my end

- Updated grid layout breakpoints from md to lg for better responsive behavior
- Added conditional time range controls visibility per chart to reduce UI clutter
- Enhanced date formatting using Intl.DateTimeFormat for consistent display
- Improved calendar interaction by setting defaultMonth to selected date
- Updated tooltips to clarify time range navigation (one-third range movement)
- Updated grid layout with better proportions using grid-rows-[4fr_2fr] for more balanced chart display
- Standardized chart heights using min-h-[48svh] for consistent mobile display
- Added border and padding to bottom charts in desktop view for visual separation
- Refined time range controls visibility and positioning across breakpoints
- Updated "Started Sandboxes" label to "Started & Resumed Sandboxes" for accuracy
- Improved metric header
- Simplified x-axis configuration by moving min/max values into initial chart options
- Fixed interval calculation to ensure proper tick spacing based on sampling mode
- Removed unnecessary useEffect hook for setting time range
- Added chartSpan variable to improve code readability and reusability
- Ensured minimum interval respects weekly/daily sampling modes while maintaining proper tick display

The changes make the chart more reliable by
- Updated x-axis to show only start and end labels by setting interval to MAX_SAFE_INTEGER
- Added support for decimal values under 1 in formatAxisNumber with 2 decimal precision
- Disabled toolbox component in chart configuration for cleaner UI
- Removed unused index parameter from x-axis formatter function
- Added ToolboxComponent registration to echarts configuration
- Moved chart configuration to shared constants file and added support for hourly sampling mode
- Enhanced timestamp normalization logic to handle hourly, daily, and weekly sampling periods
- Updated chart styling with better opacity, spacing and grid layout
- Added dynamic tick intervals based on sampling mode (hourly/daily/weekly)
- Improved hover display formatting to show appropriate time labels for each sampling mode
- Refactored data point
@ValentaTomas
Copy link
Member

@ben-fornefeld Any blockers for merging this? There were a few commits since the review :D

@ben-fornefeld ben-fornefeld dismissed tomassrnka’s stale review October 30, 2025 02:10

there were ux decisions that needed post-addressing

@ben-fornefeld
Copy link
Member Author

@ben-fornefeld Any blockers for merging this? There were a few commits since the review :D

yes, small fixes about how the chart behaves around the edges and how the sampling work

- Renamed calculateYAxisMax to calculateAxisMax for clarity
- Enhanced formatAxisDate function to support hourly, daily, and weekly sampling modes
- Updated chart data mapping to utilize new date formatting logic
- Removed unused area color variables from chart configurations for cleaner code
- Adjusted HOURLY_SAMPLING_THRESHOLD_DAYS constant from 5 to 3 for better sampling accuracy
- Updated display-utils to improve timestamp formatting for daily and weekly sampling modes
- Refactored sampling-utils to streamline usage data processing and normalize timestamps
- Removed deprecated compute-usage-chart utilities for cleaner codebase
- Improved time range controls by eliminating unnecessary props and enhancing data handling
- Adjusted usage charts context to utilize new data processing logic and ensure accurate display
cursor[bot]

This comment was marked as outdated.

@ben-fornefeld ben-fornefeld merged commit 680269f into main Nov 3, 2025
3 of 5 checks passed
@ben-fornefeld ben-fornefeld deleted the refactor-usage-page-charts-to-be-able-to-show-more-fine-eng-3214 branch November 3, 2025 16:21
ben-fornefeld added a commit that referenced this pull request Nov 3, 2025
…sage data (#171)

<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Replaces the usage page with ECharts-based interactive charts powered
by a new context, hourly aggregation, and time-range controls; unifies
axis max logic and updates API usage/formatting utilities.
>
> - **Usage Page (UI/UX)**:
> - Replace legacy cards/charts with a 2x2 grid of `UsageMetricChart`
(sandboxes, cost, vcpu, ram) backed by `UsageChartsProvider`.
> - Add brush-based selection, hover-driven value display, and
URL-synced timeframe via `nuqs`.
> - Introduce `UsageTimeRangeControls` with date/time picker, presets,
and shift navigation.
> - **Charts**:
> - New `compute-usage-chart` (ECharts bar) and supporting
configs/types.
> - Team metrics chart: switch from dataZoom to brush, remove static
toolbox config, and use shared `calculateAxisMax`.
> - **Data Processing & Formatting**:
> - Add hourly usage processing with sampling (`hourly/daily/weekly`) in
`sampling-utils` and zero-fill in `time-series`.
> - New display/format helpers (`formatAxisDate/Hour/Day`, totals, empty
states) and compact axis number formatting tweaks.
> - Shared `calculateAxisMax` in `lib/utils/chart` with tests updated
accordingly.
> - **Server/API**:
> - `get-usage`: fetch raw `UsageResponse`, convert
`hour_usages.timestamp` to ms, and return directly (replaces prior
cached transform).
>   - Update consumers (e.g., billing credits) to use `getUsage`.
> - **Layout/Infra**:
> - Mark `'/dashboard/*/usage'` as `custom` layout and adjust
header/wrapper overflow behavior.
> - Remove old Recharts-based components and unused toolbox/tooltip
utilities.
> - **New UI Primitives**:
> - Add `TimeRangePicker`, `TimeRangePresets`, and enhance `TimeInput`;
minor `AnimatedNumber` adjustment.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
4b10e72. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Jakub Dobry <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

design For changes related to UI/UX improvement Improvements in-code refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants