1use kithe_plot::model::DataSource;
7use kithe_plot::PlotEditorApp;
8
9struct HostDataSource {
11 names: Vec<String>,
12 cols: Vec<Vec<f64>>,
13}
14
15impl HostDataSource {
16 fn demo() -> Self {
17 let x: Vec<f64> = (0..300).map(|i| i as f64 / 20.0).collect();
18 let y1: Vec<f64> = x.iter().map(|v| v.sin()).collect();
19 let y2: Vec<f64> = x.iter().map(|v| (v / 2.0).cos()).collect();
20 Self {
21 names: vec!["x".to_owned(), "sin(x)".to_owned(), "cos(x/2)".to_owned()],
22 cols: vec![x, y1, y2],
23 }
24 }
25}
26
27impl DataSource for HostDataSource {
28 fn column(&self, name: &str) -> Option<Vec<f64>> {
29 self.names
30 .iter()
31 .position(|n| n == name)
32 .map(|idx| self.cols[idx].clone())
33 }
34
35 fn column_names(&self) -> Vec<String> {
36 self.names.clone()
37 }
38
39 fn len(&self) -> usize {
40 self.cols.first().map(|c| c.len()).unwrap_or(0)
41 }
42}
43
44fn main() -> Result<(), eframe::Error> {
45 let source = HostDataSource::demo();
46 let native_options = eframe::NativeOptions::default();
47 eframe::run_native(
48 "Host App + Embedded Plot Redactor",
49 native_options,
50 Box::new(move |cc| {
51 cc.egui_ctx.set_visuals(eframe::egui::Visuals::light());
52 let mut app = PlotEditorApp::new();
53 app.controller_mut()
54 .load_from_data_source(&source)
55 .expect("failed to load host data source");
56 Ok(Box::new(app))
57 }),
58 )
59}