-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathchart_data.rs
More file actions
55 lines (47 loc) · 1.58 KB
/
chart_data.rs
File metadata and controls
55 lines (47 loc) · 1.58 KB
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
use crate::{
candle_set::CandleSet, chart::Candle, chart_renderer::ChartRenderer, info_bar::InfoBar,
volume_pane::VolumePane, y_axis::YAxis,
};
#[derive(Debug, Clone)]
pub struct ChartData {
pub main_candle_set: CandleSet,
pub visible_candle_set: CandleSet,
pub terminal_size: (u16, u16),
pub height: i64,
}
impl ChartData {
pub fn new(candles: Vec<Candle>, (w, h): (u16, u16)) -> Self {
let mut chart_data = ChartData {
main_candle_set: CandleSet::new(candles),
visible_candle_set: CandleSet::new(Vec::new()),
terminal_size: (w, h),
height: h as i64,
};
chart_data.compute_visible_candles();
chart_data
}
pub fn compute_height(&mut self, volume_pane: &VolumePane) {
let volume_pane_height = if volume_pane.enabled {
volume_pane.height
} else {
0
};
self.height = self.terminal_size.1 as i64
- ChartRenderer::MARGIN_TOP
- InfoBar::HEIGHT
- volume_pane_height;
}
pub fn compute_visible_candles(&mut self) {
let term_width = self.terminal_size.0 as usize as i64;
let nb_candles = self.main_candle_set.candles.len();
let nb_visible_candles = term_width - YAxis::WIDTH;
self.visible_candle_set.set_candles(
self.main_candle_set
.candles
.iter()
.skip((nb_candles as i64 - nb_visible_candles as i64).max(0) as usize)
.cloned()
.collect::<Vec<Candle>>(),
);
}
}