Skip to content

Commit

Permalink
Update readme, respect filters in assets YoY chart, cleanup dashboard (
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgerstmayr authored Mar 20, 2024
1 parent 83c0e0f commit 684b357
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Enable this plugin in Fava by adding the following lines to your ledger:
```

## Configuration
The plugin looks by default for a `dashboards.yaml` file in the same directory where Fava is started (e.g. if you run `fava personal.beancount`, the `dashboards.yaml` file should be in the same directory as `personal.beancount`).
The plugin looks by default for a `dashboards.yaml` file in the directory of the Beancount ledger (e.g. if you run `fava personal.beancount`, the `dashboards.yaml` file should be in the same directory as `personal.beancount`).
The location of the `dashboards.yaml` configuration file can be customized:
```
2010-01-01 custom "fava-extension" "fava_dashboards" "{
Expand All @@ -49,6 +49,7 @@ The `script` field must contain valid JavaScript code.
It must return a valid configuration depending on the panel `type`.
The following variables and functions are available:
* `ext`: the Fava [`ExtensionContext`](https://github.com/beancount/fava/blob/main/frontend/src/extensions.ts)
* `ext.api.get("query", {bql: "SELECT ..."}`: executes the specified BQL query
* `panel`: the current (augmented) panel definition. The results of the BQL queries can be accessed with `panel.queries[i].result`.
* `ledger.dateFirst`: first date in the current date filter
* `ledger.dateLast`: last date in the current date filter
Expand Down
17 changes: 8 additions & 9 deletions example/dashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ dashboards:
// Unfortunately the `balance` column does not support GROUP BY
// (see https://groups.google.com/g/beancount/c/TfZJswxuIDA/m/psc2BkrBAAAJ)
// therefore we need to run a separate query per year.
const filterParams = Object.fromEntries(new URL(window.location.href).searchParams);
const queries = await Promise.all(
years.map((year) =>
ext.api.get("query", {
Expand All @@ -358,6 +359,7 @@ dashboards:
FROM CLOSE ON ${year + 1}-01-01
WHERE account_sortkey(account) ~ '^[01]'
GROUP BY currency`,
...filterParams,
}),
),
);
Expand Down Expand Up @@ -623,7 +625,7 @@ dashboards:
SELECT root(account, 4) AS account, CONVERT(SUM(position), '{{ledger.ccy}}') AS value
WHERE account ~ '^Income:'
GROUP BY account
link: /beancount/account/{account}/?r=changes&time={time}
link: /beancount/account/{account}/?r=changes
type: echarts
script: |
const currencyFormat = new Intl.NumberFormat(undefined, {
Expand Down Expand Up @@ -658,8 +660,7 @@ dashboards:
],
[clickEvt]: (event) => {
const account = "Income" + event.treePathInfo.map((i) => i.name).join(":");
const time = new URLSearchParams(window.location.search).get("time") ?? "";
const link = panel.queries[0].link.replace("{account}", account).replace("{time}", time);
const link = panel.queries[0].link.replace("{account}", account);
window.open(helpers.urlFor(link));
},
};
Expand All @@ -672,7 +673,7 @@ dashboards:
SELECT root(account, 3) AS account, CONVERT(SUM(position), '{{ledger.ccy}}') AS value
WHERE account ~ '^Expenses:'
GROUP BY account
link: /beancount/account/{account}/?r=changes&time={time}
link: /beancount/account/{account}/?r=changes
type: echarts
script: |
const currencyFormat = new Intl.NumberFormat(undefined, {
Expand Down Expand Up @@ -707,8 +708,7 @@ dashboards:
],
[clickEvt]: (event) => {
const account = "Expenses" + event.treePathInfo.map((i) => i.name).join(":");
const time = new URLSearchParams(window.location.search).get("time") ?? "";
const link = panel.queries[0].link.replace("{account}", account).replace("{time}", time);
const link = panel.queries[0].link.replace("{account}", account);
window.open(helpers.urlFor(link));
},
};
Expand Down Expand Up @@ -1050,7 +1050,7 @@ dashboards:
SELECT account, CONVERT(SUM(position), '{{ledger.ccy}}') AS value
WHERE account ~ '^(Income|Expenses):'
GROUP BY account
link: /beancount/account/{account}/?time={time}
link: /beancount/account/{account}/
type: d3_sankey
script: |
const currencyFormat = new Intl.NumberFormat(undefined, {
Expand Down Expand Up @@ -1113,8 +1113,7 @@ dashboards:
},
onClick: (event, node) => {
if (node.name === "Savings") return;
const time = new URLSearchParams(window.location.search).get("time") ?? "";
const link = panel.queries[0].link.replace("{account}", node.name).replace("{time}", time);
const link = panel.queries[0].link.replace("{account}", node.name);
window.open(helpers.urlFor(link));
},
};
Expand Down

0 comments on commit 684b357

Please sign in to comment.