let mut vals = Vec::new();
const ROWS: usize = 16; // tiles y
const COLS: usize = ROWS; // tiles x
// populate values
for x in 0..COLS {
for y in 0..ROWS {
let r = f32::sqrt((x.pow(2) + y.pow(2)) as f32);
vals.push(f64::sin(r as f64 + self.t as f64 / 100.0));
}
}
const RESOLUTION: usize = 256; // number of color steps in interpolated color palette
let heatmap = egui::plot::Heatmap::<RESOLUTION>::new(vals, COLS)
.unwrap()
.show_labels(self.show_labels) // bool
.palette(self.color_gradient.clone()) // Vec<Color32>
.name("something");
Plot::new("plot")
.legend(Legend::default())
.allow_zoom(false)
.allow_scroll(false)
.allow_boxed_zoom(false)
.allow_drag(false)
.set_margin_fraction(Vec2::new(0.0, 0.0))
.width(500.0)
.view_aspect(1.0)
.show(ui, |plot_ui| {
plot_ui.heatmap(heatmap);
});
TODO
axis legends (related to/depends on https://github.com/emilk/egui/issues/889). I also think axis labels and ticks should be outside of the plotting window, similar to ImPlot. ImPlot has an option to move the legend out of the plotting window which I find convenient, too.
Value to color mapping is sometimes weird, debugging needed
Legend (similar to ImPlot, an extra window that shows value-to-color-mapping).
I did not find a feature request about heat maps. Heat map plotting is available in the ImPlot library. The related demo widget looks like this:
I started implementing a similar feature for the egui plot widget which currently looks like this:
simplescreenrecorder.webm
And the API to create such a thing is:
TODO