diff --git a/hledger-web/Hledger/Web/Foundation.hs b/hledger-web/Hledger/Web/Foundation.hs index 93ce3bc20..577bfa557 100644 --- a/hledger-web/Hledger/Web/Foundation.hs +++ b/hledger-web/Hledger/Web/Foundation.hs @@ -160,6 +160,7 @@ instance Yesod App where addScript $ StaticR js_jquery_cookie_js addScript $ StaticR js_jquery_hotkeys_js addScript $ StaticR js_jquery_flot_min_js + addScript $ StaticR js_jquery_flot_selection_min_js addScript $ StaticR js_jquery_flot_time_min_js addScript $ StaticR js_jquery_flot_tooltip_min_js toWidget [hamlet| \ |] diff --git a/hledger-web/Hledger/Web/Handler/RegisterR.hs b/hledger-web/Hledger/Web/Handler/RegisterR.hs index b8daf19e4..192ed96cb 100644 --- a/hledger-web/Hledger/Web/Handler/RegisterR.hs +++ b/hledger-web/Hledger/Web/Handler/RegisterR.hs @@ -19,7 +19,7 @@ import Hledger.Web.WebOptions import Hledger.Web.Widget.AddForm (addModal) import Hledger.Web.Widget.Common (accountQuery, mixedAmountAsHtml, - transactionFragment, removeInacct, replaceInacct) + transactionFragment, removeDates, removeInacct, replaceInacct) -- | The main journal/account register view, with accounts sidebar. getRegisterR :: Handler Html @@ -99,8 +99,8 @@ decorateLinks = -- | Generate javascript/html for a register balance line chart based on -- the provided "TransactionsReportItem"s. -registerChartHtml :: String -> [(CommoditySymbol, [TransactionsReportItem])] -> HtmlUrl AppRoute -registerChartHtml title percommoditytxnreports = $(hamletFile "templates/chart.hamlet") +registerChartHtml :: Text -> String -> [(CommoditySymbol, [TransactionsReportItem])] -> HtmlUrl AppRoute +registerChartHtml q title percommoditytxnreports = $(hamletFile "templates/chart.hamlet") -- have to make sure plot is not called when our container (maincontent) -- is hidden, eg with add form toggled where @@ -109,6 +109,7 @@ registerChartHtml title percommoditytxnreports = $(hamletFile "templates/chart.h commoditiesIndex = zip (map fst percommoditytxnreports) [0..] :: [(CommoditySymbol,Int)] simpleMixedAmountQuantity = maybe 0 aquantity . listToMaybe . amounts shownull c = if null c then " " else c + nodatelink = (RegisterR, [("q", T.unwords $ removeDates q)]) dayToJsTimestamp :: Day -> Integer dayToJsTimestamp d = diff --git a/hledger-web/Hledger/Web/Widget/Common.hs b/hledger-web/Hledger/Web/Widget/Common.hs index 34ecff747..8b28994bf 100644 --- a/hledger-web/Hledger/Web/Widget/Common.hs +++ b/hledger-web/Hledger/Web/Widget/Common.hs @@ -15,6 +15,7 @@ module Hledger.Web.Widget.Common , writeJournalTextIfValidAndChanged , journalFile404 , transactionFragment + , removeDates , removeInacct , replaceInacct ) where @@ -120,6 +121,13 @@ transactionFragment j Transaction{tindex, tsourcepos} = -- or 0 if this txn has no known file (eg a forecasted txn) tfileindex = maybe 0 (+1) $ elemIndex (sourceFilePath tsourcepos) (journalFilePaths j) +removeDates :: Text -> [Text] +removeDates = + map quoteIfSpaced . + filter (\term -> + not $ T.isPrefixOf "date:" term || T.isPrefixOf "date2:" term) . + Query.words'' Query.prefixes + removeInacct :: Text -> [Text] removeInacct = map quoteIfSpaced . diff --git a/hledger-web/static/hledger.js b/hledger-web/static/hledger.js index bb4686854..824de62bb 100644 --- a/hledger-web/static/hledger.js +++ b/hledger-web/static/hledger.js @@ -58,7 +58,10 @@ function registerChart($container, series) { { /* general chart options */ xaxis: { mode: "time", - timeformat: "%Y/%m/%d" + timeformat: "%Y/%m/%d", + }, + selection: { + mode: "x" }, legend: { position: 'sw' diff --git a/hledger-web/templates/chart.hamlet b/hledger-web/templates/chart.hamlet index 99993ab2b..921c5766c 100644 --- a/hledger-web/templates/chart.hamlet +++ b/hledger-web/templates/chart.hamlet @@ -55,5 +55,20 @@ ] 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); + var from = new Date(ranges.xaxis.from); + var to = new Date(ranges.xaxis.to); + 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; + } + }); }; }); diff --git a/hledger-web/templates/register.hamlet b/hledger-web/templates/register.hamlet index 1656bc3e2..fbdc6f0b6 100644 --- a/hledger-web/templates/register.hamlet +++ b/hledger-web/templates/register.hamlet @@ -2,7 +2,7 @@ #{header}
- ^{registerChartHtml balancelabel $ transactionsReportByCommodity items} + ^{registerChartHtml q balancelabel $ transactionsReportByCommodity items}