Skip to content

Commit

Permalink
Make pie slices clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
raboof committed Jan 26, 2021
1 parent c9d25a8 commit 0680436
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions hledger-web/Hledger/Web/Handler/RegisterR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ registerChartHtml title percommoditytxnreports = $(hamletFile "templates/chart.h
shownull c = if null c then " " else c

-- | Generate javascript/html for a mockup pie chart
registerPieChartHtml :: BalanceReport -> HtmlUrl AppRoute
registerPieChartHtml (items, _) = $(hamletFile "templates/piechart.hamlet")
registerPieChartHtml :: Text -> BalanceReport -> HtmlUrl AppRoute
registerPieChartHtml q (items, _) = $(hamletFile "templates/piechart.hamlet")
where
charttitle = "Pie Chart" :: String
labelDataTuples =
Expand All @@ -127,6 +127,7 @@ registerPieChartHtml (items, _) = $(hamletFile "templates/piechart.hamlet")
flip concatMap items $ \(accname, _, _, Mixed as) ->
flip map as $ \a -> (accname, aquantity a)
showChart = if ((length labelDataTuples) > 1) then "true" else "false" :: String
noacctlink = (RegisterR, [("q", T.unwords $ removeInacct q)])

dayToJsTimestamp :: Day -> Integer
dayToJsTimestamp d =
Expand Down
14 changes: 13 additions & 1 deletion hledger-web/templates/piechart.hamlet
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
}
},
grid: {
hoverable: true
hoverable: true,
clickable: true
},
legend: {
show: true,
Expand All @@ -37,5 +38,16 @@
var percent = parseFloat(obj.series.percent).toFixed(2);
\$("#piehover").html("<span style='font-weight:bold; color:" + obj.series.color + "'>" + obj.series.label + " (" + percent + "%)</span>");
});
\$chartdiv.bind("plotclick", function(event, pos, obj) {
if (!obj) {
return;
}
var baselink = "@?{noacctlink}";
if (baselink.endsWith("?q")) {
document.location = baselink + "=inacct:%22" + obj.series.label + "%22";
} else {
document.location = baselink + "%20inacct:%22" + obj.series.label + "%22";
}
});
}
});
2 changes: 1 addition & 1 deletion hledger-web/templates/register.hamlet
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div .hidden-xs>
^{registerChartHtml balancelabel $ transactionsReportByCommodity items}
^{registerPieChartHtml balancereport }
^{registerPieChartHtml q balancereport }

<div.table-responsive>
<table .table.table-striped.table-condensed>
Expand Down

0 comments on commit 0680436

Please sign in to comment.