Skip to content

Commit 18c9149

Browse files
committed
make it work for the chart as well
1 parent 9cd973c commit 18c9149

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
### coin2html
2626

27-
- allow dropping subaccounts from aggregations (in both chart and register)
2827
- show reconciliation state in balance view (last reconciled date? vs balance date?)
2928
- show reconciliation flag in non-aggregated register
3029
- filter subaccounts, payee, tag...

cmd/coin2html/js/src/viewsAggregatedRegisterChart.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
AggregationStyle,
99
addAggregationStyleInput,
1010
showDetails,
11+
addExcludedSubAccountsSpan,
12+
updateView,
1113
} from "./views";
1214
import {
1315
groupByWithSubAccounts,
@@ -22,10 +24,11 @@ import { select } from "d3-selection";
2224

2325
export function viewAggregatedRegisterChart(options?: {
2426
negated?: boolean; // is this negatively denominated account (e.g. Income/Liability)
27+
exclude?: Account[];
2528
}) {
2629
const containerSelector = MainView;
2730
const account = State.SelectedAccount;
28-
const opts = { negated: false }; // defaults
31+
const opts = { negated: false, exclude: State.View.ExcludeSubAccounts }; // defaults
2932
Object.assign(opts, options);
3033
// clear out the container
3134
emptyElement(containerSelector);
@@ -34,13 +37,17 @@ export function viewAggregatedRegisterChart(options?: {
3437
});
3538
addAggregationStyleInput(containerSelector);
3639
addSubAccountMaxInput(containerSelector);
40+
addExcludedSubAccountsSpan(containerSelector, account);
3741

3842
const groupKey = Aggregation[State.View.Aggregate] as d3.TimeInterval;
3943
const dates = groupKey.range(State.StartDate, State.EndDate);
4044
const maxAccounts = State.View.AggregatedSubAccountMax;
41-
const accountGroups = groupByWithSubAccounts(account, groupKey, maxAccounts, {
42-
negated: opts.negated,
43-
});
45+
const accountGroups = groupByWithSubAccounts(
46+
account,
47+
groupKey,
48+
maxAccounts,
49+
opts,
50+
);
4451
const maxLabelLength = Math.round(180 / State.View.AggregatedSubAccountMax);
4552
const labelFromAccount = (a: Account | undefined) =>
4653
a ? shortenAccountName(account.relativeName(a), maxLabelLength) : "Other";
@@ -54,7 +61,7 @@ export function viewAggregatedRegisterChart(options?: {
5461
: group.balance;
5562
const widthFromGroup = (group: PostingGroup) => {
5663
let width = Math.trunc(
57-
account.commodity.convert(amountFromGroup(group), group.date).toNumber()
64+
account.commodity.convert(amountFromGroup(group), group.date).toNumber(),
5865
);
5966
if (opts.negated) width = -width;
6067
return width < 0 ? 0 : width;
@@ -137,7 +144,7 @@ export function viewAggregatedRegisterChart(options?: {
137144

138145
var legend = svg
139146
.selectAll(".legend")
140-
.data(labels)
147+
.data(accountGroups.map((gs) => gs.account))
141148
.join("g")
142149
.attr("class", "legend")
143150
.attr("transform", "translate(" + margin.left + ",0)");
@@ -154,7 +161,12 @@ export function viewAggregatedRegisterChart(options?: {
154161

155162
legend
156163
.append("text")
157-
.text((d) => d)
164+
.text((a) => labelFromAccount(a))
158165
.attr("x", (d, i) => w * i + 10)
159-
.attr("y", textOffset);
166+
.attr("y", textOffset)
167+
.on("click", (e, d) => {
168+
if (!d) return;
169+
State.View.ExcludeSubAccounts.push(d);
170+
updateView();
171+
});
160172
}

0 commit comments

Comments
 (0)