| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hledger.Write.Chart.Svg
Description
Draw a Chart as SVG, a self-contained graphical file viewable in web browsers and many image viewers.
Charts over time (periods or dates) are drawn with time along the x axis:
bar series as vertical bars (stacked, with a 2px gap between segments), line series as 2px lines,
and totals as ink-coloured line marks across each period's bars, or as an ink-coloured line.
Charts of categories (eg the accounts of a single-period report) are drawn as horizontal bars,
with labels on the left and an aligned value column on the right.
There is one panel per commodity, one above the other, and a legend listing the series (see legendListsSeries), and any average line.
Each mark has a tooltip (an SVG title) giving its x label, series and value,
and for an "other" series, the accounts it combines, one per line.
The SVG includes its own styles, with a colour-blind-safe palette and a dark-mode variant (used when the viewer prefers a dark colour scheme). Text widths are estimated, since fonts are not known. Coordinates are rounded to one decimal place, so the output is deterministic.
A page embedding a chart can draw it with SvgOptions, eg without its styles, which the page then supplies
(chartStylesheet).
Synopsis
- chartAsSvg :: Chart -> Text
- chartAsSvgWith :: Bool -> Chart -> Text
- chartSvgMarkup :: Bool -> Chart -> Svg
- data SvgOptions = SvgOptions {
- svgStyles :: Bool
- svgDark :: Bool
- svgWidth :: Double
- svgPlotHeight :: Double
- svgPointLink :: Int -> Maybe Text
- svgDateScale :: Bool
- svgToday :: Maybe Day
- svgIds :: Text
- defaultSvgOptions :: SvgOptions
- chartSvgMarkupWith :: SvgOptions -> Chart -> Svg
- chartPanelsSvgMarkupWith :: SvgOptions -> Chart -> [Svg]
- chartStylesheet :: Bool -> Text
- tests_Hledger_Write_Chart_Svg :: TestTree
Documentation
chartAsSvg :: Chart -> Text Source #
Render a chart as a complete SVG document, with a dark variant for viewers preferring a dark colour scheme.
chartAsSvgWith :: Bool -> Chart -> Text Source #
Render a chart as SVG, with or without the dark variant (eg without, when embedding it in a page that is always light). It has one element per line, for readability.
chartSvgMarkup :: Bool -> Chart -> Svg Source #
A chart as SVG markup, which can also be embedded in HTML; with or without the dark variant.
data SvgOptions Source #
How to draw a chart as SVG.
Constructors
| SvgOptions | |
Fields
| |
defaultSvgOptions :: SvgOptions Source #
A self-contained chart: with its styles, including their dark variant, 880px wide, plots 260px high, no links, no date scale, and no shading.
chartSvgMarkupWith :: SvgOptions -> Chart -> Svg Source #
A chart as SVG markup, which can also be embedded in HTML, drawn with these options.
chartPanelsSvgMarkupWith :: SvgOptions -> Chart -> [Svg] Source #
Each of a chart's panels as a chart of its own, in SVG markup drawn with these options,
coloured as in the whole chart; eg for a page to show one commodity's panel at a time.
Each has its own ids (see svgIds), the given prefix numbered.
chartStylesheet :: Bool -> Text Source #
The chart's styles: a colour-blind-safe categorical palette (8 slots) and chart chrome colours,
with a dark variant used when the viewer prefers a dark colour scheme.
Colours are written literally in each rule (rather than as CSS custom properties),
since some SVG renderers (eg librsvg, used by many image viewers) don't support those.
Charts include these styles, unless drawn without them for a page that supplies them (see SvgOptions).