chart-svg-0.6.0.0: Charting library targetting SVGs.
Safe HaskellSafe-Inferred
LanguageGHC2021

Chart.Markup

Description

Conversion between ChartOptions and Markup representations.

Synopsis

Documentation

newtype Markup #

A list of Elements or Tree Tokens

>>> markup Html "<foo class=\"bar\">baz</foo>"
That (Markup {elements = [Node {rootLabel = OpenTag StartTag "foo" [Attr {attrName = "class", attrValue = "bar"}], subForest = [Node {rootLabel = Content "baz", subForest = []}]}]})

Constructors

Markup 

Fields

Instances

Instances details
Monoid Markup 
Instance details

Defined in MarkupParse

Semigroup Markup 
Instance details

Defined in MarkupParse

Generic Markup 
Instance details

Defined in MarkupParse

Associated Types

type Rep Markup :: Type -> Type #

Methods

from :: Markup -> Rep Markup x #

to :: Rep Markup x -> Markup #

Show Markup 
Instance details

Defined in MarkupParse

NFData Markup 
Instance details

Defined in MarkupParse

Methods

rnf :: Markup -> () #

Eq Markup 
Instance details

Defined in MarkupParse

Methods

(==) :: Markup -> Markup -> Bool #

(/=) :: Markup -> Markup -> Bool #

Ord Markup 
Instance details

Defined in MarkupParse

ToExpr Markup 
Instance details

Defined in MarkupParse

Methods

toExpr :: Markup -> Expr #

listToExpr :: [Markup] -> Expr #

type Rep Markup 
Instance details

Defined in MarkupParse

