Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions demo/src/plot_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum Panel {
Interaction,
CustomAxes,
LinkedAxes,
Heatmap,
}

impl Default for Panel {
Expand All @@ -44,6 +45,7 @@ pub struct PlotDemo {
interaction_demo: InteractionDemo,
custom_axes_demo: CustomAxesDemo,
linked_axes_demo: LinkedAxesDemo,
heatmap_demo: HeatmapDemo,
open_panel: Panel,
}

Expand Down Expand Up @@ -124,6 +126,7 @@ impl PlotDemo {
ui.selectable_value(&mut self.open_panel, Panel::Interaction, "Interaction");
ui.selectable_value(&mut self.open_panel, Panel::CustomAxes, "Custom Axes");
ui.selectable_value(&mut self.open_panel, Panel::LinkedAxes, "Linked Axes");
ui.selectable_value(&mut self.open_panel, Panel::Heatmap, "Heatmap");
});
ui.separator();

Expand Down Expand Up @@ -152,6 +155,9 @@ impl PlotDemo {
Panel::LinkedAxes => {
self.linked_axes_demo.ui(ui);
}
Panel::Heatmap => {
self.heatmap_demo.ui(ui);
}
}
}
}
Expand Down Expand Up @@ -1204,3 +1210,92 @@ fn is_approx_zero(val: f64) -> bool {
fn is_approx_integer(val: f64) -> bool {
val.fract().abs() < 1e-6
}

#[derive(PartialEq, serde::Serialize, serde::Deserialize)]
struct HeatmapDemo {
tick: f64,
animate: bool,
show_labels: bool,
palette: Vec<Color32>,
rows: usize,
cols: usize,
}

pub const TURBO_COLORMAP: [Color32; 10] = [
Color32::from_rgb(48, 18, 59),
Color32::from_rgb(35, 106, 141),
Color32::from_rgb(30, 160, 140),
Color32::from_rgb(88, 200, 98),
Color32::from_rgb(164, 223, 39),
Color32::from_rgb(228, 223, 14),
Color32::from_rgb(250, 187, 13),
Color32::from_rgb(246, 135, 8),
Color32::from_rgb(213, 68, 2),
Color32::from_rgb(122, 4, 2),
];

impl Default for HeatmapDemo {
fn default() -> Self {
Self {
tick: 0.0,
animate: false,
show_labels: true,
palette: TURBO_COLORMAP.to_vec(),
rows: 10,
cols: 15,
}
}
}

impl HeatmapDemo {
fn ui(&mut self, ui: &mut egui::Ui) -> Response {
ui.checkbox(&mut self.animate, "Animate");
if self.animate {
ui.ctx().request_repaint();
self.tick += 1.0;
}
ui.checkbox(&mut self.show_labels, "Show labels");
ui.add(egui::Slider::new(&mut self.rows, 1..=100).text("Rows"));
ui.add(egui::Slider::new(&mut self.cols, 1..=100).text("Columns"));
let mut values = Vec::new();
for y in 0..self.rows {
for x in 0..self.cols {
let y = y as f64;
let x = x as f64;
let cols = self.cols as f64;
let rows = self.rows as f64;
values.push(((x + self.tick) / rows).sin() + ((y + self.tick) / cols).cos());
}
}
ui.add_enabled_ui(self.palette.len() > 1, |ui| {
if ui.button("Pop color").clicked() {
self.palette.pop();
}
});
if ui.button("Push color").clicked() {
self.palette
.push(*self.palette.last().expect("Palette is empty"));
}
ui.horizontal(|ui| {
for color in &mut self.palette {
ui.color_edit_button_srgba(color);
}
});

let heatmap = egui_plot::Heatmap::<128>::new(values, self.cols)
.expect("Failed to create heatmap")
.palette(&self.palette)
.show_labels(self.show_labels);
Plot::new("Heatmap Demo")
.legend(Legend::default())
.allow_zoom(false)
.allow_scroll(false)
.allow_drag(false)
.allow_boxed_zoom(false)
.set_margin_fraction(vec2(0.0, 0.0))
.show(ui, |plot_ui| {
plot_ui.heatmap(heatmap);
})
.response
}
}
4 changes: 2 additions & 2 deletions demo/tests/snapshots/demos/Charts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/demos/Custom Axes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions demo/tests/snapshots/demos/Heatmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/demos/Interaction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/demos/Items.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/demos/Legend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/demos/Lines.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/demos/Linked Axes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/demos/Markers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/light_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/scale_0.50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/scale_1.00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/scale_1.39.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/tests/snapshots/scale_2.00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading