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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Plot markers: point / vertical-line / horizontal-line annotations drawn over
//! the data area (silx `addMarker`).
//!
//! The seven point-marker symbols (circle, point, pixel, plus, cross, diamond,
//! square) are placed across the plot, each labeled. A dashed vertical-line
//! marker and a solid horizontal-line marker show the line kinds with text. The
//! markers are egui-painter overlays, so they stay crisp and pixel-sized while
//! panning and zooming (`doc/design.md` §8).
//!
//! Run with: `cargo run --example plot_markers`
use eframe::egui;
use siplot::{LineStyle, Marker, MarkerSymbol, Plot, PlotView, install};
struct MarkerApp {
plot: Plot,
}
impl MarkerApp {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
let render_state = cc
.wgpu_render_state
.as_ref()
.expect("eframe must use the wgpu renderer (NativeOptions.renderer = Wgpu)");
install(render_state);
let mut plot = Plot::new(0);
plot.limits = (0.0, 8.0, 0.0, 6.0);
plot.title = Some("plot markers (point / vline / hline)".to_owned());
// One point marker per symbol, evenly spaced, each labeled.
let symbols = [
(
MarkerSymbol::Circle,
"o",
egui::Color32::from_rgb(120, 180, 255),
),
(
MarkerSymbol::Point,
".",
egui::Color32::from_rgb(120, 255, 180),
),
(
MarkerSymbol::Pixel,
",",
egui::Color32::from_rgb(200, 200, 200),
),
(
MarkerSymbol::Plus,
"+",
egui::Color32::from_rgb(255, 220, 120),
),
(
MarkerSymbol::Cross,
"x",
egui::Color32::from_rgb(255, 150, 200),
),
(
MarkerSymbol::Diamond,
"d",
egui::Color32::from_rgb(180, 160, 255),
),
(
MarkerSymbol::Square,
"s",
egui::Color32::from_rgb(255, 130, 120),
),
];
for (i, (symbol, label, color)) in symbols.into_iter().enumerate() {
let x = 1.0 + i as f64;
plot.markers.push(
Marker::point(x, 4.5)
.with_symbol(symbol)
.with_symbol_size(14.0)
.with_color(color)
.with_text(label),
);
}
// A dashed vertical-line marker and a solid horizontal-line marker.
plot.markers.push(
Marker::vline(4.0)
.with_color(egui::Color32::from_rgb(255, 200, 80))
.with_line_style(LineStyle::Dashed)
.with_text("x = 4"),
);
plot.markers.push(
Marker::hline(2.0)
.with_color(egui::Color32::from_rgb(120, 220, 255))
.with_line_width(1.5)
.with_text("y = 2")
.with_bgcolor(egui::Color32::from_black_alpha(180)),
);
Self { plot }
}
}
impl eframe::App for MarkerApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show_inside(ui, |ui| {
PlotView::new().show(ui, &mut self.plot);
});
}
}
fn main() -> eframe::Result {
let options = eframe::NativeOptions {
renderer: eframe::Renderer::Wgpu,
..Default::default()
};
eframe::run_native(
"siplot · plot_markers",
options,
Box::new(|cc| Ok(Box::new(MarkerApp::new(cc)) as Box<dyn eframe::App>)),
)
}