type Rep Markup = D1 ('MetaData "Markup" "MarkupParse" "markup-parse-0.1.1-Ux2cyiaJyB5WjBazMvHjb" 'True) (C1 ('MetaCons "Markup" 'PrefixI 'True) (S1 ('MetaSel ('Just "elements") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Element])))

data ChartOptions Source #

A product type consisting of a ChartTree, HudOptions and MarkupOptions, which is what you need to create Markup.

Instances

Instances details
Monoid ChartOptions Source # 
Instance details

Defined in Chart.Markup

Semigroup ChartOptions Source # 
Instance details

Defined in Chart.Markup

Generic ChartOptions Source # 
Instance details

Defined in Chart.Markup

Associated Types

type Rep ChartOptions :: Type -> Type #

Show ChartOptions Source # 
Instance details

Defined in Chart.Markup

Eq ChartOptions Source # 
Instance details

Defined in Chart.Markup

type Rep ChartOptions Source # 
Instance details

Defined in Chart.Markup

type Rep ChartOptions = D1 ('MetaData "ChartOptions" "Chart.Markup" "chart-svg-0.6.0.0-HjsGv1l8hv76XDZORokPY6" 'False) (C1 ('MetaCons "ChartOptions" 'PrefixI 'True) (S1 ('MetaSel ('Just "markupOptions") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MarkupOptions) :*: (S1 ('MetaSel ('Just "hudOptions") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HudOptions) :*: S1 ('MetaSel ('Just "chartTree") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ChartTree))))

forgetHud :: ChartOptions -> ChartOptions Source #

Processes the hud options and turns them into charts, rescales the existing charts, resets the hud options to mempty, and turns on ScalePArea in chart styles.

Note that this is a destructive operation, and, in particular, that

view #chartTree (forgetHud (mempty & set #chartTree c)) /= c

markupChartOptions :: ChartOptions -> Markup Source #

Convert ChartOptions to Markup

>>> markupChartOptions (ChartOptions (defaultMarkupOptions & #cssOptions % #preferColorScheme .~ PreferNormal) mempty mempty) & markdown_ Compact Xml
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\" viewBox=\"-0.5 -0.5 1.0 1.0\"><style>\nsvg { font-family: system-ui,-apple-system,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,\"Noto Sans\",\"Liberation Sans\",sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\";\n}\n\nticktext { font-family: SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace;\n}\n\n</style><g class=\"chart\"></g><g class=\"hud\"></g></svg>"

markupChartTree :: ChartTree -> Markup Source #

Convert a ChartTree to markup

>>> lineExample & view #chartTree & markupChartTree & markdown_ Compact Xml
"<g class=\"line\"><g stroke-width=\"0.0150\" stroke=\"rgb(2%, 73%, 80%)\" stroke-opacity=\"1.0\" fill=\"none\"><polyline points=\"0,-1.0 1.0,-1.0 2.0,-5.0\"/></g><g stroke-width=\"0.0150\" stroke=\"rgb(2%, 29%, 48%)\" stroke-opacity=\"1.0\" fill=\"none\"><polyline points=\"0,0 2.8,-3.0\"/></g><g stroke-width=\"0.0150\" stroke=\"rgb(66%, 7%, 55%)\" stroke-opacity=\"1.0\" fill=\"none\"><polyline points=\"0.5,-4.0 0.5,0\"/></g></g>"

markupChart :: Chart -> Markup Source #

Convert a Chart to Markup

>>> import MarkupParse
>>> import Optics.Core
>>> import Control.Category ((>>>))
>>> lineExample & toListOf (#chartTree % charts') & mconcat & fmap (markupChart >>> markdown_ Compact Xml)
["<g stroke-width=\"0.0150\" stroke=\"rgb(2%, 73%, 80%)\" stroke-opacity=\"1.0\" fill=\"none\"><polyline points=\"0,-1.0 1.0,-1.0 2.0,-5.0\"/></g>","<g stroke-width=\"0.0150\" stroke=\"rgb(2%, 29%, 48%)\" stroke-opacity=\"1.0\" fill=\"none\"><polyline points=\"0,0 2.8,-3.0\"/></g>","<g stroke-width=\"0.0150\" stroke=\"rgb(66%, 7%, 55%)\" stroke-opacity=\"1.0\" fill=\"none\"><polyline points=\"0.5,-4.0 0.5,0\"/></g>"]

header :: Maybe Double -> Rect Double -> Markup -> Markup Source #

Create the classic SVG element

>>> header (Just 300) (Rect (-0.75) 0.75 (-0.5) 0.5) (element_ "foo" []) & markdown_ Compact Xml
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"450\" height=\"300\" viewBox=\"-0.75 -0.5 1.5 1.0\"><foo></foo></svg>"

renderChartOptions :: ChartOptions -> Text Source #

Render ChartOptions to an SVG Text snippet

>>> renderChartOptions (ChartOptions (defaultMarkupOptions & #cssOptions % #preferColorScheme .~ PreferNormal) mempty mempty)
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\" viewBox=\"-0.5 -0.5 1.0 1.0\"><style>\nsvg { font-family: system-ui,-apple-system,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,\"Noto Sans\",\"Liberation Sans\",sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\";\n}\n\nticktext { font-family: SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace;\n}\n\n</style><g class=\"chart\"></g><g class=\"hud\"></g></svg>"

encodeChartOptions :: ChartOptions -> ByteString Source #

Render ChartOptions to an SVG ByteString

>>> encodeChartOptions (ChartOptions (defaultMarkupOptions & #cssOptions % #preferColorScheme .~ PreferNormal) mempty mempty)
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\" viewBox=\"-0.5 -0.5 1.0 1.0\"><style>\nsvg { font-family: system-ui,-apple-system,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,\"Noto Sans\",\"Liberation Sans\",sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\";\n}\n\nticktext { font-family: SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace;\n}\n\n</style><g class=\"chart\"></g><g class=\"hud\"></g></svg>"

writeChartOptions :: FilePath -> ChartOptions -> IO () Source #

Convert ChartOptions to an SVG ByteString and save to a file

data CssOptions Source #

css options

>>> defaultCssOptions
CssOptions {shapeRendering = NoShapeRendering, preferColorScheme = PreferHud, fontFamilies = "\nsvg { font-family: system-ui,-apple-system,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,\"Noto Sans\",\"Liberation Sans\",sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\";\n}\n\nticktext { font-family: SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace;\n}\n\n", cssExtra = ""}

Instances

Instances details
Generic CssOptions Source # 
Instance details

Defined in Chart.Markup

Associated Types

type Rep CssOptions :: Type -> Type #

Show CssOptions Source # 
Instance details

Defined in Chart.Markup

Eq CssOptions Source # 
Instance details

Defined in Chart.Markup

type Rep CssOptions Source # 
Instance details

Defined in Chart.Markup

type Rep CssOptions = D1 ('MetaData "CssOptions" "Chart.Markup" "chart-svg-0.6.0.0-HjsGv1l8hv76XDZORokPY6" 'False) (C1 ('MetaCons "CssOptions" 'PrefixI 'True) ((S1 ('MetaSel ('Just "shapeRendering") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ShapeRendering) :*: S1 ('MetaSel ('Just "preferColorScheme") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PreferColorScheme)) :*: (S1 ('MetaSel ('Just "fontFamilies") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "cssExtra") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))))

defaultCssOptions :: CssOptions Source #

No special shape rendering and default hud responds to user color scheme preferences.

data PreferColorScheme Source #

CSS prefer-color-scheme options

Constructors

PreferHud

includes css that switches approriate hud elements between light and dark.

PreferDark 
PreferLight 
PreferNormal 

Instances

Instances details
Generic PreferColorScheme Source # 
Instance details

Defined in Chart.Markup

Associated Types

type Rep PreferColorScheme :: Type -> Type #

Show PreferColorScheme Source # 
Instance details

Defined in Chart.Markup

Eq PreferColorScheme Source # 
Instance details

Defined in Chart.Markup

type Rep PreferColorScheme Source # 
Instance details

Defined in Chart.Markup

type Rep PreferColorScheme = D1 ('MetaData "PreferColorScheme" "Chart.Markup" "chart-svg-0.6.0.0-HjsGv1l8hv76XDZORokPY6" 'False) ((C1 ('MetaCons "PreferHud" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PreferDark" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "PreferLight" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PreferNormal" 'PrefixI 'False) (U1 :: Type -> Type)))

cssPreferColorScheme :: (Colour, Colour) -> PreferColorScheme -> ByteString Source #

CSS prefer-color-scheme text snippet

>>> cssPreferColorScheme (light, dark) PreferHud
"svg {\n  color-scheme: light dark;\n}\n{\n  .canvas g, .title g, .axisbar g, .ticktext g, .tickglyph g, .ticklines g, .legendContent g text {\n    fill: rgb(5%, 5%, 5%);\n  }\n  .ticklines g, .tickglyph g, .legendBorder g {\n    stroke: rgb(5%, 5%, 5%);\n  }\n  .legendBorder g {\n    fill: rgb(94%, 94%, 94%);\n  }\n}\n@media (prefers-color-scheme:dark) {\n  .canvas g, .title g, .axisbar g, .ticktext g, .tickglyph g, .ticklines g, .legendContent g text {\n    fill: rgb(94%, 94%, 94%);\n  }\n  .ticklines g, .tickglyph g, .legendBorder g {\n    stroke: rgb(94%, 94%, 94%);\n  }\n  .legendBorder g {\n    fill: rgb(5%, 5%, 5%);\n  }\n}"

fillSwitch :: (Colour, Colour) -> ByteString -> ByteString -> ByteString Source #

CSS snippet to switch between dark and light mode

fillSwitch (color1, color2) "dark" "stuff"

... will default to color1 for elements of the "stuff" class, but switch to color2 if "dark" mode is preferred by the user.

data ShapeRendering Source #

CSS glyphShape rendering options

Instances

Instances details
Generic ShapeRendering Source # 
Instance details

Defined in Chart.Markup

Associated Types

type Rep ShapeRendering :: Type -> Type #

Show ShapeRendering Source # 
Instance details

Defined in Chart.Markup

Eq ShapeRendering Source # 
Instance details

Defined in Chart.Markup

type Rep ShapeRendering Source # 
Instance details

Defined in Chart.Markup

type Rep ShapeRendering = D1 ('MetaData "ShapeRendering" "Chart.Markup" "chart-svg-0.6.0.0-HjsGv1l8hv76XDZORokPY6" 'False) (C1 ('MetaCons "UseGeometricPrecision" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "UseCssCrisp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NoShapeRendering" 'PrefixI 'False) (U1 :: Type -> Type)))

markupCssOptions :: CssOptions -> Markup Source #

Convert CssOptions to Markup

data MarkupOptions Source #

Markup options.

>>> defaultMarkupOptions
MarkupOptions {markupHeight = Just 300.0, chartAspect = FixedAspect 1.5, cssOptions = CssOptions {shapeRendering = NoShapeRendering, preferColorScheme = PreferHud, fontFamilies = "\nsvg { font-family: system-ui,-apple-system,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,\"Noto Sans\",\"Liberation Sans\",sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\";\n}\n\nticktext { font-family: SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace;\n}\n\n", cssExtra = ""}, renderStyle = Compact}

Instances

Instances details
Generic MarkupOptions Source # 
Instance details

Defined in Chart.Markup

Associated Types

type Rep MarkupOptions :: Type -> Type #

Show MarkupOptions Source # 
Instance details

Defined in Chart.Markup

Eq MarkupOptions Source # 
Instance details

Defined in Chart.Markup

type Rep MarkupOptions Source # 
Instance details

Defined in Chart.Markup

type Rep MarkupOptions = D1 ('MetaData "MarkupOptions" "Chart.Markup" "chart-svg-0.6.0.0-HjsGv1l8hv76XDZORokPY6" 'False) (C1 ('MetaCons "MarkupOptions" 'PrefixI 'True) ((S1 ('MetaSel ('Just "markupHeight") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Double)) :*: S1 ('MetaSel ('Just "chartAspect") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ChartAspect)) :*: (S1 ('MetaSel ('Just "cssOptions") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CssOptions) :*: S1 ('MetaSel ('Just "renderStyle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 RenderStyle))))

defaultMarkupOptions :: MarkupOptions Source #

The official markup options

encodeNum :: Double -> ByteString Source #

Show a Double, or rounded to 4 decimal places if this is shorter.

>>> encodeNum 1
"1.0"
>>> encodeNum 1.23456
"1.2346"

encodePx :: Double -> ByteString Source #

SVG width and height, without any unit suffix, are defined as pixels, which are Integers

>>> encodePx 300.0
"300"