Added stem plots and legend entry hover checking

This commit is contained in:
4bb4 2021-01-31 12:40:13 +01:00
parent 2c56bd9803
commit 21aa28591c
7 changed files with 113 additions and 10 deletions

View file

@ -3,6 +3,7 @@ pub mod heatmaps;
pub mod line_plots;
pub mod scatter_plots;
pub mod stairs_plots;
mod stem_plots;
pub mod text_plots;
use imgui::{im_str, Condition, Ui, Window};
@ -43,5 +44,9 @@ pub fn show_demos(ui: &Ui, plot_ui: &PlotUi) {
ui.separator();
ui.text(im_str!("Heatmaps:"));
heatmaps::show_demo_headers(ui, plot_ui);
ui.separator();
ui.text(im_str!("Stem plots:"));
stem_plots::show_demo_headers(ui, plot_ui);
});
}

View file

@ -3,12 +3,12 @@
use imgui::{im_str, CollapsingHeader, Condition, Ui};
use implot::{
get_plot_limits, get_plot_mouse_position, get_plot_query, is_plot_hovered, is_plot_queried,
pixels_to_plot_vec2, plot_to_pixels_vec2, push_style_color, push_style_var_f32,
push_style_var_i32, set_colormap_from_preset, set_colormap_from_vec, set_plot_y_axis,
AxisFlags, Colormap, ImPlotLimits, ImPlotPoint, ImPlotRange, ImVec2, ImVec4, Marker, Plot,
PlotColorElement, PlotFlags, PlotLine, PlotLocation, PlotOrientation, PlotUi, StyleVar,
YAxisChoice,
get_plot_limits, get_plot_mouse_position, get_plot_query, is_legend_entry_hovered,
is_plot_hovered, is_plot_queried, pixels_to_plot_vec2, plot_to_pixels_vec2, push_style_color,
push_style_var_f32, push_style_var_i32, set_colormap_from_preset, set_colormap_from_vec,
set_plot_y_axis, AxisFlags, Colormap, ImPlotLimits, ImPlotPoint, ImPlotRange, ImVec2, ImVec4,
Marker, Plot, PlotColorElement, PlotFlags, PlotLine, PlotLocation, PlotOrientation, PlotUi,
StyleVar, YAxisChoice,
};
pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
@ -156,6 +156,8 @@ pub fn show_query_features_plot(ui: &Ui, plot_ui: &PlotUi) {
let mut hover_pos_from_pixels: Option<ImPlotPoint> = None;
let mut plot_limits: Option<ImPlotLimits> = None;
let mut query_limits: Option<ImPlotLimits> = None;
let mut legend1_hovered = false;
let mut legend2_hovered = false;
// Draw a plot
Plot::new("Plot querying")
@ -183,6 +185,12 @@ pub fn show_query_features_plot(ui: &Ui, plot_ui: &PlotUi) {
None,
));
// Plot a line so we have a legend entry
PlotLine::new("Legend1").plot(&vec![2.0, 2.0], &vec![2.0, 1.0]);
PlotLine::new("Legend2").plot(&vec![0.0, 0.0], &vec![1.0, 1.0]);
legend1_hovered = is_legend_entry_hovered("Legend1");
legend2_hovered = is_legend_entry_hovered("Legend2");
if is_plot_queried() {
query_limits = Some(get_plot_query(None));
}
@ -214,6 +222,11 @@ pub fn show_query_features_plot(ui: &Ui, plot_ui: &PlotUi) {
if let Some(query) = query_limits {
ui.text(im_str!("Query limits are {:#?}", query));
}
ui.text(im_str!(
"Legend hovering - 1: {}, 2: {}",
legend1_hovered,
legend2_hovered
));
// Try out converting pixel position to plot position
if let Some(pos) = hover_pos_from_pixels {

View file

@ -0,0 +1,28 @@
//! This example demonstrates how stem plots are to be used. For more general
//! features of the libray, see the line_plots example.
use imgui::{im_str, CollapsingHeader, Ui};
use implot::{Plot, PlotStems, PlotUi};
pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
ui.text(im_str!("This header shows a simple stem plot."));
let content_width = ui.window_content_region_width();
Plot::new("Stem plot")
// The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here.
.size(content_width, 300.0)
.build(plot_ui, || {
// If this is called outside a plot build callback, the program will panic.
let axis_positions = vec![0.2, 0.4, 0.6, 0.8, 0.9, 0.93];
let values = vec![0.1, 0.2, 0.3, 0.4, 0.3, 0.8];
PlotStems::new("legend label")
.with_reference_y(0.1)
.plot(&axis_positions, &values);
});
}
pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
if CollapsingHeader::new(im_str!("Stem plots")).build(&ui) {
show_basic_plot(&ui, &plot_ui);
}
}