hledger-web 1.43.2 → 1.50
raw patch · 10 files changed
+272/−238 lines, 10 filesdep ~basedep ~hledgerdep ~hledger-libPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, hledger, hledger-lib
API changes (from Hackage documentation)
Files
- CHANGES.md +19/−0
- Hledger/Web/Handler/RegisterR.hs +4/−4
- Hledger/Web/Widget/Common.hs +2/−2
- hledger-web.1 +8/−5
- hledger-web.cabal +11/−11
- hledger-web.info +15/−12
- hledger-web.txt +85/−82
- static/hledger.js +0/−80
- templates/chart.hamlet +127/−41
- templates/register.hamlet +1/−1
CHANGES.md view
@@ -18,8 +18,27 @@ API -->+ User-visible changes in hledger-web. See also the hledger changelog.+++# 1.50 2025-09-03++Breaking changes++- hledger now requires at least GHC 9.6 (and base 4.18), to ease maintenance.++Fixes++- The register chart is no longer hidden when the window is narrow.++- Dragging on the register chart now selects date ranges more accurately.+ Eg, now you can select a range including transactions at the rightmost edge of the chart.++Improvements++- Use hledger 1.50 # 1.43.2 2025-06-13
Hledger/Web/Handler/RegisterR.hs view
@@ -114,9 +114,9 @@ shownull c = if null c then " " else c nodatelink = (RegisterR, [("q", T.unwords $ removeDates q)]) -dayToJsTimestamp :: Day -> Integer-dayToJsTimestamp d =+-- | Makes a unix timestamp (milliseconds since epoch) corresponding to noon on the given date in UTC.+dayToUtcNoonTimestamp :: Day -> Integer+dayToUtcNoonTimestamp d = read (formatTime defaultTimeLocale "%s" t) * 1000 -- XXX read where- t = UTCTime d (secondsToDiffTime 0)-+ t = UTCTime d (secondsToDiffTime $ 12 * 60 * 60)
Hledger/Web/Widget/Common.hs view
@@ -82,9 +82,9 @@ where l = ledgerFromJournal Any j indent a = preEscapedString $ concat $ replicate (2 + 2 * a) " "- hasSubAccounts acct = maybe True (not . null . asubs) (ledgerAccount l acct)+ hasSubAccounts acct = maybe True (not . null . asubs) $ ledgerAccount l acct isInterestingAccount acct = maybe False isInteresting $ ledgerAccount l acct- where isInteresting a = not (mixedAmountLooksZero (aebalance a)) || any isInteresting (asubs a)+ where isInteresting a = not (all (mixedAmountLooksZero . bdexcludingsubs) . pdperiods $ adata a) || any isInteresting (asubs a) matchesAcctSelector acct = Just True == ((`matchesAccount` acct) <$> inAccountQuery qopts) accountQuery :: AccountName -> Text
hledger-web.1 view
@@ -1,5 +1,5 @@ -.TH "HLEDGER\-WEB" "1" "June 2025" "hledger-web-1.43.2 " "hledger User Manuals"+.TH "HLEDGER\-WEB" "1" "September 2025" "hledger-web-1.50 " "hledger User Manuals" @@ -7,7 +7,7 @@ hledger\-web \- web interface and API for \f[CR]hledger\f[R], a robust, friendly plain text accounting app. .SH SYNOPSIS-\f[CR]hledger\-web [OPTS] [QUERY]\f[R]+\f[CR]hledger\-web [OPTS] [QUERY]\f[R] .PD 0 .P .PD@@ -15,9 +15,9 @@ .PD 0 .P .PD-\f[CR]hledger web \-\- [OPTS] [QUERY]\f[R]+\f[CR]hledger web [OPTS] [QUERY]\f[R] .SH DESCRIPTION-This manual is for hledger\[aq]s web interface, version 1.43.2.+This manual is for hledger\[aq]s web interface, version 1.50. See also the hledger manual for common concepts and file formats. .PP hledger is a robust, user\-friendly, cross\-platform set of programs for@@ -84,7 +84,7 @@ \-\-base\-url=BASEURL set the base url (default: http://IPADDR:PORT) \-\-test run hledger\-web\[aq]s tests and exit. hspec test runner args may follow a \-\-, eg: hledger\-web \-\-test- \-\- \-\-help+ \-\-help .EE .PP By default hledger\-web listens only on IP address \f[CR]127.0.0.1\f[R],@@ -139,6 +139,9 @@ hledger\-ui, also make future\-dated transactions visible at startup. \-I \-\-ignore\-assertions don\[aq]t check balance assertions by default+ \-\-txn\-balancing=... how to check that transactions are balanced:+ \[aq]old\[aq]: use global display precision+ \[aq]exact\[aq]: use transaction precision (default) \-\-infer\-costs infer conversion equity postings from costs \-\-infer\-equity infer costs from conversion equity postings \-\-infer\-market\-prices infer market prices from costs
hledger-web.cabal view
@@ -1,11 +1,11 @@ cabal-version: 2.2 --- This file has been generated from package.yaml by hpack version 0.38.0.+-- This file has been generated from package.yaml by hpack version 0.38.2. -- -- see: https://github.com/sol/hpack name: hledger-web-version: 1.43.2+version: 1.50 synopsis: Web user interface for the hledger accounting system description: A simple web user interface for the hledger accounting system, providing a more modern UI than the command-line or terminal interfaces.@@ -28,7 +28,7 @@ license-file: LICENSE build-type: Simple tested-with:- ghc==8.10.7, ghc==9.0.2, ghc==9.2.8, ghc==9.4.8, ghc==9.6.7, ghc==9.8.4, ghc==9.10.2, ghc==9.12.1+ ghc==9.6.7, ghc==9.8.4, ghc==9.10.2, ghc==9.12.2 extra-source-files: CHANGES.md README.md@@ -159,11 +159,11 @@ hs-source-dirs: ./ ghc-options: -Wall -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns- cpp-options: -DVERSION="1.43.2"+ cpp-options: -DVERSION="1.50" build-depends: Decimal >=0.5.1 , aeson >=1 && <2.3- , base >=4.14 && <4.22+ , base >=4.18 && <4.22 , base64 , blaze-html , blaze-markup@@ -181,8 +181,8 @@ , filepath , githash >=0.1.6.2 , hjsmin- , hledger >=1.43.2 && <1.44- , hledger-lib >=1.43.2 && <1.44+ , hledger ==1.50.*+ , hledger-lib ==1.50.* , hspec , http-client , http-conduit@@ -229,9 +229,9 @@ hs-source-dirs: app ghc-options: -Wall -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -with-rtsopts=-T- cpp-options: -DVERSION="1.43.2"+ cpp-options: -DVERSION="1.50" build-depends:- base >=4.14 && <4.22+ base >=4.18 && <4.22 , hledger-web default-language: Haskell2010 if flag(threaded)@@ -251,9 +251,9 @@ hs-source-dirs: test ghc-options: -Wall -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns- cpp-options: -DVERSION="1.43.2"+ cpp-options: -DVERSION="1.50" build-depends:- base >=4.14 && <4.22+ base >=4.18 && <4.22 , hledger-web default-language: Haskell2010 if flag(threaded)
hledger-web.info view
@@ -16,9 +16,9 @@ 'hledger-web [OPTS] [QUERY]' or-'hledger web -- [OPTS] [QUERY]'+'hledger web [OPTS] [QUERY]' - This manual is for hledger's web interface, version 1.43.2. See also+ This manual is for hledger's web interface, version 1.50. See also the hledger manual for common concepts and file formats. hledger is a robust, user-friendly, cross-platform set of programs@@ -96,7 +96,7 @@ --base-url=BASEURL set the base url (default: http://IPADDR:PORT) --test run hledger-web's tests and exit. hspec test runner args may follow a --, eg: hledger-web --test- -- --help+ --help By default hledger-web listens only on IP address '127.0.0.1', which be accessed only from the local machine.@@ -144,6 +144,9 @@ hledger-ui, also make future-dated transactions visible at startup. -I --ignore-assertions don't check balance assertions by default+ --txn-balancing=... how to check that transactions are balanced:+ 'old': use global display precision+ 'exact': use transaction precision (default) --infer-costs infer conversion equity postings from costs --infer-equity infer costs from conversion equity postings --infer-market-prices infer market prices from costs@@ -525,15 +528,15 @@ Tag Table: Node: Top223-Node: OPTIONS2580-Node: PERMISSIONS11269-Node: EDITING UPLOADING DOWNLOADING12419-Node: RELOADING13434-Node: JSON API14001-Node: DEBUG OUTPUT19650-Node: Debug output19802-Node: ENVIRONMENT20320-Node: BUGS20556+Node: OPTIONS2575+Node: PERMISSIONS11473+Node: EDITING UPLOADING DOWNLOADING12623+Node: RELOADING13638+Node: JSON API14205+Node: DEBUG OUTPUT19854+Node: Debug output20006+Node: ENVIRONMENT20524+Node: BUGS20760 End Tag Table
hledger-web.txt view
@@ -6,43 +6,43 @@ plain text accounting app. SYNOPSIS- hledger-web [OPTS] [QUERY]+ hledger-web [OPTS] [QUERY] or- hledger web -- [OPTS] [QUERY]+ hledger web [OPTS] [QUERY] DESCRIPTION- This manual is for hledger's web interface, version 1.43.2. See also- the hledger manual for common concepts and file formats.+ This manual is for hledger's web interface, version 1.50. See also the+ hledger manual for common concepts and file formats. - hledger is a robust, user-friendly, cross-platform set of programs for- tracking money, time, or any other commodity, using double-entry ac-- counting and a simple, editable file format. hledger is inspired by- and largely compatible with ledger(1), and largely interconvertible+ hledger is a robust, user-friendly, cross-platform set of programs for+ tracking money, time, or any other commodity, using double-entry ac-+ counting and a simple, editable file format. hledger is inspired by+ and largely compatible with ledger(1), and largely interconvertible with beancount(1). - hledger-web is a simple web application for browsing and adding trans-- actions. It provides a more user-friendly UI than the hledger CLI or- hledger-ui TUI, showing more at once (accounts, the current account+ hledger-web is a simple web application for browsing and adding trans-+ actions. It provides a more user-friendly UI than the hledger CLI or+ hledger-ui TUI, showing more at once (accounts, the current account register, balance charts) and allowing history-aware data entry, inter- active searching, and bookmarking. - hledger-web also lets you share a journal with multiple users, or even- the public web. There is no access control, so if you need that you- should put it behind a suitable web proxy. As a small protection- against data loss when running an unprotected instance, it writes a+ hledger-web also lets you share a journal with multiple users, or even+ the public web. There is no access control, so if you need that you+ should put it behind a suitable web proxy. As a small protection+ against data loss when running an unprotected instance, it writes a numbered backup of the main journal file (only) on every edit. - Like hledger, it reads from (and appends to) a journal file specified- by the LEDGER_FILE environment variable (defaulting to- $HOME/.hledger.journal); or you can specify files with -f options. It- can also read timeclock files, timedot files, or any CSV/SSV/TSV file+ Like hledger, it reads from (and appends to) a journal file specified+ by the LEDGER_FILE environment variable (defaulting to+ $HOME/.hledger.journal); or you can specify files with -f options. It+ can also read timeclock files, timedot files, or any CSV/SSV/TSV file with a date field. (See hledger(1) -> Input for details.) hledger-web can be run in three modes: o --serve-browse mode (the default): the app serves the web UI and JSON- API, and opens your default web browser to show the app if possible,- and exits automatically after two minutes of inactivity (with no re-+ API, and opens your default web browser to show the app if possible,+ and exits automatically after two minutes of inactivity (with no re- quests received and no open browser windows viewing it). o --serve: the app just serves the web UI and JSON API.@@ -73,30 +73,30 @@ --base-url=BASEURL set the base url (default: http://IPADDR:PORT) --test run hledger-web's tests and exit. hspec test runner args may follow a --, eg: hledger-web --test- -- --help+ --help - By default hledger-web listens only on IP address 127.0.0.1, which be+ By default hledger-web listens only on IP address 127.0.0.1, which be accessed only from the local machine. To allow access from elsewhere, use --host to specify an externally ac-- cessible address configured on this machine, The special address+ cessible address configured on this machine, The special address 0.0.0.0 causes it to listen on all of this machine's addresses. - Similarly, you can use --port to listen on a TCP port other than 5000.- This is useful if you want to run multiple hledger-web instances on a+ Similarly, you can use --port to listen on a TCP port other than 5000.+ This is useful if you want to run multiple hledger-web instances on a machine. - When --socket is used, hledger-web creates and communicates via a- socket file instead of a TCP port. This can be more secure, respects+ When --socket is used, hledger-web creates and communicates via a+ socket file instead of a TCP port. This can be more secure, respects unix file permissions, and makes certain use cases easier, such as run- ning per-user instances behind an nginx reverse proxy. (Eg: proxy_pass http://unix:/tmp/hledger/${remote_user}.socket;.) - You can use --base-url to change the protocol, hostname, port and path- that appear in hledger-web's hyperlinks. This is useful eg when inte-- grating hledger-web within a larger website. The default is- http://HOST:PORT/ using the server's configured host address and TCP- port (or http://HOST if PORT is 80). Note this affects url generation+ You can use --base-url to change the protocol, hostname, port and path+ that appear in hledger-web's hyperlinks. This is useful eg when inte-+ grating hledger-web within a larger website. The default is+ http://HOST:PORT/ using the server's configured host address and TCP+ port (or http://HOST if PORT is 80). Note this affects url generation but not route parsing. hledger-web also supports many of hledger's general options:@@ -121,6 +121,9 @@ hledger-ui, also make future-dated transactions visible at startup. -I --ignore-assertions don't check balance assertions by default+ --txn-balancing=... how to check that transactions are balanced:+ 'old': use global display precision+ 'exact': use transaction precision (default) --infer-costs infer conversion equity postings from costs --infer-equity infer costs from conversion equity postings --infer-market-prices infer market prices from costs@@ -182,74 +185,74 @@ --pager=YN use a pager when needed ? y/yes (default) or n/no --color=YNA --colour use ANSI color ? y/yes, n/no, or auto (default) - hledger-web shows accounts with zero balances by default (like- hledger-ui, and unlike hledger). Using the -E/--empty flag will re-- verse this behaviour. If you see accounts which appear to have a zero- balance, but cannot be hidden with -E, it's because they have a- mixed-cost balance, which looks like zero when costs are hidden.+ hledger-web shows accounts with zero balances by default (like+ hledger-ui, and unlike hledger). Using the -E/--empty flag will re-+ verse this behaviour. If you see accounts which appear to have a zero+ balance, but cannot be hidden with -E, it's because they have a+ mixed-cost balance, which looks like zero when costs are hidden. (hledger-web does not show costs.) - Reporting options and/or query arguments can be used to set an initial+ Reporting options and/or query arguments can be used to set an initial query, which although not shown in the UI, will restrict the data shown (in addition to any search query entered in the UI). - If you use the bash shell, you can auto-complete flags by pressing TAB- in the command line. If this is not working see Install > Shell com-+ If you use the bash shell, you can auto-complete flags by pressing TAB+ in the command line. If this is not working see Install > Shell com- pletions. PERMISSIONS- By default, hledger-web allows anyone who can reach it to view the+ By default, hledger-web allows anyone who can reach it to view the journal and to add new transactions, but not to change existing data. You can restrict who can reach it, by - o setting the IP address it listens on (see --host above). By default- it listens on 127.0.0.1, accessible to users on the local machine+ o setting the IP address it listens on (see --host above). By default+ it listens on 127.0.0.1, accessible to users on the local machine only. o putting it behind an authenticating proxy, such as caddy or apache o putting it behind a firewall - And you can restrict what the users reaching it can do, by specifying+ And you can restrict what the users reaching it can do, by specifying the --allow=ACCESSLEVEL option at startup. ACCESSLEVEL is one of: o view - allows viewing the journal file(s) o add - also allows adding new transactions to the main journal file - o edit - also allows editing, uploading or downloading the journal+ o edit - also allows editing, uploading or downloading the journal file(s) - o sandstorm - (for the hledger-web Sandstorm app:) allows whichever of- view, add, or edit are specified in the X-Sandstorm-Permissions HTTP+ o sandstorm - (for the hledger-web Sandstorm app:) allows whichever of+ view, add, or edit are specified in the X-Sandstorm-Permissions HTTP header The default access level is add. EDITING, UPLOADING, DOWNLOADING- If you enable the manage capability mentioned above, you'll see a new- "spanner" button to the right of the search form. Clicking this will- let you edit, upload, or download the journal file or any files it in-+ If you enable the manage capability mentioned above, you'll see a new+ "spanner" button to the right of the search form. Clicking this will+ let you edit, upload, or download the journal file or any files it in- cludes. - Note, unlike any other hledger command, in this mode you (or any visi-+ Note, unlike any other hledger command, in this mode you (or any visi- tor) can alter or wipe the data files. - Normally whenever a file is changed in this way, hledger-web saves a- numbered backup (assuming file permissions allow it, the disk is not- full, etc.) hledger-web is not aware of version control systems, cur-- rently; if you use one, you'll have to arrange to commit the changes+ Normally whenever a file is changed in this way, hledger-web saves a+ numbered backup (assuming file permissions allow it, the disk is not+ full, etc.) hledger-web is not aware of version control systems, cur-+ rently; if you use one, you'll have to arrange to commit the changes yourself (eg with a cron job or a file watcher like entr). - Changes which would leave the journal file(s) unparseable or non-valid- (eg with failing balance assertions) are prevented. (Probably. This+ Changes which would leave the journal file(s) unparseable or non-valid+ (eg with failing balance assertions) are prevented. (Probably. This needs re-testing.) RELOADING hledger-web detects changes made to the files by other means (eg if you- edit it directly, outside of hledger-web), and it will show the new- data when you reload the page or navigate to a new page. If a change+ edit it directly, outside of hledger-web), and it will show the new+ data when you reload the page or navigate to a new page. If a change makes a file unparseable, hledger-web will display an error message un- til the file has been fixed. @@ -257,8 +260,8 @@ that both machine clocks are roughly in step.) JSON API- In addition to the web UI, hledger-web also serves a JSON API that can- be used to get data or add new transactions. If you want the JSON API+ In addition to the web UI, hledger-web also serves a JSON API that can+ be used to get data or add new transactions. If you want the JSON API only, you can use the --serve-api flag. Eg: $ hledger-web -f examples/sample.journal --serve-api@@ -275,7 +278,7 @@ /accounttransactions/ACCOUNTNAME Eg, all account names in the journal (similar to the accounts command).- (hledger-web's JSON does not include newlines, here we use python to+ (hledger-web's JSON does not include newlines, here we use python to prettify it): $ curl -s http://127.0.0.1:5000/accountnames | python -m json.tool@@ -316,26 +319,26 @@ "aprice": null, ... - Most of the JSON corresponds to hledger's data types; for details of- what the fields mean, see the Hledger.Data.Json haddock docs and click- on the various data types, eg Transaction. And for a higher level un-+ Most of the JSON corresponds to hledger's data types; for details of+ what the fields mean, see the Hledger.Data.Json haddock docs and click+ on the various data types, eg Transaction. And for a higher level un- derstanding, see the journal docs. There is also a basic OpenAPI spec- ification. In some cases there is outer JSON corresponding to a "Report" type. To- understand that, go to the Hledger.Web.Handler.MiscR haddock and look- at the source for the appropriate handler to see what it returns. Eg+ understand that, go to the Hledger.Web.Handler.MiscR haddock and look+ at the source for the appropriate handler to see what it returns. Eg for /accounttransactions it's getAccounttransactionsR, returning a "ac-- countTransactionsReport ...". Looking up the haddock for that we can- see that /accounttransactions returns an AccountTransactionsReport,- which consists of a report title and a list of AccountTransactionsRe-+ countTransactionsReport ...". Looking up the haddock for that we can+ see that /accounttransactions returns an AccountTransactionsReport,+ which consists of a report title and a list of AccountTransactionsRe- portItem (etc). - You can add a new transaction to the journal with a PUT request to- /add, if hledger-web was started with the add capability (enabled by+ You can add a new transaction to the journal with a PUT request to+ /add, if hledger-web was started with the add capability (enabled by default). The payload must be the full, exact JSON representation of a- hledger transaction (partial data won't do). You can get sample JSON- from hledger-web's /transactions or /accounttransactions, or you can+ hledger transaction (partial data won't do). You can get sample JSON+ from hledger-web's /transactions or /accounttransactions, or you can export it with hledger-lib, eg like so: .../hledger$ stack ghci hledger-lib@@ -431,27 +434,27 @@ "tstatus": "Unmarked" } - And here's how to test adding it with curl. This should add a new en-+ And here's how to test adding it with curl. This should add a new en- try to your journal: $ curl http://127.0.0.1:5000/add -X PUT -H 'Content-Type: application/json' --data-binary @txn.json DEBUG OUTPUT Debug output- You can add --debug[=N] to the command line to log debug output. N+ You can add --debug[=N] to the command line to log debug output. N ranges from 1 (least output, the default) to 9 (maximum output). Typi-- cally you would start with 1 and increase until you are seeing enough.- Debug output goes to stderr, interleaved with the requests logged on+ cally you would start with 1 and increase until you are seeing enough.+ Debug output goes to stderr, interleaved with the requests logged on stdout. To capture debug output in a log file instead, you can usually redirect stderr, eg: hledger-web --debug=3 2>hledger-web.log. ENVIRONMENT- LEDGER_FILE The main journal file to use when not specified with+ LEDGER_FILE The main journal file to use when not specified with -f/--file. Default: $HOME/.hledger.journal. BUGS- We welcome bug reports in the hledger issue tracker+ We welcome bug reports in the hledger issue tracker (https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). @@ -477,4 +480,4 @@ SEE ALSO hledger(1), hledger-ui(1), hledger-web(1), ledger(1) -hledger-web-1.43.2 June 2025 HLEDGER-WEB(1)+hledger-web-1.50 September 2025 HLEDGER-WEB(1)
static/hledger.js view
@@ -58,86 +58,6 @@ }); //-----------------------------------------------------------------------// REGISTER CHART--//eslint-disable-next-line no-unused-vars-function registerChart($container, series) {- // https://github.com/flot/flot/blob/master/API.md- return $container.plot(- series,- { /* general chart options */- xaxis: {- mode: "time",- timeformat: "%Y/%m/%d",- },- selection: {- mode: "x"- },- legend: {- position: 'sw'- },- grid: {- markings: function () {- var now = Date.now();- return [- {- xaxis: { to: now }, // past- yaxis: { to: 0 }, // <0- color: '#ffdddd',- },- {- xaxis: { from: now }, // future- yaxis: { from: 0 }, // >0- color: '#e0e0e0',- },- {- xaxis: { from: now }, // future- yaxis: { to: 0 }, // <0- color: '#e8c8c8',- },- {- yaxis: { from: 0, to: 0 }, // =0- color: '#bb0000',- lineWidth:1- },- ];- },- hoverable: true,- autoHighlight: true,- clickable: true,- },- /* https://github.com/krzysu/flot.tooltip */- tooltip: true,- tooltipOpts: {- xDateFormat: "%Y/%m/%d",- content:- function(label, x, y, flotitem) {- var data = flotitem.series.data[flotitem.dataIndex];- return data[3]+" balance on %x after "+data[2]+" posted by transaction:<pre>"+data[4]+"</pre>";- },- onHover: function(flotitem, $tooltipel) {- $tooltipel.css('border-color',flotitem.series.color);- },- },- }- ).data("plot");-}--function registerChartClick(ev, pos, item) {- if (!item) {- return;- }- var targetselector = '#' + item.series.data[item.dataIndex][5];- var $target = $(targetselector);- if ($target.length) {- window.location.hash = targetselector;- $('html, body').animate({- scrollTop: $target.offset().top- }, 1000);- }-}--//---------------------------------------------------------------------- // ADD FORM function addformShow(showmsg) {
templates/chart.hamlet view
@@ -1,21 +1,22 @@+$# If $ is the first character in a line, it must be \-escaped to hide it from hamlet. <label #register-chart-label style=""><br> <div #register-chart style="height:150px; margin-bottom:1em; display:block;"> <script type=text/javascript>- \$(document).ready(function() {- var $chartdiv = $('#register-chart');- if ($chartdiv.is(':visible')) {- \$('#register-chart-label').text('#{charttitle}');- var seriesData = [+ \$(document).ready(function() {+ var $chartdiv = $('#register-chart');+ if ($chartdiv.is(':visible')) {+ \$('#register-chart-label').text('#{charttitle}');+ var seriesData = [ $forall (c,items) <- percommoditytxnreports- /* we render each commodity using two series:- * one with extra data points added to show a stepped balance line */- {+ // we render each commodity using two series:+ // one with extra data points added to show a stepped balance line+ { data: [ $forall i <- reverse items- [- #{dayToJsTimestamp $ triDate i},+ [+ #{dayToUtcNoonTimestamp $ triDate i}, #{simpleMixedAmountQuantity $ triCommodityBalance c i}- ],+ ], ], label: '#{shownull $ T.unpack c}', color: #{colorForCommodity c},@@ -28,20 +29,19 @@ }, clickable: false, hoverable: false,- },- /* and one with the original data, showing one clickable, hoverable point per transaction */- {+ },+ // and one with the original data, showing one clickable, hoverable point per transaction+ { data: [ $forall i <- reverse items- [- #{dayToJsTimestamp $ triDate i},+ [+ #{dayToUtcNoonTimestamp $ triDate i}, #{simpleMixedAmountQuantity $ triCommodityBalance c i}, '#{showZeroCommodity $ triCommodityAmount c i}', '#{showZeroCommodity $ triCommodityBalance c i}', '#{concat $ intersperse "\\n" $ lines $ T.unpack $ showTransaction $ triOrigTransaction i}', #{tindex $ triOrigTransaction i}- ],- /* [] */+ ], ], label: '', color: #{colorForCommodity c},@@ -51,26 +51,112 @@ points: { show: true, },- },- ]- var plot = registerChart($chartdiv, seriesData);- \$chartdiv.bind("plotclick", registerChartClick);- plot.setSelection({ xaxis: { from: 500, to: 700 } });- \$chartdiv.bind("plotselected", function(event, ranges) {- console.log("selected", ranges.xaxis.from, ranges.xaxis.to);- /* Round down for the 'from' day: */- var from = new Date(ranges.xaxis.from);- /* Round up for the 'to' day: */- var to = new Date(ranges.xaxis.to + (24 * 60 * 60 * 1000) - 1);- var range =- from.getFullYear() + "/" + (from.getMonth() + 1) + "/" + from.getDate() + "-" +- to.getFullYear() + "/" + (to.getMonth() + 1) + "/" + to.getDate();- var baselink = "@?{nodatelink}";- if (baselink.endsWith("?q")) {- document.location = baselink + "=date:" + range;- } else {- document.location = baselink + "%20date:" + range;- }- });- };- });+ },+ ];+ var plot = registerChart($chartdiv, seriesData);+ plot.setSelection({ xaxis: { from: 500, to: 700 } }); // ?+ \$chartdiv.bind("plotclick", registerChartClick);+ \$chartdiv.bind("plotselected", registerChartSelect);+ };+ });++ //eslint-disable-next-line no-unused-vars+ function registerChart($container, series) {+ // https://github.com/flot/flot/blob/master/API.md+ return $container.plot(+ series,+ {+ xaxis: {+ mode: "time",+ timeformat: "%Y/%m/%d",+ },+ selection: {+ mode: "x"+ },+ legend: {+ position: 'sw'+ },+ grid: {+ markings: function () {+ var now = Date.now();+ return [+ {+ xaxis: { to: now }, // past+ yaxis: { to: 0 }, // <0+ color: '#ffdddd',+ },+ {+ xaxis: { from: now }, // future+ yaxis: { from: 0 }, // >0+ color: '#e0e0e0',+ },+ {+ xaxis: { from: now }, // future+ yaxis: { to: 0 }, // <0+ color: '#e8c8c8',+ },+ {+ yaxis: { from: 0, to: 0 }, // =0+ color: '#bb0000',+ lineWidth:1+ },+ ];+ },+ hoverable: true,+ autoHighlight: true,+ clickable: true,+ },+ // https://github.com/krzysu/flot.tooltip+ tooltip: true,+ tooltipOpts: {+ xDateFormat: "%Y/%m/%d",+ content:+ function(label, x, y, flotitem) {+ var data = flotitem.series.data[flotitem.dataIndex];+ return data[3]+" balance on %x after "+data[2]+" posted by transaction:<pre>"+data[4]+"</pre>";+ },+ onHover: function(flotitem, $tooltipel) {+ \$tooltipel.css('border-color',flotitem.series.color);+ },+ },+ }+ ).data("plot");+ }++ // Handle a click event on the chart.+ function registerChartClick(ev, pos, item) {+ if (!item) { return; }+ var targetselector = '#' + item.series.data[item.dataIndex][5];+ var $target = $(targetselector);+ if ($target.length) {+ window.location.hash = targetselector;+ \$('html, body').animate({+ scrollTop: $target.offset().top+ }, 1000);+ }+ }++ // Handle a selection (zoom) event on the chart.+ function registerChartSelect(ev, ranges) {+ console.log("selected", ranges.xaxis.from, ranges.xaxis.to);++ // Reconstruct from/to dates carefully based on the selected x-values.+ // Those x values are unix timestamps (milliseconds since epoch) enclosing the data points' timestamps.+ // Those are generated by dayToJsTimestamp, and are UTC times representing the transaction dates.+ var from = new Date(ranges.xaxis.from);+ var fromy = from.getUTCFullYear();+ var fromm = from.getUTCMonth() + 1;+ var fromd = from.getUTCDate();+ var to = new Date(ranges.xaxis.to + 1 * 24 * 60 * 60 * 1000);+ var toy = to.getUTCFullYear();+ var tom = to.getUTCMonth() + 1;+ var tod = to.getUTCDate();++ var range = fromy + "/" + fromm + "/" + fromd + "-" + toy + "/" + tom + "/" + tod;+ var baselink = "@?{nodatelink}";+ if (baselink.endsWith("?q")) {+ document.location = baselink + "=date:" + range;+ } else {+ document.location = baselink + "%20date:" + range;+ }+ }
templates/register.hamlet view
@@ -1,7 +1,7 @@ <h2> #{header} -<div .hidden-xs>+<div> ^{registerChartHtml qparam balancelabel $ accountTransactionsReportByCommodity items} <div.table-responsive>