web: register chart improvements

- bigger
- plot is horizontal when balance is not changing
- legend for commodities
- some work towards stable commodity colors
This commit is contained in:
Simon Michael 2014-07-17 18:09:02 -07:00
parent 663c68e8e2
commit 4333cae43f
2 changed files with 50 additions and 21 deletions

View File

@ -205,9 +205,9 @@ filterTransactionPostings m t@Transaction{tpostings=ps} = t{tpostings=filter (m
-- | Split a transactions report whose items may involve several commodities, -- | Split a transactions report whose items may involve several commodities,
-- into one or more single-commodity transactions reports. -- into one or more single-commodity transactions reports.
transactionsReportByCommodity :: TransactionsReport -> [TransactionsReport] transactionsReportByCommodity :: TransactionsReport -> [(Commodity, TransactionsReport)]
transactionsReportByCommodity tr = transactionsReportByCommodity tr =
[filterTransactionsReportByCommodity c tr | c <- transactionsReportCommodities tr] [(c, filterTransactionsReportByCommodity c tr) | c <- transactionsReportCommodities tr]
where where
transactionsReportCommodities (_,items) = transactionsReportCommodities (_,items) =
nub $ sort $ map acommodity $ concatMap (amounts . triAmount) items nub $ sort $ map acommodity $ concatMap (amounts . triAmount) items

View File

@ -58,8 +58,8 @@ registerItemsHtml _ vd (balancelabel,items) = [hamlet|
<span .glyphicon .glyphicon-chevron-up> <span .glyphicon .glyphicon-chevron-up>
<th.description style="text-align:left;">Description <th.description style="text-align:left;">Description
<th.account style="text-align:left;">To/From Account(s) <th.account style="text-align:left;">To/From Account(s)
<th.amount style="text-align:right;">Amount Out/In <th.amount style="text-align:right; white-space:normal;">Amount Out/In
<th.balance style="text-align:right;">#{balancelabel'} <th.balance style="text-align:right; white-space:normal;">#{balancelabel'}
$forall i <- numberTransactionsReportItems items $forall i <- numberTransactionsReportItems items
^{itemAsHtml vd i} ^{itemAsHtml vd i}
|] |]
@ -96,40 +96,69 @@ registerItemsHtml _ vd (balancelabel,items) = [hamlet|
-- Data.Foldable.Foldable t1 => -- Data.Foldable.Foldable t1 =>
-- t1 (Transaction, t2, t3, t4, t5, MixedAmount) -- t1 (Transaction, t2, t3, t4, t5, MixedAmount)
-- -> t -> Text.Blaze.Internal.HtmlM () -- -> t -> Text.Blaze.Internal.HtmlM ()
registerChartHtml :: [(String, [TransactionsReportItem])] -> HtmlUrl AppRoute registerChartHtml :: [(Commodity, (String, [TransactionsReportItem]))] -> HtmlUrl AppRoute
registerChartHtml percommoditytxnreports = registerChartHtml percommoditytxnreports =
-- have to make sure plot is not called when our container (maincontent) -- have to make sure plot is not called when our container (maincontent)
-- is hidden, eg with add form toggled -- is hidden, eg with add form toggled
[hamlet| [hamlet|
<label#register-chart-label style="float:left;margin-right:1em;"> <label#register-chart-label style=""><br>
<div#register-chart style="width:600px;height:100px; margin-bottom:1em;float:left;"> <div#register-chart style="width:85%; height:150px; margin-bottom:1em; display:block;">
<script type=text/javascript> <script type=text/javascript>
\$(document).ready(function() { \$(document).ready(function() {
/* render chart with flot, if visible */ /* render chart with flot, if visible */
var chartdiv = $('#register-chart'); var chartdiv = $('#register-chart');
if (chartdiv.is(':visible')) if (chartdiv.is(':visible')) {
\$('#register-chart-label').text('#{label}'); \$('#register-chart-label').text('#{charttitle}');
/* https://github.com/flot/flot/blob/master/API.md */
\$.plot(chartdiv, \$.plot(chartdiv,
[ [
$forall (_,items) <- percommoditytxnreports $forall (comm,(_,items)) <- percommoditytxnreports
[ {
$forall i <- reverse items label: '#{comm}',
[#{dayToJsTimestamp $ triDate i}, #{triSimpleBalance i}], color: #{colorForCommodity comm},
[] data: [
], $forall i <- reverse items
[] [#{dayToJsTimestamp $ triDate i}, #{triSimpleBalance i}],
[] ],
},
], ],
{ {
xaxis: { series: {
mode: "time", points: {
timeformat: "%y/%m/%d" show: false,
} },
lines: {
show: true,
steps: true,
},
bars: {
show: false,
barWidth: 10,
},
},
yaxis: {
/* mode: "time", */
/* timeformat: "%y/%m/%d", */
/* ticks: 6, */
},
xaxis: {
mode: "time",
timeformat: "%Y/%m/%d"
/* ticks: 6, */
},
} }
); );
}
}); });
//clickable: true,
//hoverable: true,
//minTickSize: 3,
//var plot = $("#placeholder").plot(data, options).data("plot");
|] |]
where where
label = case maybe "" fst $ headMay percommoditytxnreports charttitle = case maybe "" (fst.snd) $ headMay percommoditytxnreports
of "" -> "" of "" -> ""
s -> s++":" s -> s++":"
colorForCommodity = fromMaybe 0 . flip lookup commoditiesIndex
commoditiesIndex = zip (map fst percommoditytxnreports) [0..] :: [(Commodity,Int)]