From 6ef0f22c285e3695de6f98276b2b7a2990141cae Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Tue, 19 Jan 2021 20:20:52 +0100 Subject: [PATCH] Actually populate the pie chart Co-Authored-By: Tom Sydney Kerckhove --- hledger-web/Hledger/Web/Handler/RegisterR.hs | 21 +++++++++++++----- hledger-web/templates/piechart.hamlet | 23 +++++++++++++++++--- hledger-web/templates/register.hamlet | 2 +- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/hledger-web/Hledger/Web/Handler/RegisterR.hs b/hledger-web/Hledger/Web/Handler/RegisterR.hs index d61f75a20a5..187a760b055 100644 --- a/hledger-web/Hledger/Web/Handler/RegisterR.hs +++ b/hledger-web/Hledger/Web/Handler/RegisterR.hs @@ -8,7 +8,7 @@ module Hledger.Web.Handler.RegisterR where -import Data.List (intersperse, nub, partition) +import Data.List (intersperse, nub, partition, sortOn) import qualified Data.Text as T import Text.Hamlet (hamletFile) @@ -50,6 +50,12 @@ getRegisterR = do | isJust (inAccount qopts) = "Period Total" | otherwise = "Total" transactionFrag = transactionFragment j + (chartQuery, depth) = + case (,) <$> inAccount qopts <*> inAccountQuery qopts of + Nothing -> (Any, 0) + Just ((an, _), aq) -> (aq, accountNameLevel an) + rspecWithQuery = rspec { rsQuery = (And [chartQuery, Depth $ depth + 1, m]) } + balancereport = balanceReport rspecWithQuery j defaultLayout $ do setTitle "register - hledger-web" $(widgetFile "register") @@ -111,10 +117,15 @@ registerChartHtml title percommoditytxnreports = $(hamletFile "templates/chart.h shownull c = if null c then " " else c -- | Generate javascript/html for a mockup pie chart -registerPieChartHtml :: HtmlUrl AppRoute -registerPieChartHtml title = $(hamletFile "templates/piechart.hamlet") - where - charttitle = "Pie Chart" :: String +registerPieChartHtml :: BalanceReport -> HtmlUrl AppRoute +registerPieChartHtml (items, _) = $(hamletFile "templates/piechart.hamlet") + where + charttitle = "Pie Chart" :: String + labelDataTuples = + reverse $ + sortOn snd $ + flip concatMap items $ \(accname, _, _, Mixed as) -> + flip map as $ \a -> (accname, aquantity a) dayToJsTimestamp :: Day -> Integer dayToJsTimestamp d = diff --git a/hledger-web/templates/piechart.hamlet b/hledger-web/templates/piechart.hamlet index d15d5c73670..23c621b9813 100644 --- a/hledger-web/templates/piechart.hamlet +++ b/hledger-web/templates/piechart.hamlet @@ -1,5 +1,6 @@