Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2mol/elm-colormaps
Colormaps in Elm.
https://github.com/2mol/elm-colormaps
Last synced: 2 months ago
JSON representation
Colormaps in Elm.
- Host: GitHub
- URL: https://github.com/2mol/elm-colormaps
- Owner: 2mol
- License: bsd-3-clause
- Created: 2017-12-14T12:47:15.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-05T15:09:57.000Z (over 6 years ago)
- Last Synced: 2024-05-20T22:15:02.566Z (8 months ago)
- Language: Elm
- Homepage: https://2mol.github.io/elm-colormaps/
- Size: 228 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elm Colormaps
`elm-colormaps` is a collection of high-quality colormaps intended for data visualization and scientific plotting.
For now it mainly provides a port of the five sequential colormaps (magma, inferno, plasma, viridis, and cividis) that are included in newer versions of matplotlib. These are perceptually uniform, colorblind friendly and can be printed out in grayscale with minimal loss of information.
![magma, inferno, plasma, viridis, and cividis](https://raw.githubusercontent.com/2mol/elm-colormaps/master/images/matplotlib.png)
This library provides these colormaps as functions of type `Float -> Color`, where the input is expected to be between 0 and 1.
To use, just import `Color.Colormaps` and use the functions `magma`, `inferno`, `plasma`, `viridis`, and `cividis`.
## Interop with elm-css
Since `elm-css` currently has a different Color type than the Base library, colors from `Colormap` have to be converted. To keep dependencies to a minimum, `elm-colormaps` does not ship with a conversion function. However, it can easily be written as follows:
```elm
colorCoreToCss : Color.Color -> Css.Color
colorCoreToCss c =
let
{ red, green, blue, alpha } =
Color.toRgb c
in
Css.rgba red green blue alpha
```## Examples and custom colormaps
The `examples` directory contains code illustrating all abovementioned functionality. Run the code locally with `elm-reactor` and open `Example.elm`. Alternatively, take a look at the results at [https://2mol.github.io/elm-colormaps/](https://2mol.github.io/elm-colormaps/).
There are also examples included about how to use the various helper functions that can be used to define custom colormaps from lists of RGB tuples.
## References
The original exposition on why and how the new Matplotlib colormaps were created. Highly recommended:
https://bids.github.io/colormap/
Some more information on the linearity of several colormaps, as well as some additional ones that might be interesting to port to Elm in the future:
https://matplotlib.org/users/colormaps.html
https://matplotlib.org/gallery/color/colormap_reference.html