app: burn-up window charts, estimated days, full breakdown, one tooltip
agent-review agent review: fail

From developer feedback on the redesign:
- Week use per day draws estimated days hatched beside measured ones.
- Limit history becomes a burn-up chart per window instance: even-pace
  diagonal, used line without point markers, forecast to the reset,
  the previous instance faintly, and a strip of past peaks with their
  real start and end.
- The breakdown has its detail columns back, sorts by any column and
  expands "Other" to every row.
- One tooltip component, a title and a label/value grid, for every
  chart and table.
Also the review notes of #7: dated forecasts, the real span of the
recent rate, keyboard focus, distinct settings names, a wheel that no
longer changes selections, and version 1.1.0.

Refs #5, #7
This commit is contained in:
Florian Schmidt
2026-10-15 09:38:11 +02:00
parent e687a40346
commit ab8d245df8
14 changed files with 592 additions and 101 deletions
+30 -54
View File
@@ -20,6 +20,7 @@ public sealed class PanelWindow : Window
private bool wide;
private int limitColumns;
private readonly Dictionary<Provider, string> selectedDailyWindow = [];
private readonly BreakdownState modelBreakdown = new(), projectBreakdown = new();
public PanelWindow(PanelViewModel model, Action refresh, Action settings, Action quit, Action reload)
{
@@ -122,12 +123,12 @@ public sealed class PanelWindow : Window
var chart = new Border { Child = DayView(entries[index]) };
var title = Ui.Text(group.Key + " · " + labels[index], 15);
var stack = Ui.Stack(title);
var explanation = Ui.Text("Filled: this window · outline: previous window", 12, "Muted");
void UpdateExplanation(LimitDetail item) => explanation.IsVisible = item.Days!.Previous.Count > 0 && item.Days.Current.Any(d => d.Used is not null);
var explanation = Ui.Text("Measured · Estimated from tokens (hatched) · faint: previous", 12, "Muted");
void UpdateExplanation(LimitDetail item) => explanation.IsVisible = item.Days!.Current.Any(d => d.Used is not null);
UpdateExplanation(entries[index]);
if (entries.Length > 1)
{
var selector = new ComboBox { ItemsSource = labels, SelectedIndex = index };
var selector = new WindowSelector { ItemsSource = labels, SelectedIndex = index };
selector.SelectionChanged += (_, _) =>
{
if (selector.SelectedIndex < 0) return;
@@ -143,7 +144,7 @@ public sealed class PanelWindow : Window
}), wide));
}
var tokenHeader = new DockPanel();
var toggle = new CheckBox { Content = "Include cache reads", IsChecked = model.IncludeCacheReads, HorizontalAlignment = HorizontalAlignment.Right };
var toggle = new NeutralCheckBox { Content = "Include cache reads", IsChecked = model.IncludeCacheReads, HorizontalAlignment = HorizontalAlignment.Right };
toggle.IsCheckedChanged += (_, _) => model.IncludeCacheReads = toggle.IsChecked == true;
DockPanel.SetDock(toggle, Dock.Right); tokenHeader.Children.Add(toggle);
var tokenTitle = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 24, VerticalAlignment = VerticalAlignment.Center };
@@ -164,14 +165,17 @@ public sealed class PanelWindow : Window
Legend(seriesNames), new UsageChart { Values = values.Select(v => v with { Value = Math.Max(0, v.Value - (model.IncludeCacheReads ? 0 : v.CacheRead)) }).ToArray(),
SeriesNames = seriesNames, Interval = daily ? TimeSpan.FromDays(1) : TimeSpan.FromHours(1) }));
content.Add(Ui.Columns([TokenChart("Tokens per hour", h.Hourly, false), TokenChart("Tokens per day", h.Daily, true)], wide));
content.Add(Ui.Text("Limit history", 20));
foreach (var limit in h.Limits.Where(l => l.Values.Count < 2))
content.Add(Ui.Text($"{limit.Label} · Collecting history since {limit.Since?.LocalDateTime:dd.MM. HH:mm}", 12, "Muted"));
content.Add(Ui.Columns(h.Limits.Where(l => l.Values.Count >= 2).Select(limit => Ui.Card(Ui.Stack(Ui.Text(limit.Label, 15),
Ui.Text("Used · dashed: even pace · dotted: average forecast", 12, "Muted"),
new UsageChart { Values = limit.Values, Percent = true, LimitProvider = limit.Provider, Forecast = limit.Forecast, ForecastStart = limit.ForecastStart }))), wide));
var windows = h.Limits.Where(l => l.Analysis?.Current.HasData == true).ToArray();
if (windows.Length > 0)
{
content.Add(Ui.Text("Window charts", 20));
content.Add(Ui.Columns(windows.Select(limit => Ui.Card(Ui.Stack(Ui.Text(limit.Label, 15),
Ui.Text("Measured · dashed: estimated · faint: previous · dotted: forecast", 12, "Muted"), new BurnUpChart(limit),
Ui.Text("Past instances · peak use", 12, "Muted"), new InstancePeaks(limit.Analysis!.Past, limit.Provider)))), wide));
}
content.Add(Ui.Text("Breakdown", 20));
content.Add(Ui.Columns([Breakdown("By model", h.Models, false), Breakdown("By project", h.Projects, true)], wide));
content.Add(Ui.Card(new BreakdownTable("By model", h.AllModels.Count > 0 ? h.AllModels : h.Models, false, model.ProviderFilter, modelBreakdown)));
content.Add(Ui.Card(new BreakdownTable("By project", h.AllProjects.Count > 0 ? h.AllProjects : h.Projects, true, model.ProviderFilter, projectBreakdown)));
if (model.Diagnostics.Count > 0)
{
var lines = Ui.Stack();
@@ -189,7 +193,7 @@ public sealed class PanelWindow : Window
var chip = new Border { Child = Ui.Mark(Display.State(pace.State), Brush.Parse("#0b0b0b")), Background = PaceBar.Colour(pace.State), CornerRadius = new CornerRadius(6), Padding = new Thickness(8, 4) };
DockPanel.SetDock(chip, Dock.Right); title.Children.Add(chip); title.Children.Add(Ui.Text(w.Provider + " · " + w.Label, 15));
var card = Ui.Stack(title, Ui.Text($"{w.UsedPercent:0.#} %", 36), Ui.Text("used", 12, "Muted"), new PaceBar(window) { Height = 10 });
card.Children.Add(Ui.Text(w.ResetsAt is { } reset ? $"Resets in {Display.Duration(reset - now)} · {reset.LocalDateTime:ddd HH:mm}" : "Reset unknown", 13, "Secondary"));
card.Children.Add(Ui.Text(w.ResetsAt is { } reset ? $"Resets in {Display.Duration(reset - now)} · {Display.Projection(reset)}" : "Reset unknown", 13, "Secondary"));
if (pace.Projection is { } projection)
{
var caption = Display.Forecast(projection, pace.State) + $" ({Display.Duration(w.ResetsAt!.Value - projection)} before reset)";
@@ -204,24 +208,27 @@ public sealed class PanelWindow : Window
card.Children.Add(Ui.Text($"≈ {average:0.#} % at reset", 13, "Secondary"));
if (detail?.Recent is { } recent)
{
var line = Ui.Text($"Last 24 h: +{recent.Increase:0.#} %" + (recent.ReachesLimit is { } date ? $" · 100 % on {date.LocalDateTime:ddd HH:mm}" : $" · ≈ {recent.UseAtReset:0.#} % at reset"), 13, "Secondary");
ToolTip.SetTip(line, $"{recent.PercentPerDay:0.##} %/day over {Display.Duration(recent.Span)} of samples"); card.Children.Add(line);
var line = Ui.Text($"Last {Display.Span(recent.Span)}: +{recent.Increase:0.#} %" + (recent.ReachesLimit is { } date ? $" · 100 % on {Display.Projection(date)}" : $" · ≈ {recent.UseAtReset:0.#} % at reset"), 13, "Secondary");
ToolTip.SetTip(line, new DataTooltip("Recent rate", new("Rate", $"{recent.PercentPerDay:0.##} %/day"), new("Observed span", Display.Duration(recent.Span)))); card.Children.Add(line);
}
if (detail?.Days is { } days)
{
card.Children.Add(Ui.Text(days.Today is { } today ? $"Today +{today:0.#} % of the week" : "Today · collecting a day baseline", 15));
card.Children.Add(Ui.Text(days.Today is { } today ? days.TodayOrigin == UseOrigin.Estimated
? $"Today ≈ +{today:0.#} % of the week (estimated)" : $"Today +{today:0.#} % of the week" : "Today · collecting a day baseline", 15));
card.Children.Add(Ui.Text($"Even pace {days.EvenPace:0.#} %/day", 13, "Secondary"));
if (days.DailyBudget is { } budget) card.Children.Add(Ui.Text($"Budget {budget:0.#} %/day for {Display.Duration(w.ResetsAt!.Value - now)}", 15));
}
if (now - w.SampleTime > model.ProbeInterval * 2) card.Children.Add(Ui.Text($"⚠ sample {Display.Duration(now - w.SampleTime)} old", 12, "Muted"));
var tile = Ui.Card(card); tile.Name = $"LimitTile-{w.Provider}-{w.Id}"; return tile;
var tile = Ui.Card(card); tile.Name = $"LimitTile-{w.Provider}-{w.Id}";
ToolTip.SetTip(tile, new DataTooltip(w.Provider + " · " + w.Label, new("Used", $"{w.UsedPercent:0.##} %"), new("Expected", $"{pace.ElapsedFraction * 100:0.##} %"),
new("State", Display.State(pace.State)), new("Reset", w.ResetsAt is { } r ? Display.Projection(r) : "Unknown"), new("Sample", w.SampleTime.LocalDateTime.ToString("g")))); return tile;
}
private Control TokenTile(ProviderSnapshot provider, string label, TokenCounts counts)
{
var tile = Ui.Stack(Ui.Text(label, 12, "Secondary"), Ui.Text(Display.Compact(Math.Max(0, counts.Total - (model.IncludeCacheReads ? 0 : counts.CacheRead))), 32),
new CompositionBar(counts, provider.Provider, model.IncludeCacheReads) { Height = 6 });
tile.Width = wide ? 164 : 188; tile.Margin = new Thickness(0, 8, 16, 0);
ToolTip.SetTip(tile, Display.Tokens(counts)); return tile;
ToolTip.SetTip(tile, DataTooltip.Tokens(provider.Provider + " · " + label, counts)); return tile;
}
private Control CompositionLegend()
{
@@ -248,43 +255,6 @@ public sealed class PanelWindow : Window
}
return legend;
}
private Control Breakdown(string title, IReadOnlyList<BreakdownRow> rows, bool projects)
{
var table = Ui.Stack(Ui.Text(title, 15));
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,90,140"), RowSpacing = 8, ColumnSpacing = 8 };
var names = projects ? ShortProjectNames(rows.Select(r => r.Name).ToArray()) : rows.Select(r => r.Name).ToArray();
Add(Ui.Text("Name", 12, "Muted"), 0, 0); Add(Ui.Text("Total", 12, "Muted"), 0, 1); Add(Ui.Text("Share", 12, "Muted"), 0, 2);
for (var i = 0; i < rows.Count; i++)
{
var row = rows[i]; var label = Ui.Text(names[i], 13);
label.TextWrapping = TextWrapping.NoWrap; label.TextTrimming = TextTrimming.CharacterEllipsis;
Control nameCell = label;
if (!projects && model.ProviderFilter is null && row.Providers is { Count: > 0 } rowProviders)
{
var cell = new DockPanel();
foreach (var provider in rowProviders)
{
var dot = Ui.Mark("●", Ui.ProviderColour(provider, Ui.Dark(this))); dot.Margin = new Thickness(0, 0, 6, 0);
ToolTip.SetTip(dot, provider.ToString()); DockPanel.SetDock(dot, Dock.Left); cell.Children.Add(dot);
}
cell.Children.Add(label); nameCell = cell;
}
ToolTip.SetTip(nameCell, row.Name + "\n" + Display.Tokens(row.Counts)); Add(nameCell, i + 1, 0);
var total = Ui.TableNumber(Display.Compact(row.Counts.Total)); ToolTip.SetTip(total, Display.Tokens(row.Counts)); Add(total, i + 1, 1);
var share = new Grid { ColumnDefinitions = new ColumnDefinitions("*,50"), ColumnSpacing = 8 };
share.Children.Add(new ProgressBar { Minimum = 0, Maximum = 1, Value = row.Share, Width = 82, MinWidth = 0, Height = 5, VerticalAlignment = VerticalAlignment.Center,
Foreground = model.ProviderFilter is { } p ? Ui.ProviderColour(p, Ui.Dark(this)) : Ui.Colour("Muted", Ui.Dark(this)) });
var percent = Ui.TableNumber(row.Share.ToString("P1"), 12, "Secondary"); Grid.SetColumn(percent, 1); share.Children.Add(percent);
ToolTip.SetTip(share, row.Name + "\n" + Display.Tokens(row.Counts)); Add(share, i + 1, 2);
}
table.Children.Add(grid); if (rows.Count == 0) table.Children.Add(Ui.Text("No tokens in this range.", 12, "Muted"));
return Ui.Card(table);
void Add(Control c, int row, int col)
{
while (grid.RowDefinitions.Count <= row) grid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
Grid.SetRow(c, row); Grid.SetColumn(c, col); grid.Children.Add(c);
}
}
public static string[] ShortProjectNames(string[] paths)
{
var parts = paths.Select(p => p.Replace('\\', '/').Split('/', StringSplitOptions.RemoveEmptyEntries)).ToArray();
@@ -295,5 +265,11 @@ public sealed class PanelWindow : Window
return string.Join('/', p.TakeLast(depth));
}).ToArray();
}
// Leave wheel events unhandled so they bubble to the page instead of changing selection.
private sealed class WindowSelector : ComboBox
{
protected override Type StyleKeyOverride => typeof(ComboBox);
protected override void OnPointerWheelChanged(Avalonia.Input.PointerWheelEventArgs e) { }
}
public static int LimitColumnCount(double contentWidth) => contentWidth >= 1400 ? 3 : contentWidth >= 1200 ? 2 : 1;
}