Add stacked chart primitives for account analytics (#45763)

## What changed

Add daily stacked bar rendering in the TUI analytics module, staged for dashboard integration.

- Plot three categories plus an Other remainder without renormalizing values, with separate positive and negative bands for signed credits.
- Add readable numeric axes, calendar ticks, a selection cursor, and a callout showing the authoritative daily total. Distinguish missing days from zero usage.
- Keep the selection visible in narrow viewports and omit labels that cannot fit without truncation.
- Use terminal palette colors for series and adapt secondary text to terminal color support and background.

## Testing

Add unit and snapshot coverage for axis scaling, signed bars on light and dark terminals, missing and zero values, narrow layouts, tiny segments, authoritative totals, and duplicate-date remainders.

GitOrigin-RevId: 2ed58def17abd14e77929016a54fd20e91d45670
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-09-15 19:01:18 +00:00
1 parent 1fc46a532b
commit af3bc6f796
18 files changed
+1671 -2

No files matched your search

+18 -1
View File
@@ -1,4 +1,4 @@
//! Shared report category aggregation for token model filtering.
//! Shared report category aggregation and stacked-chart partitioning.
use super::models::AccountAnalyticsHistory;
use super::models::AccountAnalyticsValue;
@@ -24,3 +24,20 @@ pub(super) fn categories(history: &AccountAnalyticsHistory) -> Vec<AccountAnalyt
});
values
}
/// The last plotted category collects all remaining values without renormalizing them.
pub(super) fn parts(
values: &[AccountAnalyticsValue],
categories: &[AccountAnalyticsValue],
) -> [f64; 4] {
let mut parts = [0.0; 4];
for value in values {
let index = categories
.iter()
.take(/*n*/ 3)
.position(|category| category.key == value.key)
.unwrap_or(/*default*/ 3);
parts[index] += value.value;
}
parts
}