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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#![allow(clippy::needless_return)]
use animate::{CanvasContext, Point};
use dataflow::*;
use std::fmt;
#[macro_use]
extern crate log;
mod basechart;
pub use basechart::*;
mod bar;
pub use bar::*;
mod gauge;
pub use gauge::*;
mod line;
pub use line::*;
mod options;
pub use options::*;
mod pie;
pub use pie::*;
mod radar;
pub use radar::*;
pub mod utils;
pub(crate) const CLOCKWISE: i64 = 1;
pub(crate) const COUNTERCLOCKWISE: i64 = -1;
pub(crate) const HIGHLIGHT_OUTER_RADIUS_FACTOR: f64 = 1.05;
pub const PI: f64 = std::f64::consts::PI;
pub const TAU: f64 = std::f64::consts::TAU;
pub const PI_2: f64 = std::f64::consts::FRAC_PI_2;
pub const DEFAULT_FONT_FAMILY: &str = "monospace";
pub const CHART_PADDING: f64 = 12.0;
pub const LEGEND_MARGIN: f64 = 12.0;
pub const CHART_TITLE_MARGIN: f64 = 12.0;
pub const TITLE_PADDING: f64 = 6.0;
pub const AXIS_LABEL_MARGIN: usize = 12;
pub type LabelFormatter = fn(label: String) -> String;
pub type ValueFormatter = fn(value: f64) -> String;
pub fn default_label_formatter(label: String) -> String {
label
}
pub fn default_value_formatter(value: f64) -> String {
format!("{}", value)
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Visibility {
Hidden,
Hiding,
Showing,
Shown,
}
impl Default for Visibility {
fn default() -> Self {
Visibility::Hidden
}
}
pub struct MouseEvent;
pub trait Entity {
fn free(&mut self);
fn save(&self);
}
pub trait Drawable<C>
where
C: CanvasContext,
{
fn draw(&self, ctx: &C, percent: f64, highlight: bool);
}
#[derive(Default, Debug, Clone)]
pub struct ChartChannel<E>
where
E: Entity,
{
name: String,
fill: Fill,
highlight: Fill,
state: Visibility,
entities: Vec<E>,
}
impl<E> ChartChannel<E>
where
E: Entity,
{
pub fn new(name: &str, fill: Fill, highlight: Fill, entities: Vec<E>) -> Self {
Self {
name: name.into(),
fill,
highlight,
state: Visibility::Shown,
entities,
}
}
pub fn free_entities(&self, start: usize, end: Option<usize>) {
let end = match end {
Some(end) => end,
None => self.entities.len(),
};
let mut start = start;
while start < end {
start += 1;
}
unimplemented!()
}
}
pub trait Chart<C, M, D, E>
where
E: Entity,
C: CanvasContext,
M: fmt::Display,
D: fmt::Display + Copy,
{
fn calculate_drawing_sizes(&self, ctx: &C);
fn update_channel(&self, index: usize);
fn draw_axes_and_grid(&self, ctx: &C);
fn draw_channels(&self, ctx: &C, percent: f64) -> bool;
fn draw_frame(&self, ctx: &C, time: Option<i64>);
fn create_entities(
&self,
channel_index: usize,
start: usize,
end: usize,
color: Fill,
highlight_color: Fill,
) -> Vec<E>;
fn create_entity(
&self,
channel_index: usize,
entity_index: usize,
value: Option<D>,
color: Fill,
highlight_color: Fill,
) -> E;
fn create_channels(&self, start: usize, end: usize);
fn get_tooltip_position(&self, tooltip_width: f64, tooltip_height: f64) -> Point<f64>;
fn set_stream(&mut self, stream: DataStream<M, D>);
fn draw(&self, ctx: &C);
fn resize(&self, w: f64, h: f64);
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}