Allow selecting the date range from the chart
By dragging a region with the mouse
This commit is contained in:
parent
9cff45b2c5
commit
fe6e9a79fe
@ -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| \<!--[if lte IE 8]> <script type="text/javascript" src="@{StaticR js_excanvas_min_js}"></script> <![endif]--> |]
|
||||
|
||||
@ -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 =
|
||||
|
||||
@ -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 .
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
#{header}
|
||||
|
||||
<div .hidden-xs>
|
||||
^{registerChartHtml balancelabel $ transactionsReportByCommodity items}
|
||||
^{registerChartHtml q balancelabel $ transactionsReportByCommodity items}
|
||||
|
||||
<div.table-responsive>
|
||||
<table .table.table-striped.table-condensed>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user