Skip to content

Commit

Permalink
increased default max depth to 10, added favicon, improved test
Browse files Browse the repository at this point in the history
  • Loading branch information
ma4nn committed Aug 19, 2024
1 parent 5e89500 commit f9e52ca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/SankeyChart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Exporter {version = {{ version }},
MAIN_CATEGORY_NAME = "Saldo" -- name of the category for balancing incomes and expenses
MISSING_CATEGORY_NAME = "(ohne)"
CATEGORIES_TO_EXCLUDE = {} -- which categories should be ignored
MAX_DEPTH_INCOME = 2 -- how deep to go down in the category path for incomes
MAX_DEPTH_EXPENSE = 2 -- how deep to go down in the category path for expenses
MAX_DEPTH_INCOME = 10 -- how deep to go down in the category path for incomes
MAX_DEPTH_EXPENSE = 10 -- how deep to go down in the category path for expenses
CATEGORIES_PATH_SEPARATOR = ' » '
SECONDS_PER_MONTH = 60 * 60 * 24 * 30;
CATEGORY_LINK_TYPE_INCOME = 'income'
Expand All @@ -62,7 +62,7 @@ local function pairsByKeys (t, f)
return iter
end

local function get_link_id(category_link)
local function get_link_id (category_link)
return 10000 * category_link.from_category_id + category_link.to_category_id
end

Expand Down Expand Up @@ -119,6 +119,7 @@ function WriteHeader (account, startDate, endDate, transactionCount)
<title>Cashflow Chart ]] .. start_date .. [[ bis ]] .. end_date .. [[</title>
<link rel="stylesheet" href="{{ highcharts_css_url }}" integrity="{{ highcharts_css_sri }}" crossorigin="anonymous">
<link href="{{ bootstrap_css_url }}" rel="stylesheet" integrity="{{ bootstrap_css_sri }}" crossorigin="anonymous">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 576 512'%3E%3C!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--%3E%3Cpath fill='%23304f5f' d='M304 240l0-223.4c0-9 7-16.6 16-16.6C443.7 0 544 100.3 544 224c0 9-7.6 16-16.6 16L304 240zM32 272C32 150.7 122.1 50.3 239 34.3c9.2-1.3 17 6.1 17 15.4L256 288 412.5 444.5c6.7 6.7 6.2 17.7-1.5 23.1C371.8 495.6 323.8 512 272 512C139.5 512 32 404.6 32 272zm526.4 16c9.3 0 16.6 7.8 15.4 17c-7.7 55.9-34.6 105.6-73.9 142.3c-6 5.6-15.4 5.2-21.2-.7L320 288l238.4 0z'/%3E%3C/svg%3E">
<style>
{{ inline_css }}
</style>
Expand All @@ -127,7 +128,7 @@ function WriteHeader (account, startDate, endDate, transactionCount)
<div class="container">
<h1 class="text-center">Cashflows</h1>
<h5 class="text-center">]] .. account.name .. [[, ]] .. start_date .. [[ bis ]] .. end_date .. [[</h5>
<p class="text-center">Das folgende <a href="https://de.wikipedia.org/wiki/Sankey-Diagramm" target="_blank">Sankey Chart</a> zeigt die aus <a href="https://moneymoney-app.com/" target="_blank">MoneyMoney</a> exportierten Cashflows des <strong>Kontos ]] .. account.name .. [[ (]] .. account.accountNumber .. [[)</strong> für den <strong>Zeitraum ]] .. start_date .. [[ bis ]] .. end_date .. [[</strong>.<br>
<p class="text-center">Das folgende <a href="https://de.wikipedia.org/wiki/Sankey-Diagramm" target="_blank" rel="external noopener">Sankey Chart</a> zeigt die aus <a href="https://moneymoney-app.com/" target="_blank" rel="external noopener">MoneyMoney</a> exportierten Cashflows des <strong>Kontos ]] .. account.name .. [[ (]] .. account.accountNumber .. [[)</strong> für den <strong>Zeitraum ]] .. start_date .. [[ bis ]] .. end_date .. [[</strong>.<br>
Es wurde aus insgesamt <strong>]] .. transactionCount .. [[ Transaktionen</strong> generiert.</p>
<div class="controls pb-4">
Expand Down Expand Up @@ -220,7 +221,7 @@ function WriteTransactions (account, transactions)
end
end
else
print("Transaction " .. transaction.name .. " currency " .. transaction.currency .. " differs from the others (" .. currency .. " or category " .. transaction.category .. " is excluded, skipping.")
print("Transaction '" .. transaction.name .. "' in currency " .. transaction.currency .. " differs from the others (" .. currency .. ") or category " .. transaction.category .. " is excluded, skipping.")
end
end

Expand Down
23 changes: 19 additions & 4 deletions src/SankeyChartTest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@ io.output(f) -- suppress output
version = 1
currency = "EUR"

-- print is used for logging in MoneyMoney extensions, so we redirect it here
local print_stdout = print
print = function(...)
io.stderr:write(...)
end

-- dummy exporter
function Exporter(version, format, fileExtension, reverseOrder, description)
version = version
end

local dummyAccount = { name = "Test", accountNumber = 1234, currency = "EUR" }
local dummyAccount = { name = "Tagesgeld Test Bank", accountNumber = 1234, currency = currency }
local transactions = {
{ name = "Wocheneinkauf", amount = -3.50, currency = currency, category = "Freizeit" },
{ name = "Geschenk", amount = -20, currency = "USD", category = "Freizeit" },
{ name = "Tanken", amount = -69.76, currency = currency, category = "Auto\\Sprit" },
{ name = "Werkstatt", amount = -69.76, currency = currency, category = "Auto\\Instandhaltung" },
{ name = "Miete", amount = -800, currency = currency, category = "Wohnen" },
{ name = "Gehalt", amount = 1500, currency = currency, category = "Arbeit" },
{ name = "Aktie XYZ Dividende", amount = 45.32, currency = currency, category = "Dividende" },
}

local sankey_extension = require("dist/SankeyChart")

WriteHeader (dummyAccount, os.time{year=1970, month=1, day=1, hour=0}, os.time{year=1970, month=1, day=1, hour=0}, 1)
WriteTransactions (dummyAccount, {})
WriteHeader (dummyAccount, os.time{year=2024, month=3, day=10, hour=0}, os.time{year=2024, month=4, day=19, hour=0}, 1)
WriteTransactions (dummyAccount, transactions)
WriteTail (dummyAccount)

f:seek("set", 0) -- set file handle back to start
s = f:read("*a")
print (s)
print_stdout (s)

assert(s ~= nil and s ~= '')

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function createChart(chartDataTree: Tree): void {
// tooltip for link
pointFormatter: function() {
const point = this as any;
return point.fromNode.name + " → " + point.toNode.name + ": " + numberFormat(point.weight);
return point.fromNode.name + " → " + point.toNode.name + ": " + numberFormat(point.weight) + "<br /><br /><span class='small'>(Klick entfernt die Kategorie aus dem Chart.)</span>";
},
// tooltip for node
nodeFormatter: function() {
Expand Down
4 changes: 4 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ body, .highcharts-container {
font-family: system-ui
}

.small {
font-size: 9px;
}

footer, footer a:link, footer a:visited {
color: #efefef;
}
Expand Down

0 comments on commit f9e52ca

Please sign in to comment.