Skip to main content

basic/
basic.rs

1use gpui::{AppContext, Application, Bounds, WindowBounds, WindowOptions, px, size};
2
3use gpui_liveplot::{
4    AxisConfig, LineStyle, Plot, PlotView, PlotViewConfig, Rgba, Series, SeriesKind, Theme,
5};
6
7fn main() {
8    Application::new().run(|cx| {
9        let options = WindowOptions {
10            window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
11                None,
12                size(px(720.0), px(480.0)),
13                cx,
14            ))),
15            ..Default::default()
16        };
17
18        cx.open_window(options, |_window, cx| {
19            let series = Series::from_iter_y(
20                "signal",
21                (0..400).map(|i| {
22                    let x = i as f64 * 0.03;
23                    x.sin()
24                }),
25                SeriesKind::Line(LineStyle {
26                    color: Rgba {
27                        r: 0.2,
28                        g: 0.75,
29                        b: 0.95,
30                        a: 1.0,
31                    },
32                    width: 2.0,
33                }),
34            );
35
36            let mut plot = Plot::builder()
37                .theme(Theme::dark())
38                .x_axis(AxisConfig::builder().title("Sample").build())
39                .y_axis(AxisConfig::builder().title("Amplitude").build())
40                .build();
41            plot.add_series(&series);
42
43            let config = PlotViewConfig {
44                show_legend: true,
45                show_hover: true,
46                ..Default::default()
47            };
48
49            let view = PlotView::with_config(plot, config);
50            cx.new(|_| view)
51        })
52        .unwrap();
53    });
54}