-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add heatmap plot widget #2246
Add heatmap plot widget #2246
Conversation
I see in the commit that you're working on Interpolation between the point, I believe that this is some sort of blueing between pixels. If so, is it going to be optional? |
I tried the implementation, but it gets very laggy when loading relatively large arrays. I tried your example and it works fine, but when loading a 1200x360px the whole ui is unresponsive. Do you think the issue is with egui itself? compared to the example in imgui where we see the high fps white noise, i think there still some work to do... |
Hi, I'm working on a heatmap widget for egui. |
I don't understand, sorry.
Yes, the implementation is very basic, drawing each data point one-by-one, as primitive. For large amounts of data, this becomes inefficient. 1200x360 is basically an image ... maybe we can draw the map in the same way we would draw an actual bitmap image, but it would require some more time and investment. I think it is a good start to get some inspiration from the imgui source code.
Hi, I tested your examples. Good work, but it is laggy for me, too, and for some reason the UI looks distorted. If you manage to resolve the hickups feel free to replace this MR with yours. |
b83d623
to
203d972
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool demo!
impl std::error::Error for HeatmapErr {} | ||
|
||
/// A heatmap. | ||
pub struct Heatmap<const RESOLUTION: usize> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to its own file (this one is already too long!)
pos: PlotPoint, | ||
/// values to plot | ||
pub(super) values: Vec<f64>, | ||
/// number of columns in heatmap | ||
cols: usize, | ||
/// number of rows in heatmap | ||
rows: usize, | ||
/// minimum value in colormap. | ||
/// Everything smaller will be mapped to palette[0] | ||
min: f64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find readability increases a lot by adding newlines before docstrings:
pos: PlotPoint, | |
/// values to plot | |
pub(super) values: Vec<f64>, | |
/// number of columns in heatmap | |
cols: usize, | |
/// number of rows in heatmap | |
rows: usize, | |
/// minimum value in colormap. | |
/// Everything smaller will be mapped to palette[0] | |
min: f64, | |
pos: PlotPoint, | |
/// values to plot | |
pub(super) values: Vec<f64>, | |
/// number of columns in heatmap | |
cols: usize, | |
/// number of rows in heatmap | |
rows: usize, | |
/// minimum value in colormap. | |
/// Everything smaller will be mapped to palette[0] | |
min: f64, |
if cols == 0 { | ||
return Err(HeatmapErr::ZeroColumns); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an error?
if v < &min { | ||
min = *v; | ||
} | ||
if v > &max { | ||
max = *v; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if v < &min { | |
min = *v; | |
} | |
if v > &max { | |
max = *v; | |
} | |
min = min.min(v); | |
max = max.max(v); |
// calculate palette | ||
let base_colors = vec![ | ||
Color32::BLACK, | ||
Color32::DARK_RED, | ||
Color32::YELLOW, | ||
Color32::BLACK, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to use a standard colormap here, like turbo
Recently, I implemented a polar plot widget for ImGui using GLSL shaders. I needed it to visualize radar spectrum data. It takes a two-dimensional array as input and performs a color mapping and then an (optional) transformation to polar coordinate space. With GPU acceleration, this runs smoothly even for larger arrays. It could be used here to greatly improve performance. Is it possible (and reasonable) to use shaders in egui-plot widgets? Or are there some major issues with it? |
@JohannesProgrammiert the heatmap looks great -- is there any reason this PR is still in progress? |
Some reasons:
But generally, it works and could be merged to provide an "early access" version of this feature. |
i remember trying this out a few months back and it worked good enough for a mvp. Do you have an idea of the timeline? I remember this was the missing widet for me to switch to egui and rust in general for production. I'll clone this and update my code as it seems to conflict with the latest branch, but if you are about to merge it within the next few weeks, i might just wait ;) |
Not sure if it is covered, but it would be great to be able to set a background image so that you could use a heatmap on top of it to represent different aspects (e.g. a map and on top the heatmap to represent temperatures). |
This will hopefully speed up its development by having more reviewers and maintainers. Please re-open this PR at https://github.com/emilk/egui_plot/pulls See also: |
Add widget for heatmap plot. Takes ImPlot as inspiration.
Preview:
simplescreenrecorder.webm
TODO before ready
Closes emilk/egui_plot#6.