1use gpui::{AppContext, Application, Bounds, WindowBounds, WindowOptions, px, size};
2
3use gpui_liveplot::{
4 AxisConfig, Color, GpuiPlotView, LineStyle, Plot, PlotViewConfig, 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: Color::new(0.2, 0.75, 0.95, 1.0),
27 width: 2.0,
28 }),
29 );
30
31 let mut plot = Plot::builder()
32 .theme(Theme::dark())
33 .x_axis(AxisConfig::builder().title("Sample").build())
34 .y_axis(AxisConfig::builder().title("Amplitude").build())
35 .build();
36 plot.add_series(&series);
37
38 let config = PlotViewConfig {
39 show_legend: true,
40 show_hover: true,
41 ..Default::default()
42 };
43
44 let view = GpuiPlotView::with_config(plot, config);
45 cx.new(|_| view)
46 })
47 .unwrap();
48 });
49}