Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Conversion between ChartOptions
and Markup
representations.
Synopsis
- newtype Markup = Markup {}
- data ChartOptions = ChartOptions {}
- forgetHud :: ChartOptions -> ChartOptions
- markupChartOptions :: ChartOptions -> Markup
- markupChartTree :: ChartTree -> Markup
- markupChart :: Chart -> Markup
- header :: Maybe Double -> Rect Double -> Markup -> Markup
- renderChartOptions :: ChartOptions -> Text
- encodeChartOptions :: ChartOptions -> ByteString
- writeChartOptions :: FilePath -> ChartOptions -> IO ()
- data CssOptions = CssOptions {}
- defaultCssOptions :: CssOptions
- data PreferColorScheme
- cssPreferColorScheme :: (Colour, Colour) -> PreferColorScheme -> ByteString
- fillSwitch :: (Colour, Colour) -> ByteString -> ByteString -> ByteString
- data ShapeRendering
- markupCssOptions :: CssOptions -> Markup
- data MarkupOptions = MarkupOptions {}
- defaultMarkupOptions :: MarkupOptions
- encodeNum :: Double -> ByteString
- encodePx :: Double -> ByteString
- defaultCssFontFamilies :: ByteString
Documentation
A list of Element
s or Tree
Token
s
>>>
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 = []}]}]})
data ChartOptions Source #
A product type consisting of a ChartTree
, HudOptions
and MarkupOptions
, which is what you need to create Markup
.
Instances
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
defaultCssOptions :: CssOptions Source #
No special shape rendering and default hud responds to user color scheme preferences.
data PreferColorScheme Source #
CSS prefer-color-scheme options
PreferHud | includes css that switches approriate hud elements between light and dark. |
PreferDark | |
PreferLight | |
PreferNormal |
Instances
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
Generic ShapeRendering Source # | |
Defined in Chart.Markup type Rep ShapeRendering :: Type -> Type # from :: ShapeRendering -> Rep ShapeRendering x # to :: Rep ShapeRendering x -> ShapeRendering # | |
Show ShapeRendering Source # | |
Defined in Chart.Markup showsPrec :: Int -> ShapeRendering -> ShowS # show :: ShapeRendering -> String # showList :: [ShapeRendering] -> ShowS # | |
Eq ShapeRendering Source # | |
Defined in Chart.Markup (==) :: ShapeRendering -> ShapeRendering -> Bool # (/=) :: ShapeRendering -> ShapeRendering -> Bool # | |
type Rep ShapeRendering Source # | |
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
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"
defaultCssFontFamilies :: ByteString Source #
default fonts.