/ src / app.rs
app.rs
 1  use crate::player::Player;
 2  use eframe::{egui::{CentralPanel, ComboBox, Context}, Frame};
 3  use egui_plot::{Line, Plot, PlotPoints};
 4  use riven::consts::{IntoEnumIterator, PlatformRoute};
 5  
 6  pub struct App {
 7      api_key: String,
 8      player1: Player,
 9      player2: Player,
10      region: PlatformRoute,
11      data_series: Vec<(f64, f64)>,
12      is_loading: bool,
13  }
14  impl Default for App {
15      fn default() -> Self {
16          Self {
17              region: PlatformRoute::EUW1,
18              api_key: Default::default(),
19              player1: Default::default(),
20              player2: Default::default(),
21              data_series: Default::default(),
22              is_loading: Default::default()
23          }
24      }
25  }
26  impl eframe::App for App {
27      fn update(&mut self, ctx: &Context, _frame: &mut Frame) { //TODO: Add a season dropdown
28          CentralPanel::default().show(ctx, |ui| {
29              self.player1.input_field(ui, 1);
30              self.player2.input_field(ui, 2);
31              
32              ui.horizontal(|ui| {
33                  ui.label("API Key");
34                  ui.text_edit_singleline(&mut self.api_key);
35              });
36  
37              ComboBox::from_label("Region")
38                  .selected_text(self.region.as_region_str())
39                  .show_ui(ui, |ui| {
40                      PlatformRoute::iter().for_each(|region| {
41                          ui.selectable_value(&mut self.region, region, region.as_region_str());
42                      });
43                  });
44  
45              if ui.button("Compare").clicked() {
46                  self.is_loading = true;
47  
48                  //TODO: get match ids for player1 
49                  //TODO: get match info for each match id
50                  //TODO: make 2 match lists (with and without player2 on team)
51                  //TODO: Plot w/l % of both match lists in different colors
52                  //TODO: Add legend so you can tell which line is with and without player2
53  
54                  // dummy data
55                  self.data_series = (0..100)
56                      .map(|i| {
57                          let x = i as f64;
58                          let y = (x / 10.0).sin() * 5.0;
59                          (x, y)
60                      })
61                      .collect();
62                  self.is_loading = false;
63              }
64  
65              if self.is_loading {
66                  ui.label("Loading...");
67              }
68  
69              ui.separator();
70  
71              if !self.data_series.is_empty() {
72                  let points: PlotPoints = self
73                      .data_series
74                      .iter()
75                      .map(|&(x, y)| [x, y])
76                      .collect();
77                  let line = Line::new("stat diff", points);
78  
79                  Plot::new("comparison_plot")
80                      .allow_zoom(true)
81                      .allow_scroll(true)
82                      .allow_double_click_reset(true)
83                      .show(ui, |plot_ui| {
84                          plot_ui.line(line);
85                      });
86              } else {
87                  ui.label("No data to display. Click Compare.");
88              }
89          });
90      }
91  }