-
Notifications
You must be signed in to change notification settings - Fork 22
/
bar_plots.rs
49 lines (45 loc) · 2.05 KB
/
bar_plots.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! This example demonstrates how bar plots are to be used. For more general
//! features of the libray, see the line_plots example.
use imgui::{CollapsingHeader, Ui};
use implot::{Plot, PlotBars, PlotUi};
pub fn show_basic_vertical_plot(ui: &Ui, plot_ui: &PlotUi) {
ui.text("This header shows a simple vertical bar plot.");
let content_width = ui.window_content_region_width();
Plot::new("Vertical bar 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];
let values = vec![0.1, 0.2, 0.3, 0.4];
PlotBars::new("legend label")
.with_bar_width(0.1)
.plot(&axis_positions, &values);
});
}
pub fn show_basic_horizontal_plot(ui: &Ui, plot_ui: &PlotUi) {
ui.text("This header shows a simple horizontal bar plot.");
let content_width = ui.window_content_region_width();
Plot::new("Horizontal bar 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];
let values = vec![0.1, 0.2, 0.3, 0.4];
PlotBars::new("legend label")
.with_bar_width(0.05)
.with_horizontal_bars()
.plot(&axis_positions, &values);
});
}
pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
if CollapsingHeader::new("Bar plots: Basic vertical").build(ui) {
show_basic_vertical_plot(ui, plot_ui);
}
if CollapsingHeader::new("Bar plots: Basic horizontal").build(ui) {
show_basic_horizontal_plot(ui, plot_ui);
}
}