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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#![deny(warnings)]
#![deny(missing_docs)]
#[macro_use]
extern crate derive_builder;
#[macro_use]
extern crate log;
use std::fmt::Debug;
mod graph;
pub use graph::{Config, ConfigBuilder, Graph, PointStyle, View, ViewMode};
mod graph_with_controls;
pub use graph_with_controls::GraphWithControls;
mod null_data_source;
pub use null_data_source::NullDataSource;
pub mod observable_value;
mod signal;
pub use signal::Signal;
mod store;
use store::Store;
mod test_data_generator;
pub use test_data_generator::TestDataGenerator;
#[derive(Debug)]
pub enum Error {
String(String),
}
pub type Result<T> = std::result::Result<T, Error>;
pub type Time = u32;
pub type Value = u16;
#[derive(Debug, Clone)]
pub struct Point {
pub t: Time,
pub vs: Vec<Value>,
}
impl Point {
pub fn t(&self) -> Time {
self.t
}
pub fn vals(&self) -> &[Value] {
&self.vs
}
}
#[derive(Clone, Copy)]
pub struct Color(pub u8, pub u8, pub u8);
impl Color {
pub fn from_rgb(r: u8, g: u8, b: u8) -> Color {
Color(r, g, b)
}
pub fn r(&self) -> u8 {
self.0
}
pub fn g(&self) -> u8 {
self.1
}
pub fn b(&self) -> u8 {
self.2
}
}
#[cfg(test)]
mod color_tests {
use super::Color;
#[test]
fn values() {
let c = Color::from_rgb(10, 20, 30);
assert_eq!(c.r(), 10);
assert_eq!(c.g(), 20);
assert_eq!(c.b(), 30);
}
}
pub trait DataSource: Debug + Send {
fn get_data(&mut self) -> Result<Vec<Point>>;
fn get_num_values(&self) -> Result<usize>;
fn get_colors(&self) -> Result<Vec<Color>> {
Ok(vec![Color(255u8, 0u8, 0u8),
Color(0u8, 255u8, 0u8),
Color(0u8, 0u8, 255u8)
])
}
}