Skip to content

Commit

Permalink
coin2html: make the account heading clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
mkobetic committed Dec 7, 2024
1 parent 995dd6c commit 0509610
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/coin2html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Check out the [examples/yearly](https://mkobetic.github.io/coin/).

Account hierarchy nav on the left, segregated by account type (`Assets`, `Income`, `Expenses`, `Liabilities`, `Equity`).
Clicking a specific account restricts the detail view on the right to that account's hierarchy.
Currently selected account is shown as a heading above the details view.
Currently selected account is shown as a heading above the details view. The individual names in the heading can be clicked to select the account represented by the name (this allows climbing up the account parent chain conveniently).

Details of the selected account are shown on the right with different presentation options (`Register`, `Chart`, ...).
The details show account transactions restricted to selected time range, controlled by the `From/To` inputs.
Expand Down
3 changes: 3 additions & 0 deletions cmd/coin2html/js/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ export class Account {
),
}));
}
withAllParents(): Account[] {
return this.parent ? this.parent.withAllParents().concat(this) : [this];
}
getRootAccount(): Account {
return this.parent ? this.parent.getRootAccount() : this;
}
Expand Down
15 changes: 14 additions & 1 deletion cmd/coin2html/js/src/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,20 @@ function updateView() {

function updateAccount() {
const account = State.SelectedAccount;
d3.select(AccountOutput).text(account.fullName);
// d3.select(AccountOutput).text(account.fullName);
const spans = d3
.select(AccountOutput)
.selectAll("span")
.data(account.withAllParents())
.join("span")
.text((d) => (d.parent ? ":" : ""));
spans
.append("a")
.text((acc: Account) => acc.name)
.on("click", (e: Event, acc: Account) => {
State.SelectedAccount = acc;
updateAccount();
});
updateView();
}

Expand Down
24 changes: 21 additions & 3 deletions examples/yearly/viewer/index.html

Large diffs are not rendered by default.

0 comments on commit 0509610

Please sign in to comment.