Introduce colormaps
- Dominant language
- Rust
- Stars
- 468
- Forks
- 108
- Avg merge
- 15m
- Merged PRs (30d)
- 3
Description
Introduce colormaps and a default colormap.
There are two principal uses of colormaps:
1. Heatmaps
2. Picking plot item colors (lines, markers, etc.)
# Definition
Let's define colormap as a mapping from the unit interval to RGB space (Color32).
Within this unit interval, there are at least two "anchor" points, for $t=0$ and $t=1$.
There can be more anchors at distinct $t$.
# Interpolation
The colormap interpolates between the anchor points. The interpolation can be specified as one of:
- RGB
- HSL / HSV / HSB
- CIELAB
- LCH
- OKLab / OKLCH
[Exploration with chatgpt](https://chatgpt.com/share/693d4f60-bc68-800a-a235-7af22118fd81).
# Sampling
These can be either "finite" to cycle through the colormap, or "infinite", covering the unit interval.
The finite case $N$ can simply go through the unit interval in round-robin fashion: $t=(i \mod N / N)$
The "infinite" case can use
- Sobol / Kronecker/ Van der Corput sequence. [Exploration with chatgpt](https://chatgpt.com/s/t_693d506d6f5081919ea578723ec36373)
# Principal uses
## 1. Heatmaps
One has to first normalize the input data to unit interval to get the color. This normalization will be typically linear or logarithmic, for on a given segment (for min/max over displayed data).
For coloring values (i.e. the heatmap implementation), one has to normalize the input data to unit interval before getting the color.
## 2. Plot item colors
We use the sampling algorithm here and get a color via a `next` call.
# Colormap API
- `new` with vec of Color32 anchor points -- make them uniformly distributed. At least 2 points! Makes sampling to be finite N by default.
- `new_with_positions` allow pass vec of [Color32, t=f32] values. Check ordering, and boundary points! Makes sampling to be
- `with_interpolation` - set
- `with_sampling` - specify
- `get(&self, t: f32) -> Color32: `
- `next(&mut self, id: egui::Id) -> Color32:` - use an internal counter to get the next color, by using specified sampling. Use the passed `id` to make sure the assigned colors are stable.
# Integration
Specify colormap in the `Plot` builder. Do not require plot lines/points to specify colors, but they can override them.
# Demo
Allow changing the color maps and sampling, show both a plot with some lines/points (left), and a heatmap (right).
Contributor guide
Assessment
This issue has not been assessed yet.