hvega
Create Vega-Lite visualizations (version 3) in Haskell.
https://github.com/DougBurke/hvega
Version on this page: | 0.3.0.1 |
LTS Haskell 23.16: | 0.12.0.7 |
Stackage Nightly 2025-03-26: | 0.12.0.7 |
Latest on Hackage: | 0.12.0.7 |
hvega-0.3.0.1@sha256:20e38956e5e8e3729cd20774a0aac15f22acf862552cdc955a50bc1e5d084ee9,1330
Module documentation for 0.3.0.1
- Graphics
- Graphics.Vega
hvega
Support the creation of Vega-Lite visualizations in Haskell. This code is released under the BSD3 license.
It is an almost-direct copy of version 2.2.1 of the Elm Vega library, which is released under a BSD3 license by Jo Wood of the giCentre at the City University of London.
Example
let cars = dataFromUrl "https://vega.github.io/vega-datasets/data/cars.json" []
enc = encoding
. position X [ PName "Horsepower", PmType Quantitative ]
. position Y [ PName "Miles_per_Gallon", PmType Quantitative ]
. color [ MName "Origin", MmType Nominal ]
bkg = background "rgba(0, 0, 0, 0.05)"
in toVegaLite [ bkg, cars, mark Circle [], enc [] ]
When viewed with a Vega-Lite aware viewer, the resultant plot is
Documentation
The Elm Vega documentation can be used as a guide to using this module. The Vega-Lite Example Gallery has been converted to an IHaskell notebook Uunfortunately the plots created by VegaEmbed do not appear in the notebook when viewed with either GitHub’s viewer or ipynb viewer, but things seem much better when using Jupyter Lab (rather than notebook) to create the notebooks (since Vega is natively supported in this environment). The notebooks have been re-created using Jupyter Lab (thanks to Tweag I/O’s JupyterWith environment), which should make the plots appear on GitHub (you may need to reload the notebooks as I find they don’t display on the first try).
The notebooks directory contains a poorly-curated set of examples and experiments with hvega.
Differences to Elm Vega
The main changes to version 2.2.1 of Elm Vega are:
-
Replace
Spec
byVLSpec
(although both are synonyms for the underlying JSON representation). -
Add a type for the output of
toVegaLite
(VegaLite
) that is separate fromVLSpec
, which is usefull for integration with IHaskell. The JSON specification is retrieved withfromVL
. -
Take advantage of the lack of backwards compatibality requirements to remove or replace several symbols (such as add the
Utc
constructor toTimeUnit
, remove thebin
function, and useData
rather than(VLProperty, VLSpec)
in function signatures). -
In version 0.2.0.0, the constructors for the
LegendOrientation
type have gained aLO
prefix, which avoids clashing with the Prelude’sEither
type.
Changes
For the latest version of this document, please see https://github.com/DougBurke/hvega/blob/master/hvega/CHANGELOG.md.
0.3.0.1
The minimum base version has been bumped from 4.7 to 4.9, which means ghc 8.0 or later. This is because the 0.2.0.1 release does not appear to build with ghc 7.10. If this restriction is a problem then please comment on the issues list.
There have been minor documentation updates, adding @since
annotations.
0.3.0.0
The Channel
type has been extended to include ChFill
and ChStroke
constructors and the tooltips
function allows you to provide
multiple tooltips for a channel. The schema version has been changed
from 2 to 3, but there has been limited checking to see if the API
correctly reflects the new schema.
This functionality was provided by Adam Massmann (massma) and BinderDavid.
0.2.1.0
Added the toHtml
and toHtmlFile
functions which create the necessary
HTML to view the Vega-Lite visualization using
Vega Embed
(this is similar to how
ihaskell-hvega
works).
This functionality was provided by Gregory Schwartz; apologies for taking so long to get it released.
0.2.0.0
The constructors for the LegendOrientation type have been renamed (by
adding the prefix LO
) which avoids the name clash with Left
and Right
seen in earlier releases. This is a breaking API change.
Clarify how to use the library in the main hvega
module.
Thanks to contributions from Nicolas Mattia (nmattia) and Marco Zocca (ocramz).
0.1.0.3
The only change is to the cabal file, where cabal-version: >=1.18
has
been changed to cabal-version: 1.18
.
0.1.0.2
Updated the upper bounds of aeson
to really allow v1.4. This was not
released on Hackage.
0.1.0.1
Updated the upper bounds of aeson
from v1.2 to v1.4.
The cabal package now includes stack.yaml
and default.nix
(although
the latter is not guaranteed to be correct), as well as a
change log and an extra image.
0.1.0.0
This is the initial version of hvega
, which is based on
version 2.2.1 of the
Elm Vega library.