Step 3 of the analytics plan: - Zusammensetzung: treemap (chartjs-chart-treemap 4.2.2, vendored) with the queried node's children and, nested, their children; clicking a tile drills down to that level - Jahresvergleich: one line per year over Jan-Dec, monthly or cumulative - Jahre im Vergleich: category x year table, cells shaded by monthly average (so the running year compares fairly), change vs. the same months of the previous year, clickable rows; replaces both heatmap and table from the plan - ExpenseAnalysis returns year profiles, the category x year table and the two-level composition; StackedBarChart becomes a generic ChartJsChart - Click hints only show when something can be drilled into; the treemap cursor only changes over clickable tiles; zero cells show "-" Fix: choosing a year in Von/Bis started an endless navigation loop (FluentSelect re-reports its value on every re-render, before the new URL has been applied), so the page stopped updating. The handlers now take over the year immediately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
3.5 KiB
C#
98 lines
3.5 KiB
C#
#nullable enable
|
||
|
||
using System;
|
||
using System.Collections.Generic;
|
||
|
||
namespace Schaad.Accounting.Datasets.Analytics
|
||
{
|
||
public enum AnalyticsPeriod
|
||
{
|
||
Month,
|
||
Quarter,
|
||
Year
|
||
}
|
||
|
||
public enum AnalyticsLevel
|
||
{
|
||
All,
|
||
SubClass,
|
||
Account,
|
||
Text
|
||
}
|
||
|
||
/// <summary>
|
||
/// A position in the drill-down: all expenses → subclass → account → booking-text group.
|
||
/// Deeper nodes carry their parents (an account node also has its subclass).
|
||
/// </summary>
|
||
public record AnalyticsNode(int? SubClass = null, int? Account = null, string? Text = null)
|
||
{
|
||
public static readonly AnalyticsNode All = new();
|
||
|
||
public AnalyticsLevel Level =>
|
||
Text != null ? AnalyticsLevel.Text
|
||
: Account != null ? AnalyticsLevel.Account
|
||
: SubClass != null ? AnalyticsLevel.SubClass
|
||
: AnalyticsLevel.All;
|
||
}
|
||
|
||
public record AnalyticsQuery(int FromYear, int ToYear, AnalyticsPeriod Period, AnalyticsNode Node);
|
||
|
||
public record AnalyticsBreadcrumb(AnalyticsNode Node, string Name);
|
||
|
||
/// <summary>
|
||
/// One child of the queried node, with its value per period (aligned with
|
||
/// <see cref="AnalyticsResult.Periods"/>).
|
||
/// </summary>
|
||
public record AnalyticsCategory(
|
||
AnalyticsNode Node,
|
||
string Name,
|
||
IReadOnlyList<decimal> Values,
|
||
decimal Total,
|
||
decimal Share,
|
||
bool CanDrillDown);
|
||
|
||
/// <summary>
|
||
/// The last year of the range against the year before, over the same months
|
||
/// (January to <see cref="Months"/>), so an unfinished year compares fairly.
|
||
/// </summary>
|
||
public record YearComparison(int Year, int Months, decimal Current, decimal Previous)
|
||
{
|
||
public decimal? ChangePercent => Previous == 0 ? null : (Current - Previous) / Math.Abs(Previous) * 100;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Monthly values of the queried node in one year (index 0 = January). Months after the last
|
||
/// month with data are null.
|
||
/// </summary>
|
||
public record YearProfile(int Year, IReadOnlyList<decimal?> Months, decimal Total);
|
||
|
||
/// <summary>
|
||
/// A category's value in one year. For the running year only the months with data count, and
|
||
/// the change compares the same months of the previous year.
|
||
/// </summary>
|
||
public record YearCell(int Year, decimal Value, decimal? ChangePercent);
|
||
|
||
/// <summary>
|
||
/// One row of the category × year table, in the same order as <see cref="AnalyticsResult.Categories"/>.
|
||
/// </summary>
|
||
public record CategoryYears(AnalyticsNode Node, string Name, bool CanDrillDown, IReadOnlyList<YearCell> Cells, decimal Total);
|
||
|
||
/// <summary>
|
||
/// A treemap tile: a child of the queried node and, one level deeper, one of its children.
|
||
/// <see cref="Child"/> is null when the child has no deeper level (booking-text groups).
|
||
/// Only positive amounts are included; an area can't show a refund.
|
||
/// </summary>
|
||
public record CompositionItem(AnalyticsNode Parent, string ParentName, AnalyticsNode? Child, string? ChildName, decimal Value);
|
||
|
||
public record AnalyticsResult(
|
||
IReadOnlyList<AnalyticsBreadcrumb> Breadcrumb,
|
||
IReadOnlyList<DateOnly> Periods,
|
||
IReadOnlyList<AnalyticsCategory> Categories,
|
||
decimal Total,
|
||
int Months,
|
||
decimal AveragePerMonth,
|
||
YearComparison? Comparison,
|
||
IReadOnlyList<YearProfile> YearProfiles,
|
||
IReadOnlyList<CategoryYears> CategoryYears,
|
||
IReadOnlyList<CompositionItem> Composition);
|
||
}
|