hledger
Safe HaskellNone
LanguageGHC2021

Hledger.Cli.Chart

Description

Turning reports into charts (Hledger.Write.Chart), and the --chart option.

Each adapter here chooses a useful default chart for its report, so that charts just work without configuration (see doc/SPEC-charts.md, "Smart defaults").

Synopsis

Documentation

chartFlag :: Flag RawOpts Source #

The --chart[=net,SCALE] option, for commands that can show a chart. It also accepts a KIND, like compoundChartFlag, but it is ignored, so not mentioned.

balanceChartFlag :: Flag RawOpts Source #

The --chart[=KIND,net,SCALE] option, for the balance command, whose charts can group accounts by type.

compoundChartFlag :: Flag RawOpts Source #

The --chart[=KIND,net,SCALE] option, for compound balance commands, whose sections a chart can arrange.

chartWidthFlag :: Flag RawOpts Source #

The --width option, for commands that can show a chart.

data ChartArg Source #

What --chart's value says: a chart kind, whether to draw the total or net, and scale amounts.

Constructors

ChartArg 

Fields

parseChartArg :: Map CommoditySymbol AmountStyle -> String -> Either String ChartArg Source #

Parse the value of --chart: comma-separated parts, which are optional words (an optional chart kind, default auto, and net, in any order), followed by optional scale amounts (see setChartScales), read with these commodity styles (so that eg 10.000 EUR is ten thousand when EUR is written with a decimal comma). Since commas separate the parts, a comma between digits (a decimal comma, or a digit group mark) is an error.

chartArg :: Map CommoditySymbol AmountStyle -> CliOpts -> ChartArg Source #

What --chart's value says, reading its amounts with these commodity styles (by default, an auto chart).

chartArgFor :: CliOpts -> Chart -> ChartArg Source #

What --chart's value says for this chart, reading its amounts with the chart's commodity styles.

chartRequested :: CliOpts -> Bool Source #

Was a chart requested, with --chart or an output format that can only show charts (svg) ?

chartAsTextForOpts :: CliOpts -> Chart -> IO Text Source #

Draw a chart as text, as the command line options say: --width characters wide or the terminal width, with colour if enabled (exact 24-bit colours, like SVG charts', if the terminal advertises support for them, otherwise the terminal's basic colours), and with unicode block characters if the system's text encoding is UTF-8 (otherwise ASCII). Also warns if the chart has many panels (one per commodity).

writeChart :: CliOpts -> Maybe Text -> Chart -> IO () Source #

Write a chart in the output format and to the destination selected by the command line options: as text (txt), as an SVG image (svg), as the chart's data (csv, tsv, json), or as an SVG image above the report's html, collapsed, if that is provided (html). Other formats give an error (before the chart is computed).

multiBalanceReportAsChart :: (AccountName -> Maybe AccountType) -> ReportOpts -> Text -> MultiBalanceReport -> Chart Source #

Chart a multi-period balance report.

Period changes (flows) are drawn as stacked bars, end balances (stocks, with --cumulative or --historical) as lines; either way, the total is a line. There is one panel per commodity, most-used commodity first. In tree mode, each account's own amounts are charted, excluding its displayed subaccounts', so nothing is counted twice. The total is omitted with -N, with --percent (where it is always 100), and when there is only one series. Each series' group is its main account type (assets, liabilities, equity, revenues, expenses; then accounts of no known type), so that the grouped layout (--chart=grouped) draws a bar per type, side by side, with the amounts' own signs.

balanceReportAsChart :: (AccountName -> Maybe AccountType) -> ReportOpts -> Text -> BalanceReport -> Chart Source #

Chart a single-period balance report, as one bar per account (horizontal, since the accounts are categories). There is one panel per commodity, most-used commodity first; accounts with no amount in a panel's commodity have no value (a gap) there. Unlike stacked charts, all rows are shown, with the report's indentation in tree mode. The total, which belongs to no row (so is not drawn, even with --chart=net), is shown below the chart, as in the table; not with -N or --percent.

compoundBalanceReportAsChart :: (AccountName -> Maybe AccountType) -> [Maybe AccountType] -> ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount -> Chart Source #

Chart a compound balance report (balancesheet, incomestatement, cashflow..): its sections' accounts, and the net total.

Amounts are shown as their contribution to the net total: positive for sections that add to it (eg revenues, assets), negative for sections that subtract from it (eg expenses, liabilities). (The report's tables show both as positive.) So bars above zero increase the net and bars below zero reduce it; eg a refund, which is a negative expense, is drawn above zero. At each period, all sections' accounts are stacked in one diverging bar, positive amounts above zero and negative ones below (the diverging layout, the default); or with --chart=grouped, each section's accounts are stacked in a bar of their own, side by side. See setChartLayout, which also re-signs the data for the grouped layout. Each series has its section (as its group) and the section's usual sign, so that renderers can show contra amounts (eg a refund) distinctly. The net total is a line, for changes (eg incomestatement) as well as end balances (eg balancesheet), so that all charts show their totals the same way. A single-period report is drawn the same way, with one period. With -1 (depth 1), each section is a single bar. There is one panel per commodity, most-used commodity first. Each section has at most maxSectionSeries series, the smallest accounts being combined into an "other" series. In tree mode, each account's own amounts are charted. The net total is omitted with -N and with --percent.

The second argument gives each section's account type, if known (eg from the report's query for it); accounts with no type of their own get their section's, for colouring. An account shown as "..." (eg with depth 0) is labelled with its section's title.

accountTransactionsReportAsChart :: (AccountName -> Maybe AccountType) -> Text -> AccountName -> (Transaction -> Day) -> AccountTransactionsReport -> Chart Source #

Chart an account register (aregister): the balance after each transaction (or the running total or average, as the report shows), as a line over time. The arguments are the title, the account's name, and a function giving a transaction's date in the register. There is one panel per commodity, most-used commodity first.

postingsReportAsChart :: (AccountName -> Maybe AccountType) -> Map AccountName MixedAmount -> ReportOpts -> Text -> PostingsReport -> Chart Source #

Chart a postings report (register). With a report interval, each account's amount in each period is drawn as stacked bars, with the period's total as a line (like a multi-period balance report; at most maxSeries series, the smallest combined into "other"). Otherwise, the running total (or average) after each posting is drawn as a line over time; and with postings to several accounts (and not --average), each account's own running total (from the report start) is drawn too, in its account type's colour, with the overall running total in ink. There is one panel per commodity, most-used commodity first.

The second argument gives the accounts' balances before the report period, if the running total includes them (with --historical; see postingsReportStartBalances), so that each account's running total starts from its balance.

unitAmount :: CommoditySymbol -> [Amount] -> Amount Source #

A unit for values in this commodity: an amount of it from the list (for its display style), with zero quantity and no cost.