Skip to content

Commit

Permalink
coin2html: update account list update fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mkobetic committed Dec 15, 2024
1 parent 05c1e5a commit 743848c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 32 deletions.
5 changes: 5 additions & 0 deletions cmd/coin2html/js/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export class Account {
getRootAccount(): Account {
return this.parent ? this.parent.getRootAccount() : this;
}
isParentOf(a: Account): boolean {
if (!a.parent) return false;
if (a.parent == this) return true;
return this.isParentOf(a.parent);
}
}

export interface Tags {
Expand Down
10 changes: 6 additions & 4 deletions cmd/coin2html/js/src/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export enum AggregationStyle {
// UI State
export const State = {
// All these must be set after loading of data is finished, see initializeUI()
SelectedAccount: undefined as unknown as Account,
SelectedAccount: undefined as unknown as Account, // currently viewed account
AccountListRoot: undefined as unknown as Account, // account used to generate the account list
SelectedView: "Register",
StartDate: new Date(),
EndDate: new Date(),
Expand Down Expand Up @@ -231,7 +232,8 @@ export function updateAccount() {
.text((acc: Account) => acc.name)
.on("click", (e: Event, acc: Account) => {
State.SelectedAccount = acc;
updateAccount();
if (acc.isParentOf(State.AccountListRoot)) updateAccounts();
else updateAccount();
});
updateView();
}
Expand All @@ -257,10 +259,10 @@ export function addViewSelect() {

type liWithAccount = HTMLLIElement & { __data__: Account };
export function addAccountList() {
const account = State.SelectedAccount;
State.AccountListRoot = State.SelectedAccount;
select(AccountList)
.selectAll("li")
.data(account.allChildren())
.data(State.AccountListRoot.allChildren())
.join("li")
.text((d) => State.SelectedAccount.relativeName(d))
.on("click", (e: Event) => {
Expand Down
98 changes: 70 additions & 28 deletions examples/yearly/viewer/index.html

Large diffs are not rendered by default.

0 comments on commit 743848c

Please sign in to comment.