Skip to content

Commit

Permalink
update links
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgerstmayr committed Sep 25, 2023
1 parent 301c403 commit 4d6340b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions example/dashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ dashboards:
},
],
onClick: (event) => {
if (!panel.queries[0].link) return;
const [month, year] = event.name.split("/");
const link = panel.queries[0].link.replaceAll("#", "%23").replace("{time}", `${year}-${month.padStart(2, "0")}`);
window.open(link);
Expand All @@ -240,6 +239,7 @@ dashboards:
CONVERT(COST(LAST(balance)), '{{ledger.ccy}}', DATE_ADD(YMONTH(DATE_ADD(YMONTH(FIRST(date)), 31)), -1)) AS book_value
WHERE account ~ '^Assets:' AND currency != '{{ledger.ccy}}'
GROUP BY year, month
link: /beancount/balance_sheet/?time={time}
type: echarts
script: |
const currencyFormat = new Intl.NumberFormat(undefined, {
Expand Down Expand Up @@ -291,7 +291,6 @@ dashboards:
},
],
onClick: (event) => {
if (!panel.queries[0].link) return;
const [month, year] = event.name.split("/");
const link = panel.queries[0].link.replaceAll("#", "%23").replace("{time}", `${year}-${month.padStart(2, "0")}`);
window.open(link);
Expand Down Expand Up @@ -1137,7 +1136,7 @@ dashboards:
},
],
onClick: (event) => {
if (!panel.queries[0].link) return;
if (event.seriesName === "Projection") return;
const [month, year] = event.name.split("/");
const link = panel.queries[0].link.replaceAll("#", "%23").replace("{time}", `${year}-${month.padStart(2, "0")}`);
window.open(link);
Expand Down
7 changes: 4 additions & 3 deletions frontend/tests/e2e/__snapshots__/dashboards.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ exports[`Dashboard: HTML Snapshot Tests Assets 1`] = `
]
}
],
"script": "const currencyFormat = new Intl.NumberFormat(undefined, {\\n style: \\"currency\\",\\n currency: ledger.ccy,\\n maximumFractionDigits: 0,\\n});\\nconst months = helpers.iterateMonths(ledger.dateFirst, ledger.dateLast).map((m) =\\u003e \`\${m.month}/\${m.year}\`);\\nconst amounts = {};\\n\\n// the beancount query only returns months where there was at least one matching transaction, therefore we group by month\\nfor (let row of panel.queries[0].result) {\\n amounts[\`\${row.month}/\${row.year}\`] = row.value[ledger.ccy];\\n}\\n\\nreturn {\\n tooltip: {\\n valueFormatter: currencyFormat.format,\\n },\\n xAxis: {\\n data: months,\\n },\\n yAxis: {\\n axisLabel: {\\n formatter: currencyFormat.format,\\n },\\n },\\n series: [\\n {\\n type: \\"line\\",\\n smooth: true,\\n connectNulls: true,\\n data: months.map((month) =\\u003e amounts[month]),\\n },\\n ],\\n onClick: (event) =\\u003e {\\n if (!panel.queries[0].link) return;\\n const [month, year] = event.name.split(\\"/\\");\\n const link = panel.queries[0].link.replaceAll(\\"#\\", \\"%23\\").replace(\\"{time}\\", \`\${year}-\${month.padStart(2, \\"0\\")}\`);\\n window.open(link);\\n },\\n};\\n",
"script": "const currencyFormat = new Intl.NumberFormat(undefined, {\\n style: \\"currency\\",\\n currency: ledger.ccy,\\n maximumFractionDigits: 0,\\n});\\nconst months = helpers.iterateMonths(ledger.dateFirst, ledger.dateLast).map((m) =\\u003e \`\${m.month}/\${m.year}\`);\\nconst amounts = {};\\n\\n// the beancount query only returns months where there was at least one matching transaction, therefore we group by month\\nfor (let row of panel.queries[0].result) {\\n amounts[\`\${row.month}/\${row.year}\`] = row.value[ledger.ccy];\\n}\\n\\nreturn {\\n tooltip: {\\n valueFormatter: currencyFormat.format,\\n },\\n xAxis: {\\n data: months,\\n },\\n yAxis: {\\n axisLabel: {\\n formatter: currencyFormat.format,\\n },\\n },\\n series: [\\n {\\n type: \\"line\\",\\n smooth: true,\\n connectNulls: true,\\n data: months.map((month) =\\u003e amounts[month]),\\n },\\n ],\\n onClick: (event) =\\u003e {\\n const [month, year] = event.name.split(\\"/\\");\\n const link = panel.queries[0].link.replaceAll(\\"#\\", \\"%23\\").replace(\\"{time}\\", \`\${year}-\${month.padStart(2, \\"0\\")}\`);\\n window.open(link);\\n },\\n};\\n",
"title": "Net Worth \\ud83d\\udcb0",
"type": "echarts",
"width": "50%"
Expand All @@ -304,6 +304,7 @@ exports[`Dashboard: HTML Snapshot Tests Assets 1`] = `
"queries": [
{
"bql": "SELECT year, month,\\nCONVERT(LAST(balance), \\u0027{{ledger.ccy}}\\u0027, DATE_ADD(YMONTH(DATE_ADD(YMONTH(FIRST(date)), 31)), -1)) AS market_value,\\nCONVERT(COST(LAST(balance)), \\u0027{{ledger.ccy}}\\u0027, DATE_ADD(YMONTH(DATE_ADD(YMONTH(FIRST(date)), 31)), -1)) AS book_value\\nWHERE account ~ \\u0027^Assets:\\u0027 AND currency != \\u0027{{ledger.ccy}}\\u0027\\nGROUP BY year, month\\n",
"link": "/beancount/balance_sheet/?time={time}",
"result": [
{
"book_value": {
Expand Down Expand Up @@ -548,7 +549,7 @@ exports[`Dashboard: HTML Snapshot Tests Assets 1`] = `
]
}
],
"script": "const currencyFormat = new Intl.NumberFormat(undefined, {\\n style: \\"currency\\",\\n currency: ledger.ccy,\\n maximumFractionDigits: 0,\\n});\\nconst months = helpers.iterateMonths(ledger.dateFirst, ledger.dateLast).map((m) =\\u003e \`\${m.month}/\${m.year}\`);\\nconst amounts = {};\\n\\n// the beancount query only returns months where there was at least one matching transaction, therefore we group by month\\nfor (let row of panel.queries[0].result) {\\n amounts[\`\${row.month}/\${row.year}\`] = {\\n market_value: row.market_value[ledger.ccy],\\n book_value: row.book_value[ledger.ccy],\\n };\\n}\\n\\nreturn {\\n tooltip: {\\n trigger: \\"axis\\",\\n valueFormatter: currencyFormat.format,\\n },\\n legend: {\\n top: \\"bottom\\",\\n },\\n xAxis: {\\n data: months,\\n },\\n yAxis: {\\n axisLabel: {\\n formatter: currencyFormat.format,\\n },\\n },\\n series: [\\n {\\n type: \\"line\\",\\n name: \\"Market Value\\",\\n smooth: true,\\n connectNulls: true,\\n data: months.map((month) =\\u003e amounts[month]?.market_value),\\n },\\n {\\n type: \\"line\\",\\n name: \\"Book Value\\",\\n smooth: true,\\n connectNulls: true,\\n data: months.map((month) =\\u003e amounts[month]?.book_value),\\n },\\n ],\\n onClick: (event) =\\u003e {\\n if (!panel.queries[0].link) return;\\n const [month, year] = event.name.split(\\"/\\");\\n const link = panel.queries[0].link.replaceAll(\\"#\\", \\"%23\\").replace(\\"{time}\\", \`\${year}-\${month.padStart(2, \\"0\\")}\`);\\n window.open(link);\\n },\\n};\\n",
"script": "const currencyFormat = new Intl.NumberFormat(undefined, {\\n style: \\"currency\\",\\n currency: ledger.ccy,\\n maximumFractionDigits: 0,\\n});\\nconst months = helpers.iterateMonths(ledger.dateFirst, ledger.dateLast).map((m) =\\u003e \`\${m.month}/\${m.year}\`);\\nconst amounts = {};\\n\\n// the beancount query only returns months where there was at least one matching transaction, therefore we group by month\\nfor (let row of panel.queries[0].result) {\\n amounts[\`\${row.month}/\${row.year}\`] = {\\n market_value: row.market_value[ledger.ccy],\\n book_value: row.book_value[ledger.ccy],\\n };\\n}\\n\\nreturn {\\n tooltip: {\\n trigger: \\"axis\\",\\n valueFormatter: currencyFormat.format,\\n },\\n legend: {\\n top: \\"bottom\\",\\n },\\n xAxis: {\\n data: months,\\n },\\n yAxis: {\\n axisLabel: {\\n formatter: currencyFormat.format,\\n },\\n },\\n series: [\\n {\\n type: \\"line\\",\\n name: \\"Market Value\\",\\n smooth: true,\\n connectNulls: true,\\n data: months.map((month) =\\u003e amounts[month]?.market_value),\\n },\\n {\\n type: \\"line\\",\\n name: \\"Book Value\\",\\n smooth: true,\\n connectNulls: true,\\n data: months.map((month) =\\u003e amounts[month]?.book_value),\\n },\\n ],\\n onClick: (event) =\\u003e {\\n const [month, year] = event.name.split(\\"/\\");\\n const link = panel.queries[0].link.replaceAll(\\"#\\", \\"%23\\").replace(\\"{time}\\", \`\${year}-\${month.padStart(2, \\"0\\")}\`);\\n window.open(link);\\n },\\n};\\n",
"title": "Portfolio \\ud83d\\udcc8",
"type": "echarts",
"width": "50%"
Expand Down Expand Up @@ -9025,7 +9026,7 @@ exports[`Dashboard: HTML Snapshot Tests Projection 1`] = `
]
}
],
"script": "const currencyFormat = new Intl.NumberFormat(undefined, {\\n style: \\"currency\\",\\n currency: ledger.ccy,\\n maximumFractionDigits: 0,\\n});\\nconst projectYears = 2; // number of years to project\\n\\n// the beancount query only returns months where there was at least one matching transaction, therefore we group by month\\nconst amounts = {};\\nconst amountsEx = {};\\nfor (let row of panel.queries[0].result) {\\n amounts[\`\${row.month}/\${row.year}\`] = row.value[ledger.ccy];\\n}\\nfor (let row of panel.queries[1].result) {\\n amountsEx[\`\${row.month}/\${row.year}\`] = row.value[ledger.ccy];\\n}\\n\\nconst results = panel.queries[0].result;\\nconst resultsEx = panel.queries[1].result;\\nconst finalAmount = results[results.length - 1].value[ledger.ccy];\\nconst dateFirst = new Date(resultsEx[0].year, resultsEx[0].month - 1, 1);\\nconst dateLast = new Date(\\n new Date(resultsEx[resultsEx.length - 1].year, resultsEx[resultsEx.length - 1].month, 1).getTime() - 1,\\n);\\nconst days = (dateLast - dateFirst) / (1000 * 60 * 60 * 24) + 1;\\nconst totalDiff = resultsEx[resultsEx.length - 1].value[ledger.ccy] - resultsEx[0].value[ledger.ccy];\\nconst monthlyDiff = (totalDiff / days) * (365 / 12);\\n\\nconst dateLastYear = dateLast.getFullYear();\\nconst dateLastMonth = dateLast.getMonth() + 1;\\nconst dateFirstStr = \`\${dateFirst.getFullYear()}-\${dateFirst.getMonth() + 1}-1\`;\\nconst dateProjectUntilStr = \`\${dateLastYear + projectYears}-\${dateLastMonth}-1\`;\\nconst months = helpers.iterateMonths(dateFirstStr, dateProjectUntilStr).map((m) =\\u003e \`\${m.month}/\${m.year}\`);\\nconst lastMonthIdx = months.findIndex((m) =\\u003e m === \`\${dateLastMonth}/\${dateLastYear}\`);\\n\\nconst projection = [];\\nlet sum = finalAmount;\\nfor (let i = lastMonthIdx; i \\u003c months.length; i++) {\\n projection[months[i]] = sum;\\n sum += monthlyDiff;\\n}\\n\\nreturn {\\n tooltip: {\\n trigger: \\"axis\\",\\n valueFormatter: (val) =\\u003e (val ? currencyFormat.format(val) : \\"\\"),\\n },\\n legend: {\\n top: \\"bottom\\",\\n },\\n xAxis: {\\n data: months,\\n },\\n yAxis: {\\n axisLabel: {\\n formatter: currencyFormat.format,\\n },\\n },\\n series: [\\n {\\n type: \\"line\\",\\n name: \\"Net Worth\\",\\n smooth: true,\\n connectNulls: true,\\n showSymbol: false,\\n data: months.map((month) =\\u003e amounts[month]),\\n },\\n {\\n type: \\"line\\",\\n name: \\"Excluding onetime txns\\",\\n smooth: true,\\n connectNulls: true,\\n showSymbol: false,\\n data: months.map((month) =\\u003e amountsEx[month]),\\n },\\n {\\n type: \\"line\\",\\n name: \\"Projection\\",\\n lineStyle: {\\n type: \\"dashed\\",\\n },\\n showSymbol: false,\\n data: months.map((month) =\\u003e projection[month]),\\n },\\n ],\\n onClick: (event) =\\u003e {\\n if (!panel.queries[0].link) return;\\n const [month, year] = event.name.split(\\"/\\");\\n const link = panel.queries[0].link.replaceAll(\\"#\\", \\"%23\\").replace(\\"{time}\\", \`\${year}-\${month.padStart(2, \\"0\\")}\`);\\n window.open(link);\\n },\\n};\\n",
"script": "const currencyFormat = new Intl.NumberFormat(undefined, {\\n style: \\"currency\\",\\n currency: ledger.ccy,\\n maximumFractionDigits: 0,\\n});\\nconst projectYears = 2; // number of years to project\\n\\n// the beancount query only returns months where there was at least one matching transaction, therefore we group by month\\nconst amounts = {};\\nconst amountsEx = {};\\nfor (let row of panel.queries[0].result) {\\n amounts[\`\${row.month}/\${row.year}\`] = row.value[ledger.ccy];\\n}\\nfor (let row of panel.queries[1].result) {\\n amountsEx[\`\${row.month}/\${row.year}\`] = row.value[ledger.ccy];\\n}\\n\\nconst results = panel.queries[0].result;\\nconst resultsEx = panel.queries[1].result;\\nconst finalAmount = results[results.length - 1].value[ledger.ccy];\\nconst dateFirst = new Date(resultsEx[0].year, resultsEx[0].month - 1, 1);\\nconst dateLast = new Date(\\n new Date(resultsEx[resultsEx.length - 1].year, resultsEx[resultsEx.length - 1].month, 1).getTime() - 1,\\n);\\nconst days = (dateLast - dateFirst) / (1000 * 60 * 60 * 24) + 1;\\nconst totalDiff = resultsEx[resultsEx.length - 1].value[ledger.ccy] - resultsEx[0].value[ledger.ccy];\\nconst monthlyDiff = (totalDiff / days) * (365 / 12);\\n\\nconst dateLastYear = dateLast.getFullYear();\\nconst dateLastMonth = dateLast.getMonth() + 1;\\nconst dateFirstStr = \`\${dateFirst.getFullYear()}-\${dateFirst.getMonth() + 1}-1\`;\\nconst dateProjectUntilStr = \`\${dateLastYear + projectYears}-\${dateLastMonth}-1\`;\\nconst months = helpers.iterateMonths(dateFirstStr, dateProjectUntilStr).map((m) =\\u003e \`\${m.month}/\${m.year}\`);\\nconst lastMonthIdx = months.findIndex((m) =\\u003e m === \`\${dateLastMonth}/\${dateLastYear}\`);\\n\\nconst projection = [];\\nlet sum = finalAmount;\\nfor (let i = lastMonthIdx; i \\u003c months.length; i++) {\\n projection[months[i]] = sum;\\n sum += monthlyDiff;\\n}\\n\\nreturn {\\n tooltip: {\\n trigger: \\"axis\\",\\n valueFormatter: (val) =\\u003e (val ? currencyFormat.format(val) : \\"\\"),\\n },\\n legend: {\\n top: \\"bottom\\",\\n },\\n xAxis: {\\n data: months,\\n },\\n yAxis: {\\n axisLabel: {\\n formatter: currencyFormat.format,\\n },\\n },\\n series: [\\n {\\n type: \\"line\\",\\n name: \\"Net Worth\\",\\n smooth: true,\\n connectNulls: true,\\n showSymbol: false,\\n data: months.map((month) =\\u003e amounts[month]),\\n },\\n {\\n type: \\"line\\",\\n name: \\"Excluding onetime txns\\",\\n smooth: true,\\n connectNulls: true,\\n showSymbol: false,\\n data: months.map((month) =\\u003e amountsEx[month]),\\n },\\n {\\n type: \\"line\\",\\n name: \\"Projection\\",\\n lineStyle: {\\n type: \\"dashed\\",\\n },\\n showSymbol: false,\\n data: months.map((month) =\\u003e projection[month]),\\n },\\n ],\\n onClick: (event) =\\u003e {\\n if (event.seriesName === \\"Projection\\") return;\\n const [month, year] = event.name.split(\\"/\\");\\n const link = panel.queries[0].link.replaceAll(\\"#\\", \\"%23\\").replace(\\"{time}\\", \`\${year}-\${month.padStart(2, \\"0\\")}\`);\\n window.open(link);\\n },\\n};\\n",
"title": "Net Worth \\ud83d\\udcb0",
"type": "echarts"
}
Expand Down

0 comments on commit 4d6340b

Please sign in to comment.