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
use crate::data::{DataGroup, DataSet, WidgetSubType, WidgetType};
use serde_json::json;
trait Widget {
fn get_group(&self) -> DataGroup;
}
pub struct MapWidget {
latitude: f32,
longitude: f32,
name: String,
graph: bool,
}
impl MapWidget {
pub fn new(name: String, latitude: f32, longitude: f32, graph: bool) -> Self {
Self {
latitude,
longitude,
name,
graph,
}
}
pub fn update(&mut self, latitude: f32, longitude: f32) {
self.latitude = latitude;
self.longitude = longitude;
}
}
impl Widget for MapWidget {
fn get_group(&self) -> DataGroup {
DataGroup {
title: self.name.clone(),
widget_type: Some(WidgetType::Map),
datasets: vec![
DataSet {
title: None,
value: json!(self.latitude),
graph: Some(self.graph),
unit: None,
w_type: Some(WidgetSubType::Latitude),
},
DataSet {
title: None,
value: json!(self.longitude),
graph: Some(self.graph),
unit: None,
w_type: Some(WidgetSubType::Longitude),
},
],
}
}
}
pub struct Dashboard {
name: String,
widgets: Vec<Box<dyn Widget>>,
}