flip columns

This commit is contained in:
Emil Lerch 2026-04-22 15:34:43 -07:00
parent ee979eb794
commit 67f2d4d7d0

View file

@ -360,9 +360,10 @@ pub fn fmtSignedMoney(buf: []u8, value: f64) ![]const u8 {
return std.fmt.bufPrint(buf, "{s}{s}", .{ prefix, abs_str }); return std.fmt.bufPrint(buf, "{s}{s}", .{ prefix, abs_str });
} }
/// Render a multi-metric timeline: Date | Net Worth | Liquid | Illiquid, /// Render a multi-metric timeline: Date | Illiquid | Liquid | Net Worth,
/// with each column showing both current value and Δ from the first row. /// with each column showing both current value and Δ from the first row.
/// This is the default view it answers "how did my net worth change /// Columns read left-to-right as "components summing to the total"
/// illiquid + liquid = net worth. Answers "how did my net worth change
/// and was it liquid vs. illiquid?" in one glance. /// and was it liquid vs. illiquid?" in one glance.
/// ///
/// Takes a TimelinePoint slice directly (rather than already-extracted /// Takes a TimelinePoint slice directly (rather than already-extracted
@ -384,7 +385,7 @@ pub fn renderPortfolioTimelineAll(
try cli.setFg(out, color, cli.CLR_MUTED); try cli.setFg(out, color, cli.CLR_MUTED);
try out.print("{s:>12} {s:>28} {s:>28} {s:>28}\n", .{ try out.print("{s:>12} {s:>28} {s:>28} {s:>28}\n", .{
"Date", "Net Worth (Δ)", "Liquid (Δ)", "Illiquid (Δ)", "Date", "Illiquid (Δ)", "Liquid (Δ)", "Net Worth (Δ)",
}); });
try out.print("{s:->12} {s:->28} {s:->28} {s:->28}\n", .{ "", "", "", "" }); try out.print("{s:->12} {s:->28} {s:->28} {s:->28}\n", .{ "", "", "", "" });
try cli.reset(out, color); try cli.reset(out, color);
@ -396,21 +397,22 @@ pub fn renderPortfolioTimelineAll(
for (points) |p| { for (points) |p| {
var db: [10]u8 = undefined; var db: [10]u8 = undefined;
try out.print("{s:>12} ", .{p.as_of_date.format(&db)}); try out.print("{s:>12} ", .{p.as_of_date.format(&db)});
try writeValueDeltaCell(out, color, p.net_worth, p.net_worth - first_nw); try writeValueDeltaCell(out, color, p.illiquid, p.illiquid - first_ill);
try out.writeAll(" "); try out.writeAll(" ");
try writeValueDeltaCell(out, color, p.liquid, p.liquid - first_liq); try writeValueDeltaCell(out, color, p.liquid, p.liquid - first_liq);
try out.writeAll(" "); try out.writeAll(" ");
try writeValueDeltaCell(out, color, p.illiquid, p.illiquid - first_ill); try writeValueDeltaCell(out, color, p.net_worth, p.net_worth - first_nw);
try out.writeByte('\n'); try out.writeByte('\n');
} }
// Three-line summary footer: one line per metric, showing first // Three-line summary footer: one line per metric, showing first
// last and absolute/percent change. More readable than stuffing // last and absolute/percent change. More readable than stuffing
// everything into one wide line. // everything into one wide line. Ordered to match the column layout
// above (components first, total last).
try out.print("\n", .{}); try out.print("\n", .{});
try writeSummaryLine(out, color, " Net Worth", mapMetric(points, .net_worth));
try writeSummaryLine(out, color, " Liquid ", mapMetric(points, .liquid));
try writeSummaryLine(out, color, " Illiquid ", mapMetric(points, .illiquid)); try writeSummaryLine(out, color, " Illiquid ", mapMetric(points, .illiquid));
try writeSummaryLine(out, color, " Liquid ", mapMetric(points, .liquid));
try writeSummaryLine(out, color, " Net Worth", mapMetric(points, .net_worth));
try out.print("\n{d} snapshots\n\n", .{points.len}); try out.print("\n{d} snapshots\n\n", .{points.len});
} }